]> scripts.mit.edu Git - wizard.git/commitdiff
More refactoring.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 14 Jun 2009 21:03:26 +0000 (17:03 -0400)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Sun, 14 Jun 2009 21:03:26 +0000 (17:03 -0400)
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
bin/wizard
lib/wizard/command/summary.py
lib/wizard/deploy.py

index 4eefba363bfaf27982eb2460114a9633da746b46..916a292528aa7d21b6176063af0220b0f6e470ce 100755 (executable)
@@ -48,9 +48,10 @@ See '%prog help COMMAND' for more information on a specific command."""
             raise SystemExit(-1)
     # Dispatch commands
     try:
-        getattr(wizard.command, command).main(rest_argv, options)
+        command_module = getattr(wizard.command, command)
     except AttributeError:
         parser.error("invalid action")
+    command_module.main(rest_argv, options)
 
 if __name__ == "__main__":
     main()
index 8589e29eef7dfd81a7e60971ef6abf397766fd9f..689225c139c97a191f3081844b5a05d6c9b73a10 100644 (file)
@@ -74,9 +74,9 @@ Examples:
         except wd.NoSuchApplication:
             unrecognized += 1
             continue
-        if deploy.application.name + "-" + str(deploy.version.version) in show:
+        if deploy.application.name + "-" + str(deploy.getVersion()) in show:
             printer.write("%s-%s deployment at %s" \
-                % (deploy.application.name, deploy.version.version, deploy.location))
+                % (deploy.application.name, deploy.getVersion(), deploy.location))
         elif deploy.application.name in show:
             pass
         else:
index 84166bd5e6e00b911ea723a44d0b85903654844e..cf5576926e24554b588a005141327ca8dd90e445 100644 (file)
@@ -23,10 +23,15 @@ class DeploymentParseError(Exception):
 class Deployment(object):
     """Represents a deployment of an autoinstall; i.e. a concrete
     directory in web_scripts that has .scripts-version in it."""
-    def __init__(self, location, version):
+    def __init__(self, location, log=None, version=None):
+        """ `location`  Location of the deployment
+            `version`   ApplicationVersion of the app (this is cached info)
+            `log`       DeployLog of the app"""
         # XXX: This constructor should change
         self.location = location
-        self.version = version
+        self._version = version
+        self._log = log
+        # Maybe should be an accessor
         self.application = version.application
     @staticmethod
     def parse(line):
@@ -47,7 +52,7 @@ class Deployment(object):
         else:
             raise DeploymentParseError
         try:
-            return Deployment(location, applications[app].getVersion(version))
+            return Deployment(location, version=applications[app].getVersion(version))
         except KeyError:
             raise NoSuchApplication
     @staticmethod
@@ -55,15 +60,28 @@ class Deployment(object):
         """Creates a deployment from a directory"""
         version_file = os.path.join(dir, '.scripts-version')
         # needs deployment log
+    def getLog(self):
+        if not self._log:
+            # XXX: Load the deployment log
+            raise NotImplemented
+        return self._log
+    def getVersion(self):
+        """Returns the distutils Version of the deployment"""
+        return self.getAppVersion().version
+    def getAppVersion(self, force = False):
+        """Returns the ApplicationVersion of the deployment"""
+        if self._version and not force: return self._version
+        else: return self.getLog()[-1].version
+    # XXX: This is summary specific code
     def count(self):
         """Simple method which registers the deployment as a +1 on the
         appropriate version. No further inspection is done."""
-        self.version.count(self)
+        self.getAppVersion().count(self)
         return True
     def count_exists(self, file):
         """Checks if the codebase has a certain file/directory in it."""
         if os.path.exists(self.location + "/" + file):
-            self.version.count_exists(self, file)
+            self.getAppVersion().count_exists(self, file)
             return True
         return False
 
@@ -96,11 +114,14 @@ class Application(object):
             ret.append("%d users have %s" % (c,f))
         return "\n".join(ret)
 
-class DeployLog(object):
+class DeployLog(list):
+    # As per #python; if you decide to start overloading magic methods,
+    # we should remove this subclass
     """Equivalent to .scripts-version: a series of DeployRevisions."""
     def __init__(self, revs = []):
         """`revs`  List of DeployRevision objects"""
-        self.revs = revs
+        # pass to list
+        list.__init__(self, revs)
     @staticmethod
     def load(file):
         """Loads a scripts version file and parses it into
@@ -129,6 +150,8 @@ class DeployLog(object):
             i += 1
         if i: revs.append(rev)
         return DeployLog(revs)
+    def __repr__(self):
+        return '<DeployLog %s>' % list.__repr__(self)
 
 class DeployRevision(object):
     """A single entry in the .scripts-version file. Contains who deployed