From 91e480048492f96ead9dad4c76c4694e2e0ccadf Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 14 Jun 2009 21:21:55 -0400 Subject: [PATCH] Implement info command, also refactoring. Signed-off-by: Edward Z. Yang --- lib/wizard/command/info.py | 41 ++++++++++++++++++++++++++++++----- lib/wizard/command/summary.py | 7 +++--- lib/wizard/deploy.py | 7 +++--- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/lib/wizard/command/info.py b/lib/wizard/command/info.py index d17b9bf..924a2f0 100644 --- a/lib/wizard/command/info.py +++ b/lib/wizard/command/info.py @@ -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() diff --git a/lib/wizard/command/summary.py b/lib/wizard/command/summary.py index 2f1d0a6..cc05bb6 100644 --- a/lib/wizard/command/summary.py +++ b/lib/wizard/command/summary.py @@ -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 diff --git a/lib/wizard/deploy.py b/lib/wizard/deploy.py index 0389b41..cc8058d 100644 --- a/lib/wizard/deploy.py +++ b/lib/wizard/deploy.py @@ -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""" -- 2.45.2