]> scripts.mit.edu Git - wizard.git/commitdiff
Implement info command, also refactoring.
authorEdward Z. Yang <edwardzyang@thewritingpot.com>
Mon, 15 Jun 2009 01:21:55 +0000 (21:21 -0400)
committerEdward Z. Yang <edwardzyang@thewritingpot.com>
Mon, 15 Jun 2009 01:21:55 +0000 (21:21 -0400)
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
lib/wizard/command/info.py
lib/wizard/command/summary.py
lib/wizard/deploy.py

index d17b9bf22467364f2f5e4f0718c6f143fe2be2ef..924a2f0c9709558df4d531008e12288d72580e31 100644 (file)
@@ -1,21 +1,52 @@
 import optparse
 import sys
+import subprocess
 
 import wizard.deploy as wd
 
+def prettify(loc):
+    return loc.replace("/afs/athena.mit.edu/contrib/", "/mit/")
+
+def indent(text, indent):
+    # There should be a built-in
+    return "\n".join([" " * indent + x for x in text.split("\n")])
+
 def main(argv, global_options):
     usage = """usage: %prog info [ARGS] DIR
 
 Prints information about an autoinstalled directory,
 including its history and current version."""
     parser = optparse.OptionParser(usage)
-    #parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
-    #        default=False, help="Print all commands and outputs")
+    parser.add_option("--reverse", dest="reverse", action="store_true",
+            default=False, help="Print entries in chronological order (default is reverse)")
     options, args = parser.parse_args(argv)
     if len(args) > 1:
         parser.error("too many arguments")
     elif not args:
         parser.error("must specify directory")
-    dir = args[0]
-    print dir
-    print options
+    deploy = wd.Deployment.fromDir(args[0])
+    deploy.getLog() # force the log to be loaded, to pre-empt errors
+    proc = False
+    # This is prime candidate for refactoring. This code pipes
+    # stdout to less, so that you get scrolling and stuff.
+    if sys.stdout.isatty():
+        proc = subprocess.Popen("less", stdin=subprocess.PIPE)
+        sys.stdout = proc.stdin
+    try:
+        if options.reverse: munge = lambda x: x
+        else: munge = reversed
+        for entry in munge(deploy.getLog()):
+            print "%s %s" % (entry.version.application.name, entry.version.version)
+            print "User: %s" % entry.user
+            print "Date: %s" % entry.datetime.strftime("%a %b %0d %H:%M:%S %Y %z")
+            print
+            info = "Unknown"
+            if isinstance(entry.source, wd.TarballInstall):
+                info = "Installed with tarball at:\n%s" % \
+                    prettify(entry.source.location)
+            print indent(info, 4)
+            print
+    finally:
+        if proc:
+            proc.stdin.close()
+            proc.wait()
index 2f1d0a679d139dbbbfb4698bb513ab6f43be2e4b..cc05bb63c8fd4bbf7c135b5346e3dba500a0d46f 100644 (file)
@@ -74,10 +74,11 @@ Examples:
         except wd.NoSuchApplication:
             unrecognized += 1
             continue
-        if deploy.application.name + "-" + str(deploy.getVersion()) in show:
+        name = deploy.getApplication().name
+        if name + "-" + str(deploy.getVersion()) in show:
             printer.write("%s-%s deployment at %s" \
-                % (deploy.application.name, deploy.getVersion(), deploy.location))
-        elif deploy.application.name in show:
+                % (name, deploy.getVersion(), deploy.location))
+        elif name in show:
             pass
         else:
             continue
index 0389b41395a5d3657446972e4dec23c26dc5cfd2..cc8058d7ab5e3bbfaca4df3497253425506ceef2 100644 (file)
@@ -28,7 +28,6 @@ class Deployment(object):
             `version`   ApplicationVersion of the app (this is cached info)
             `log`       DeployLog of the app"""
         self.location = location
-        self.application = version.application
         self._version = version
         self._log = log
     @staticmethod
@@ -45,11 +44,13 @@ class Deployment(object):
     def fromDir(dir):
         """Lazily creates a deployment from a directory"""
         return Deployment(dir)
-    def getVersionFile():
+    def getVersionFile(self):
         return os.path.join(self.location, '.scripts-version')
+    def getApplication(self):
+        return self.getAppVersion().application
     def getLog(self):
         if not self._log:
-            self._log = DeployLog(self.getVersionFile)
+            self._log = DeployLog.load(self.getVersionFile())
         return self._log
     def getVersion(self):
         """Returns the distutils Version of the deployment"""