def help_(): print() printNormal(" The following commands are available:\n "), c.printBold(", ".join(commands)) printNormal( '\n Once you have the env.sh sourced, most commands\n can also be used with "mars_command" to have\n autocompletion (e.g. mars_install)\n' )
def diff_(): global cfg layout_packages = [] cfg["update"] = False if len(sys.argv) < 3: buildconf.fetchPackages(cfg, layout_packages) else: if sys.argv[2] == "buildconf": diff_remotes() else: buildconf.fetchPackage(cfg, sys.argv[2], layout_packages) deps = [] checked = [] if cfg["checkDeps"]: for p in layout_packages: bob_package.getDeps(cfg, p, deps, checked) toInstall = [] diffs = [] for d in deps[::-1]: if d not in toInstall: toInstall.append(d) for p in layout_packages: if p not in toInstall: toInstall.append(p) for p in toInstall: if p in cfg["osdeps"]: continue if p in cfg["ignorePackages"] or "orogen" in p: continue if p in cfg["overrides"] and "fetch" in cfg["overrides"][p]: continue path = cfg["devDir"] + "/" + p p2 = p while not os.path.isdir(path + "/.git"): path = "/".join(path.split("/")[:-1]) p2 = "/".join(p2.split("/")[:-1]) if path == cfg["devDir"]: break if path == cfg["devDir"]: cfg["errors"].append("missing: git for " + p) continue if path not in diffs: diffs.append(path) out, err, r = execute.do( ["git", "diff"], cfg, None, path) #, p2.replace("/", "_")+"_diff.txt") if out: logFile = cfg["devDir"] + "/autoproj/bob/logs/" + p2.replace( "/", "_") + "_diff.txt" print(p2 + ": ", end="") c.printWarning("has diff") print(" check: less " + logFile) sys.stdout.flush() with open(logFile, "w") as f: f.write(out) else: print(p2 + ": ", end="") c.printBold("no diff")
def list_(): global cfg packages, w = buildconf.listPackages(cfg) for p in packages: if len(p[1]) > 0: print p[0], c.printBold(p[1]) else: print p[0], c.printWarning(p[0])
def diff_remotes(): global cfg path = cfg["devDir"] + "/autoproj/remotes" for d in os.listdir(path): if os.path.isdir(path+"/"+d+"/.git"): out, err, r = execute.do(["git", "diff"], cfg, None, path+"/"+d) if out: logFile = cfg["devDir"] + "/autoproj/bob/logs/"+d.replace("/", "_")+"_diff.txt" print d+": ", c.printWarning("has diff") print " check: less " + logFile with open(logFile, "w") as f: f.write(out) else: print d+": ", c.printBold("no diff")
def getConfiguration(cfg): platform = system() # check wether we have a config file path = ".." if "AUTOPROJ_CURRENT_ROOT" in os.environ: path = os.environ["AUTOPROJ_CURRENT_ROOT"] if os.path.isfile(path + "/pybob/pybob.yml"): try: cfg["numCores"] = multiprocessing.cpu_count() except: cfg["numCores"] = 1 with open(path + "/pybob/pybob.yml") as f: cfg.update(yaml.load(f)) else: # check if we have an autoproj environment if os.path.isfile(path + "/autoproj/config.yml"): acfg = {} with open(path + "/autoproj/config.yml") as f: acfg = yaml.load(f) cfg["pyScriptDir"] = path + "/pybob" cfg["devDir"] = path cfg["numCores"] = multiprocessing.cpu_count() if (acfg["autoproj_use_prerelease"]): cfg["defBuildType"] = "release" else: cfg["defBuildType"] = "debug" cfg["rockFlavor"] = acfg["ROCK_FLAVOR"] cfg["autoprojEnv"] = True else: cfg["autoprojEnv"] = False # we assume this script is executed from one folder above scriptDir = os.getcwd() # convert cwd on windows if neseccary cfg["pyScriptDir"] = scriptDir arrDevDir = scriptDir.split("/") arrDevDir.pop() if arrDevDir[-1] == "bootstrap": arrDevDir.pop() devDir = "/".join(arrDevDir) # get the dev dir # c.printBold("You must set a root directory where all repositories will be checked out and all packages will be installed") # in_ = raw_input_("Enter root directory or nothing for [\""+devDir+"\"]: ") # if len(in_) > 0: # devDir = in_ if devDir[-1] == "/": devDir.pop() cfg["devDir"] = devDir # get the numbers of cores to build print() # c.printBold("You can specify the number of CORES you want to use when compiling packages.") try: cfg["numCores"] = multiprocessing.cpu_count() except: cfg["numCores"] = 1 # in_ = raw_input_("Enter number of CORES ["+str(cfg["numCores"])+"]): ") # if len(in_) > 0: # cfg["numCores"] = int(in_) # get the default build type cfg["defBuildType"] = "debug" # pattern = ["debug", "release"] # print() # buildType = raw_input_("Enter default build type (debug|release) [debug]: ") # if buildType in pattern: # cfg["defBuildType"] = str(buildType) # get the default rock flavor cfg["rockFlavor"] = "master" # pattern = ["stable", "master"] # print() # flavor = raw_input_("Enter default rock flavor (stable|master) [master]: ") # if flavor in pattern: # cfg["rockFlavor"] = str(flavor) print() if not "buildconfAddress" in cfg: in_ = raw_input_("Enter git address of buildconf to clone: ") if len(in_) > 0: cfg["buildconfAddress"] = in_ print() cfg["buildconfBranch"] = "" # in_ = raw_input_("Enter branch of buildconf [default]: ") # if len(in_) > 0: # cfg["buildconfBranch"] = in_ path = "/usr/src/app" c.printBold("The configuration is written to \"" + path + "/pybob/pybob.yml\".\n") with open(path + "/pybob/pybob.yml", "w") as f: yaml.dump(cfg, f, default_flow_style=False) cfg["path"] = path print(path) return cfg
def install_(): global cfg layout_packages = [] cfg["update"] = False if len(sys.argv) < 3: buildconf.fetchPackages(cfg, layout_packages) else: buildconf.fetchPackage(cfg, sys.argv[2], layout_packages) deps = [] checked = [] if cfg["checkDeps"]: for p in layout_packages: bob_package.getDeps(cfg, p, deps, checked) #print deps toInstall = [] for d in deps[::-1]: if d not in toInstall: toInstall.append(d) for p in layout_packages: if p not in toInstall: toInstall.append(p) while len(toInstall) > 0: threads = [] jobs = [] iList = list(toInstall) toInstall = [] for p in iList: wait = False #c.printWarning(str(cfg["deps"][p])) if p in cfg["deps"]: for d in cfg["deps"][p]: if d in iList: wait = True break if not wait: jobs.append(p) if p in cfg["overrides"] and "install" in cfg["overrides"][p]: if cfg["multiprocessing"]: threads.append(Thread(target=cfg["overrides"][p]["install"], args=(cfg,))) else: c.printNormal("Install: "+p) le = len(cfg["errors"]) cfg["overrides"][p]["install"](cfg) if len(cfg["errors"]) <= le: c.printWarning("done") else: c.printError("error") elif p in cfg["osdeps"]: # os deps are installed in fetch phase continue else: if cfg["multiprocessing"]: threads.append(Thread(target=bob_package.installPackage, args=(cfg, p))) else: c.printNormal("Install: "+p) le = len(cfg["errors"]) bob_package.installPackage(cfg, p) if len(cfg["errors"]) <= le: c.printWarning("done") else: c.printError("error") else: toInstall.append(p) if cfg["multiprocessing"]: c.printBold("Install: "+str(jobs)) le = len(cfg["errors"]) for t in threads: t.start() for t in threads: t.join() if len(cfg["errors"]) > le: foo = ""
if "error" in l: c.printError(l.strip()) else: c.printNormal(l.strip()) def help_(): print printNormal(" The following commands are available:\n "), c.printBold(", ".join(commands)) printNormal('\n Once you have the env.sh sourced, most commands\n can also be used with "mars_command" to have\n autocompletion (e.g. mars_install)\n') env.setupEnv(cfg, False) if __name__ == "__main__": if len(sys.argv) < 2 or sys.argv[1] not in commands: print c.printBold("Please specify an action. Your options are:\n" + ", ".join(commands) + "\n") exit(0) if "-n" in sys.argv: cfg["checkDeps"] = False globals()[sys.argv[1].replace("-", "_")+"_"]() printErrors() if len(cfg["profiling"]) > 0: with open(cfg["devDir"]+"/autoproj/bob/profiling.yml", "w") as f: yaml.dump(cfg["profiling"], f, default_flow_style=False) if len(cfg["depsInverse"]) > 0: with open(cfg["devDir"]+"/autoproj/bob/depsInverse.yml", "w") as f: yaml.dump(cfg["depsInverse"], f, default_flow_style=False)
def install_(): global cfg layout_packages = [] cfg["update"] = False filterArgs = ["-n", "-k"] if len(sys.argv) < 3 or sys.argv[2] in filterArgs: # search path upwards for a manifest.xml # if not found build manifest from buildconf pathToCheck = os.getcwd() found = False done = False while not done: if os.path.isfile(pathToCheck + "/manifest.xml"): found = True done = True elif os.path.exists(pathToCheck + "/autoproj"): # found dev root done = True else: arrPath = pathToCheck.split("/") if len(arrPath) == 1: done = True else: pathToCheck = "/".join(arrPath[:-1]) if found: layout_packages.append(os.path.relpath(pathToCheck, cfg["devDir"])) else: buildconf.fetchPackages(cfg, layout_packages) else: pathToCheck = os.path.join(os.getcwd(), sys.argv[2]) if os.path.isfile(pathToCheck + "/manifest.xml"): layout_packages.append(os.path.relpath(pathToCheck, cfg["devDir"])) else: buildconf.fetchPackage(cfg, sys.argv[2], layout_packages) deps = [] checked = [] if cfg["checkDeps"]: for p in layout_packages: bob_package.getDeps(cfg, p, deps, checked) toInstall = [] for d in deps[::-1]: if d not in toInstall: toInstall.append(d) for p in layout_packages: if p not in toInstall: toInstall.append(p) iList = [] while len(toInstall) > 0: threads = [] jobs = [] oldList = iList iList = list(toInstall) if oldList == iList: # detect unresolved deps loop for p in oldList: c.printError("detect dependency cycle:\n " + str(p)) c.printWarning(" deps:") if p in cfg["deps"]: for d in cfg["deps"][p]: if d in iList: c.printWarning(" - " + str(d)) exit(-1) toInstall = [] for p in iList: wait = False if p in cfg["deps"]: for d in cfg["deps"][p]: if d in iList: wait = True break if not wait: jobs.append(p) if p in cfg["overrides"] and "install" in cfg["overrides"][p]: if cfg["multiprocessing"]: threads.append( Thread(target=cfg["overrides"][p]["install"], args=(cfg, ))) else: c.printNormal("Install: " + p) le = len(cfg["errors"]) cfg["overrides"][p]["install"](cfg) if len(cfg["errors"]) <= le: c.printWarning("done") else: c.printError("error") elif p in cfg["osdeps"]: # os deps are installed in fetch phase continue else: if cfg["multiprocessing"]: threads.append( Thread(target=bob_package.installPackage, args=(cfg, p))) else: c.printNormal("Install: " + p) le = len(cfg["errors"]) bob_package.installPackage(cfg, p) if len(cfg["errors"]) <= le: c.printWarning("done") else: c.printError("error") else: toInstall.append(p) if cfg["multiprocessing"]: c.printBold("Install: " + str(jobs)) le = len(cfg["errors"]) for t in threads: t.start() for t in threads: t.join() if len(cfg["errors"]) > le: foo = ""