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()
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
`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
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"""