X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/a626803f9eff59e5053b0a75d8675130e720846c..b1e094209f44a25efd1cefa5aea6b62cee049085:/wizard/command/info.py diff --git a/wizard/command/info.py b/wizard/command/info.py new file mode 100644 index 0000000..c5c335c --- /dev/null +++ b/wizard/command/info.py @@ -0,0 +1,52 @@ +import optparse +import sys +import subprocess + +from wizard import deploy + +def prettify(loc): + return loc.replace("/afs/athena.mit.edu/contrib/scripts", "~scripts") + +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("--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") + d = deploy.Deployment.fromDir(args[0]) + d.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(d.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, deploy.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()