def GetOptionStringsForCommand(cmdName): result = "" try: cmdDict = GetHelpEntry("commands.{0}".format(cmdName)) try: options = ughubUtil.GetFromNestedTable(cmdDict, "options") for opt in options: optionstrings = opt["name"] # filter out [ ] optionstrings = optionstrings.replace("[", "").replace("]", "") # split optionstrings = optionstrings.split(" ") # which of those start with - or --? optionstrings = list( filter(lambda s: s.startswith('-') or s.startswith('--'), optionstrings)) for s in optionstrings: result += s + "\n" except ughubUtil.NestedTableEntryNotFoundError: pass except ughubUtil.NestedTableEntryNotFoundError: raise MalformedHelpContentsError( "Requested command '{0}' not found in help database".format( cmdName)) return result[:-1]
def PrintCommandHelp(cmdName): try: cmdDict = GetHelpEntry("commands.{0}".format(cmdName)) print("Usage: ughub {0}".format(cmdDict["usage"])) print("") for line in cmdDict["description"].splitlines(): print(" {0}".format(line)) try: options = ughubUtil.GetFromNestedTable(cmdDict, "options") print("") print("Valid options:") for opt in options: name = opt["name"] sep = ":" for line in opt["description"].splitlines(): print(" {0:20}{1} {2}".format(name, sep, line)) name = "" sep = " " except ughubUtil.NestedTableEntryNotFoundError: pass except ughubUtil.NestedTableEntryNotFoundError: raise MalformedHelpContentsError("Requested command '{0}' not found in help database" .format(cmdName))
def CallGitOnPackages(args, gitCommand): packages = LoadPackageDescs() fails = [] firstPackage = True # get the argument separator "---" gitargs = [] for i in range(len(args)): if args[i] == "---": gitargs = args[i+1:] args = args[0:i] break try: CacheGitPassword() except TransactionError as e: print("WARNING:\n " + str(e)) # print("args: {0}, gitargs: {1}".format(args, gitargs)) if len(args) > 0: for pname in args: if not firstPackage: print("") firstPackage = False try: pkg = ughubUtil.GetFromNestedTable(packages, pname) if not PackageIsInstalled(pkg): raise InvalidPackageError("Package '{0}' is not installed. See 'ughub help install'".format(pname)) try: CallGitOnPackage(pkg, gitCommand, gitargs) except TransactionError as e: fails.append(str(e)) except NestedTableEntryNotFoundError: raise fails.append("Unknown package '{0}'".format(pname)) else: # check for each known package whether it is installed. If this is the case, perform a pull for pkg in packages: if PackageIsInstalled(pkg): if not firstPackage: print("") firstPackage = False try: CallGitOnPackage(pkg, gitCommand, gitargs) except TransactionError as e: fails.append(str(e)) if len(fails) > 0: msg = "The following errors occurred while performing 'git {0}':".format(gitCommand) for e in fails: msg = msg + "\n - " + e raise TransactionError(msg)
def FilterPackagesAll(packages, categories): filteredPackages = [] for pkg in packages: try: pkgcats = ughubUtil.GetFromNestedTable(pkg, "categories") if all(cat in pkgcats for cat in categories): filteredPackages.append(pkg) except ughubUtil.NestedTableEntryNotFoundError: pass return filteredPackages
def PrintCommandHelp(cmdName, args=[]): shortdesc = ughubUtil.HasCommandlineOption(args, ("--short", )) try: cmdDict = GetHelpEntry("commands.{0}".format(cmdName)) except ughubUtil.NestedTableEntryNotFoundError: raise MalformedHelpContentsError( "Requested command '{0}' not found in help database".format( cmdName)) if shortdesc: if "shortdescription" in cmdDict: ughubUtil.Write(cmdDict["shortdescription"]) return print("Usage: ughub {0}".format(cmdDict["usage"])) print("") for line in cmdDict["description"].splitlines(): print(" {0}".format(line)) try: options = ughubUtil.GetFromNestedTable(cmdDict, "options") except ughubUtil.NestedTableEntryNotFoundError: return print("") print("Valid options:") for opt in options: name = opt["name"] sep = ":" for line in opt["description"].splitlines(): print(" {0:20}{1} {2}".format(name, sep, line)) name = "" sep = " "
def GetHelpEntry(entry): return ughubUtil.GetFromNestedTable(ughubHelpContents.content, entry)