5 from wizard import deploy
8 return loc.replace("/afs/athena.mit.edu/contrib/scripts", "~scripts")
10 def indent(text, indent):
11 # There should be a built-in
12 return "\n".join([" " * indent + x for x in text.split("\n")])
14 def main(argv, global_options):
15 usage = """usage: %prog info [ARGS] DIR
17 Prints information about an autoinstalled directory,
18 including its history and current version."""
19 parser = optparse.OptionParser(usage)
20 parser.add_option("--reverse", dest="reverse", action="store_true",
21 default=False, help="Print entries in chronological order (default is reverse)")
22 options, args = parser.parse_args(argv)
24 parser.error("too many arguments")
26 parser.error("must specify directory")
27 d = deploy.Deployment.fromDir(args[0])
28 d.getLog() # force the log to be loaded, to pre-empt errors
30 # This is prime candidate for refactoring. This code pipes
31 # stdout to less, so that you get scrolling and stuff.
32 if sys.stdout.isatty():
33 proc = subprocess.Popen("less", stdin=subprocess.PIPE)
34 sys.stdout = proc.stdin
36 if options.reverse: munge = lambda x: x
37 else: munge = reversed
38 for entry in munge(d.getLog()):
39 print "%s %s" % (entry.version.application.name, entry.version.version)
40 print "User: %s" % entry.user
41 print "Date: %s" % entry.datetime.strftime("%a %b %0d %H:%M:%S %Y %z")
44 if isinstance(entry.source, deploy.TarballInstall):
45 info = "Installed with tarball at:\n%s" % \
46 prettify(entry.source.location)