Revision: 48543
Author:   kim
Date:     2009-03-18 23:24:29 +0000 (Wed, 18 Mar 2009)

Log Message:
-----------
* initial work on tags support.
* sort output from available.extension

Modified Paths:
--------------
    trunk/wikiation/installer/installation_system.py
    trunk/wikiation/installer/installer.py
    trunk/wikiation/installer/installer_util.py
    trunk/wikiation/installer/installers.py
    trunk/wikiation/installer/settings_handler.py

Added Paths:
-----------
    trunk/wikiation/installer/tags.py

Modified: trunk/wikiation/installer/installation_system.py
===================================================================
--- trunk/wikiation/installer/installation_system.py    2009-03-18 23:24:10 UTC 
(rev 48542)
+++ trunk/wikiation/installer/installation_system.py    2009-03-18 23:24:29 UTC 
(rev 48543)
@@ -6,6 +6,7 @@
 import settings_handler as settings
 import os, os.path, shutil
 import subprocess
+from tags import Tags
 
 
 class Installer_Exception (Exception):
@@ -45,8 +46,10 @@
                        if line.endswith(".install"):
                                installers2.append(line.replace(".install",""))
 
+               installers2.sort()
                return installers2
 
+       # XXX This should be a mixin
        def get_revisions(self,installer_name):
                """list the revisions a particular installer can install"""
                if not self.exists(installer_name):
@@ -54,6 +57,7 @@
 
                return self.do_get_revisions(installer_name)
 
