r48543 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48542‎ | r48543 | r48544 >
Date:23:24, 18 March 2009
Author:kim
Status:deferred
Tags:
Comment:
* initial work on tags support.
* sort output from available.extension
Modified paths:
  • /trunk/wikiation/installer/installation_system.py (modified) (history)
  • /trunk/wikiation/installer/installer.py (modified) (history)
  • /trunk/wikiation/installer/installer_util.py (modified) (history)
  • /trunk/wikiation/installer/installers.py (modified) (history)
  • /trunk/wikiation/installer/settings_handler.py (modified) (history)
  • /trunk/wikiation/installer/tags.py (added) (history)

Diff [purge]

Index: trunk/wikiation/installer/installer_util.py
@@ -32,15 +32,14 @@
3333 print "wikiation installer, interactive mode"
3434 print "help: get help"
3535 print "quit: quit"
36 - print "ls [item]: list information on available versions "
37 - print "ls2 [item]: list information on extensions or wikiation components"
38 - print "install <version>: installs the version specified"
39 - print "install <version> as <name>: installs the version specified under an alternate name"
40 - print "install latest ; install latest as <name>: installs the latest version available in svn."
41 - print "uninstall <version/name>: uninstalls the version specified"
42 - print "check_isolation <version/name>: shows all changes made to mediawiki or database since it was installed."
 36+ print "ls <path>: list information on available versions "
 37+ print "install <path>: installs the version specified"
 38+ print "install <path> as <name>: installs the version specified under an alternate name"
 39+ print "uninstall <path>: uninstalls the version specified"
 40+ print "check_isolation <instance name>: shows all changes made to mediawiki or database since it was installed."
4341 print "update_self: updates the installer and restarts in interactive mode"
44 - print "revision [new revision]: query current default revision, or set a new one (will be implemented over time)"
 42+ print "update_tags: manually force an update of the tag cache (do this from time to time, if you're referring to things by tag)"
 43+ print "TODO: Implement help path , for now, see documentation for info on how to specify <path>"
4544 print
4645 print "instead of interactive mode, you can also access commands directly from the shell:"
4746 print "wikiation_installer command [args]..."
Index: trunk/wikiation/installer/settings_handler.py
@@ -18,12 +18,15 @@
1919 # where to find .install directories and the files contained therein
2020 installfiles=os.path.join(installerdir,'installfiles')
2121
 22+# where do we store the _tagcache file
 23+tagcache=os.path.join(installerdir,"_tagcache")
2224
2325 # where to find mediawiki tags and trunk on svn
2426 tagsdir="http://svn.wikimedia.org/svnroot/mediawiki/tags"
2527 trunkdir="http://svn.wikimedia.org/svnroot/mediawiki/trunk"
2628 # we could alternately/additionally take a tag version for extensions. (future)
27 -extensionsdir=trunkdir+"/extensions"
 29+extensionssubdir="extensions"
 30+extensionsdir=trunkdir+"/"+extensionssubdir
2831
2932 # where to install diverse revisions
3033 instancesdir='/var/www/revisions'
Index: trunk/wikiation/installer/installer.py
@@ -30,6 +30,7 @@
3131 from installer_util import *
3232 from isolation import *
3333 from getch import getch
 34+from tags import Tags
3435
3536 def intro():
3637 """a nice banner/intro text for interactive mode"""
@@ -138,12 +139,17 @@
139140 elif len(args)>=2:
140141 print "I'm not sure what to do with "+ (" ".join(args[1:]))
141142
 143+ os.unlink(settings.tagcache) #paranoia is good for you
 144+
142145 print "\n\n"
143146 print "wikiation_installer update attempted/completed. Restarting"
144147 print "----------------------------------------------------------"
145148 print "\n\n"
146149 os.execl("/usr/bin/python","/usr/bin/python",__file__)
147150
 151+def update_tags(args):
 152+ """manually force update of the tag cache"""
 153+ Tags.update_cache_file()
148154
149155 def main():
150156 """main function. start of execution when run from shell"""
@@ -184,6 +190,7 @@
185191 "info":info,
186192 "check_isolation":check_isolation,
187193 "update_self":update_self,
 194+ "update_tags":update_tags
