workspace_status.py
Go to the documentation of this file.
00001 """
00002 The workspace status command produces a github markdown compatible
00003 table of the current worspace.
00004 
00005 Copyright 2015 Fetch Robotics Inc.
00006 Author: Alex Henning
00007 """
00008 
00009 import os
00010 import subprocess
00011 
00012 from ..util import add_workspace
00013 
00014 name = "workspace-status"
00015 help_text = "Print the status of the current workspace"
00016 
00017 
00018 def main(args):
00019     print "Status of %s: " % (args.workspace+"/src")
00020     data = []
00021     for name in [i for i in os.listdir(args.workspace+"/src")
00022                  if os.path.isdir(args.workspace+"/src/"+i)]:
00023         dir = args.workspace+"/src/"+name
00024         if os.path.isdir(dir+"/.git"):
00025             branch = subprocess.check_output("cd %s && git rev-parse --abbrev-ref HEAD" % dir, shell=True).strip()
00026             sha = subprocess.check_output("cd %s && git describe --always --dirty" % dir, shell=True).strip()
00027             data.append((name, branch, sha))
00028         else:
00029             data.append((name, "None", "untracked"))
00030 
00031     data.sort()
00032     name_len = max([len(name) for name, _, _ in data])
00033     branch_len = max([len(branch) for _, branch, _ in data])
00034     sha_len = max([len(sha) for _, _, sha in data])
00035 
00036     print "%s%s | %s%s | %s%s" % ("Name", " "*(name_len-len("name")),
00037                                   "Branch", " "*(branch_len-len("branch")),
00038                                   "SHA1", " "*(sha_len-len("sha1")))
00039     print "%s|%s|%s" % ("-"*(1+name_len), "-"*(2+branch_len), "-"*(1+sha_len))
00040     for name, branch, sha in data:
00041         print "%s%s | %s%s | %s%s" % (name, " "*(name_len-len(name)),
00042                                       branch, " "*(branch_len-len(branch)),
00043                                       sha, " "*(sha_len-len(sha)),)
00044 
00045 def add_arguments(parser):
00046     add_workspace(parser)


fetch_tools
Author(s): Alex Henning
autogenerated on Thu Jun 6 2019 21:10:20