+       # XXX this should be a mixin
        def do_get_revisions(self, installer_name):
                """actually perform the task of getting revisions for 
get_revisions
                First checks to see if someone has provided a script to 
determine
@@ -66,6 +70,12 @@
 
                return None
 
+       # XXX should be a mixin
+       def get_tags(self, installer_name):
+               """get list of tags available for this installer."""
+               return Tags().gettags(installer_name)
+               
+
        def get_svnbase():
                return None
 

Modified: trunk/wikiation/installer/installer.py
===================================================================
--- trunk/wikiation/installer/installer.py      2009-03-18 23:24:10 UTC (rev 
48542)
+++ trunk/wikiation/installer/installer.py      2009-03-18 23:24:29 UTC (rev 
48543)
@@ -30,6 +30,7 @@
 from installer_util import *
 from isolation import *
 from getch import getch
+from tags import Tags
 
 def intro():
        """a nice banner/intro text for interactive mode"""
@@ -138,12 +139,17 @@
        elif len(args)>=2:
                print "I'm not sure what to do with "+ (" ".join(args[1:]))
 
+       os.unlink(settings.tagcache)    #paranoia is good for you
+
        print "\n\n"
        print "wikiation_installer update attempted/completed. Restarting"
        print "----------------------------------------------------------"
        print "\n\n"
        os.execl("/usr/bin/python","/usr/bin/python",__file__)
 
+def update_tags(args):
+       """manually force update of the tag cache"""
+       Tags.update_cache_file()
 
 def main():
        """main function. start of execution when run from shell"""
@@ -184,6 +190,7 @@
        "info":info,
        "check_isolation":check_isolation,
        "update_self":update_self,
+       "update_tags":update_tags
 }
 
 # additional help texts for some commands.

Modified: trunk/wikiation/installer/installer_util.py
===================================================================
--- trunk/wikiation/installer/installer_util.py 2009-03-18 23:24:10 UTC (rev 
48542)
+++ trunk/wikiation/installer/installer_util.py 2009-03-18 23:24:29 UTC (rev 
48543)
@@ -32,15 +32,14 @@
                print "wikiation installer, interactive mode"
                print "help: get help"
                print "quit: quit"
-               print "ls [item]: list information on available versions "
-               print "ls2 [item]: list information on extensions or wikiation 
components"
-               print "install <version>: installs the version specified"
-               print "install <version> as <name>: installs the version 
specified under an alternate name"
-               print "install latest ; install latest as <name>: installs the 
latest version available in svn."
-               print "uninstall <version/name>: uninstalls the version 
specified"
-               print "check_isolation <version/name>: shows all changes made 
to mediawiki or database since it was installed."
+               print "ls <path>: list information on available versions "
+               print "install <path>: installs the version specified"
+               print "install <path> as <name>: installs the version specified 
under an alternate name"
+               print "uninstall <path>: uninstalls the version specified"
+               print "check_isolation <instance name>: shows all changes made 
to mediawiki or database since it was installed."
                print "update_self: updates the installer and restarts in 
interactive mode" 
-               print "revision [new revision]: query current default revision, 
or set a new one (will be implemented over time)" 
+               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)"
+               print "TODO: Implement help path , for now, see documentation 
for info on how to specify <path>"
                print
                print "instead of interactive mode, you can also access 
commands directly from the shell:"
                print "wikiation_installer command [args]..."

Modified: trunk/wikiation/installer/installers.py
===================================================================
--- trunk/wikiation/installer/installers.py     2009-03-18 23:24:10 UTC (rev 
48542)
+++ trunk/wikiation/installer/installers.py     2009-03-18 23:24:29 UTC (rev 
48543)
@@ -20,6 +20,8 @@
 from installation_system import Installer_Exception
 from download_installer import Download_Installer
 
+from tags import Tags, TagsException
+
 class Parse_Exception(Exception):
        pass
 
@@ -110,10 +112,17 @@
 
 
 def ls_tags(ppath):
-       print "To be implemented."
+       if not ppath["installer"]:
+               raise Listing_Exception("What extension would you like to know 
the available revisions for?")
 
+       system=get_system(ppath["system"])
+       try:
+               tags=system.get_tags(ppath["installer"])
+       except TagsException, e:
+               raise Listing_Exception(e.message)
+       
+       return tags
 
-
 def info(args):
        if len(args)<1:
                print "info: Internal error: expected more arguments"
@@ -331,8 +340,11 @@
 
                return sYstem()
 
+# Constants
+
 systems={'wikiation_toolkit':Toolkit_Installer,'extension': 
Extension_Installer, 'mediawiki':Mediawiki_Installer,'naive': Naive_Installer, 
'download':Download_Installer}
 
+
 if __name__=="__main__":
        print "testing installers.py module"
        print "CTRL-C to abort.   run installer.py to actually use the 
installer"

Modified: trunk/wikiation/installer/settings_handler.py
===================================================================
--- trunk/wikiation/installer/settings_handler.py       2009-03-18 23:24:10 UTC 
(rev 48542)
+++ trunk/wikiation/installer/settings_handler.py       2009-03-18 23:24:29 UTC 
(rev 48543)
@@ -18,12 +18,15 @@
 # where to find .install directories and the files contained therein
 installfiles=os.path.join(installerdir,'installfiles')
 
+# where do we store the _tagcache file
+tagcache=os.path.join(installerdir,"_tagcache")
 
 # where to find mediawiki tags and trunk on svn
 tagsdir="http://svn.wikimedia.org/svnroot/mediawiki/tags";
 trunkdir="http://svn.wikimedia.org/svnroot/mediawiki/trunk";
 # we could alternately/additionally take a tag version for extensions. (future)
-extensionsdir=trunkdir+"/extensions"
+extensionssubdir="extensions"
+extensionsdir=trunkdir+"/"+extensionssubdir
 
 # where to install diverse revisions
 instancesdir='/var/www/revisions'

Added: trunk/wikiation/installer/tags.py
===================================================================
--- trunk/wikiation/installer/tags.py                           (rev 0)
+++ trunk/wikiation/installer/tags.py   2009-03-18 23:24:29 UTC (rev 48543)
@@ -0,0 +1,103 @@
+import sys,os
+import os.path
+import settings_handler as settings
+import copy
+import cPickle as pickle
+import subprocess
+
+class TagsException(Exception):
+       pass
+
+class Tags:
+       """keep track of extension tags in svn.
+       the current repository is not optimised for the kinds
+       of queries the installer needs. We do the query once 
+       and cache it."""
+
+       def __init__(self):
+               # try to load preexisting cache
+               self.cache=self.load_cache()
+               # No joy? Let's generate one.
+               if not self.cache:
+                       self.cache=self.update_cache()
+               # Still no joy? 
+               if not self.cache:
+                       raise Exception("Internal error: cannot obtain a tag 
cache")
+
+       @classmethod
+       def load_cache(self):
+               """load tags from cache"""
+               if not os.path.isfile(settings.tagcache):
+                       return None
+
+               cache=pickle.load(file(settings.tagcache))
+               return cache
+
+       @classmethod
+       def svnlist(self,dir):
+               """generic obtain data from svn ls
+                       (TODO: refactor, overlaps with DownloadInstaller 
get_installers)"""
+               
+               command=['svn','ls',dir]
+               process=subprocess.Popen(command,stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)
+               failp=process.stderr.read()
+               if failp:
+                       return None
+               l=list(process.stdout)
+               # tidy l in place
+               for i in range(len(l)):
+                       l[i]=l[i].strip()
+                       if l[i].endswith("/"):
+                               l[i]=l[i][:-1]
+               return l
+
+       def update_cache(self):
+               """update cache to disk and to memory"""
+               self.cache=self.update_cache_file()
+               return self.cache
+
+       @classmethod
+       def update_cache_file(self):
+               """update cache to disk. returns a cache. This is an expensive 
operation.
+                  (cache format is {"extension name":["tag1", "tag2", "tag3", 
...]}, ...)
+               """
+               print "Updating tags cache, this takes a minute or so."
+               print "(Items marked with '*' do not seem to contain 
extensions)"
+               cache={}
+               tags=self.svnlist(settings.tagsdir)
+               for tag in tags:
+                       sys.stdout.write(tag)
+                       sys.stdout.flush()
+
+                       
extensions=self.svnlist(settings.tagsdir+"/"+tag+"/"+settings.extensionssubdir)
+                       if extensions==None:
+                               extensions=[]
+                               sys.stdout.write('*')
+                               sys.stdout.flush()
+                       for extension in extensions:
+                               if extension not in cache:
+                                       cache[extension]=[]
+                               cache[extension].append(tag)
+                       sys.stdout.write('; ')
+                       sys.stdout.flush()
+
+               #store cache to disk
+               pickle.dump(cache, 
file(settings.tagcache,"w"),pickle.HIGHEST_PROTOCOL)
+               
+               #make empty line
+               print
+               print "completed."
+               return cache
+
+       def gettags(self,extension):
+               if extension not in self.cache:
+                       raise TagsException("Could not find extension 
"+str(extension)+".")
+               
+               tags=self.cache[extension]
+               return copy.copy(tags)
+
+if __name__=="__main__":
+       tags=Tags()
+       print "Imagemap: ",tags.gettags("ImageMap")
+       print "Cite: ", tags.gettags("Cite")
+



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to