188195 }
189196
190197 # additional help texts for some commands.
Index: trunk/wikiation/installer/tags.py
@@ -0,0 +1,103 @@
 2+import sys,os
 3+import os.path
 4+import settings_handler as settings
 5+import copy
 6+import cPickle as pickle
 7+import subprocess
 8+
 9+class TagsException(Exception):
 10+ pass
 11+
 12+class Tags:
 13+ """keep track of extension tags in svn.
 14+ the current repository is not optimised for the kinds
 15+ of queries the installer needs. We do the query once
 16+ and cache it."""
 17+
 18+ def __init__(self):
 19+ # try to load preexisting cache
 20+ self.cache=self.load_cache()
 21+ # No joy? Let's generate one.
 22+ if not self.cache:
 23+ self.cache=self.update_cache()
 24+ # Still no joy?
 25+ if not self.cache:
 26+ raise Exception("Internal error: cannot obtain a tag cache")
 27+
 28+ @classmethod
 29+ def load_cache(self):
 30+ """load tags from cache"""
 31+ if not os.path.isfile(settings.tagcache):
 32+ return None
 33+
 34+ cache=pickle.load(file(settings.tagcache))
 35+ return cache
 36+
 37+ @classmethod
 38+ def svnlist(self,dir):
 39+ """generic obtain data from svn ls
 40+ (TODO: refactor, overlaps with DownloadInstaller get_installers)"""
 41+
 42+ command=['svn','ls',dir]
 43+ process=subprocess.Popen(command,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 44+ failp=process.stderr.read()
 45+ if failp:
 46+ return None
 47+ l=list(process.stdout)
 48+ # tidy l in place
 49+ for i in range(len(l)):
 50+ l[i]=l[i].strip()
 51+ if l[i].endswith("/"):
 52+ l[i]=l[i][:-1]
 53+ return l
 54+
 55+ def update_cache(self):
 56+ """update cache to disk and to memory"""
 57+ self.cache=self.update_cache_file()
 58+ return self.cache
 59+
 60+ @classmethod
 61+ def update_cache_file(self):
 62+ """update cache to disk. returns a cache. This is an expensive operation.
 63+ (cache format is {"extension name":["tag1", "tag2", "tag3", ...]}, ...)
 64+ """
 65+ print "Updating tags cache, this takes a minute or so."
 66+ print "(Items marked with '*' do not seem to contain extensions)"
 67+ cache={}
 68+ tags=self.svnlist(settings.tagsdir)
 69+ for tag in tags:
 70+ sys.stdout.write(tag)
 71+ sys.stdout.flush()
 72+
 73+ extensions=self.svnlist(settings.tagsdir+"/"+tag+"/"+settings.extensionssubdir)
 74+ if extensions==None:
 75+ extensions=[]
 76+ sys.stdout.write('*')
 77+ sys.stdout.flush()
 78+ for extension in extensions:
 79+ if extension not in cache:
 80+ cache[extension]=[]
 81+ cache[extension].append(tag)
 82+ sys.stdout.write('; ')
 83+ sys.stdout.flush()
 84+
 85+ #store cache to disk
 86+ pickle.dump(cache, file(settings.tagcache,"w"),pickle.HIGHEST_PROTOCOL)
 87+
 88+ #make empty line
 89+ print
 90+ print "completed."
 91+ return cache
 92+
 93+ def gettags(self,extension):
 94+ if extension not in self.cache:
 95+ raise TagsException("Could not find extension "+str(extension)+".")
 96+
 97+ tags=self.cache[extension]
 98+ return copy.copy(tags)
 99+
 100+if __name__=="__main__":
 101+ tags=Tags()
 102+ print "Imagemap: ",tags.gettags("ImageMap")
 103+ print "Cite: ", tags.gettags("Cite")
 104+
Index: trunk/wikiation/installer/installation_system.py
@@ -6,6 +6,7 @@
77 import settings_handler as settings
88 import os, os.path, shutil
99 import subprocess
 10+from tags import Tags
1011
1112
1213 class Installer_Exception (Exception):
@@ -45,8 +46,10 @@
4647 if line.endswith(".install"):
4748 installers2.append(line.replace(".install",""))
4849
 50+ installers2.sort()
4951 return installers2
5052
 53+ # XXX This should be a mixin
5154 def get_revisions(self,installer_name):
5255 """list the revisions a particular installer can install"""
5356 if not self.exists(installer_name):
@@ -54,6 +57,7 @@
5558
5659 return self.do_get_revisions(installer_name)
5760
 61+ # XXX this should be a mixin
5862 def do_get_revisions(self, installer_name):
5963 """actually perform the task of getting revisions for get_revisions
6064 First checks to see if someone has provided a script to determine
@@ -66,6 +70,12 @@
6771
6872 return None
6973
 74+ # XXX should be a mixin
 75+ def get_tags(self, installer_name):
 76+ """get list of tags available for this installer."""
 77+ return Tags().gettags(installer_name)
 78+
 79+
7080 def get_svnbase():
7181 return None
7282
Index: trunk/wikiation/installer/installers.py
@@ -20,6 +20,8 @@
2121 from installation_system import Installer_Exception
2222 from download_installer import Download_Installer
2323
 24+from tags import Tags, TagsException
 25+
2426 class Parse_Exception(Exception):
2527 pass
2628
@@ -110,10 +112,17 @@
111113
112114
113115 def ls_tags(ppath):
114 - print "To be implemented."
 116+ if not ppath["installer"]:
 117+ raise Listing_Exception("What extension would you like to know the available revisions for?")
115118
 119+ system=get_system(ppath["system"])
 120+ try:
 121+ tags=system.get_tags(ppath["installer"])
 122+ except TagsException, e:
 123+ raise Listing_Exception(e.message)
 124+
 125+ return tags
116126
117 -
118127 def info(args):
119128 if len(args)<1:
120129 print "info: Internal error: expected more arguments"
@@ -331,8 +340,11 @@
332341
333342 return sYstem()
334343
 344+# Constants
 345+
335346 systems={'wikiation_toolkit':Toolkit_Installer,'extension': Extension_Installer, 'mediawiki':Mediawiki_Installer,'naive': Naive_Installer, 'download':Download_Installer}
336347
 348+
337349 if __name__=="__main__":
338350 print "testing installers.py module"
339351 print "CTRL-C to abort. run installer.py to actually use the installer"

Status & tagging log