def rpm_install(namelist): v.print_v(v.PDEBUG, "rpm install: "+str(namelist)) try: nlj = namelist.name; except: if(namelist.combiner == "&&"): print "Multiple packages provided, installing both" return rpm_install(namelist.first) and rpm_install(namelist.second); elif(namelist.combiner == "||"): print "Multiple options provided, checking to see which is acceptable" if (rpm_exists(namelist.first.name, comparator=namelist.first.compare, version=namelist.first.version)): print "The first option succeeded, installing %s" % (namelist.first.name) return rpm_install(namelist.first) elif (rpm_exists(namelist.second.name, comparator=namelist.second.compare, version=namelist.second.version)): print "The second option succeeded, installing %s" % (namelist.second.name) return rpm_install(namelist.second) else: print "Neither option succeeded, this should not have happened!" return False else: print "invalid combiner logic." return false; # if(namelist is list): # nlj = " ".join(namelist); return sudorun("yum -y install %s"%(nlj));
def rpm_install(namelist): v.print_v(v.PDEBUG, "rpm install: " + str(namelist)) try: nlj = namelist.name except: if (namelist.combiner == "&&"): print "Multiple packages provided, installing both" return rpm_install(namelist.first) and rpm_install(namelist.second) elif (namelist.combiner == "||"): print "Multiple options provided, checking to see which is acceptable" if (rpm_exists(namelist.first.name, comparator=namelist.first.compare, version=namelist.first.version)): print "The first option succeeded, installing %s" % ( namelist.first.name) return rpm_install(namelist.first) elif (rpm_exists(namelist.second.name, comparator=namelist.second.compare, version=namelist.second.version)): print "The second option succeeded, installing %s" % ( namelist.second.name) return rpm_install(namelist.second) else: print "Neither option succeeded, this should not have happened!" return False else: print "invalid combiner logic." return false # if(namelist is list): # nlj = " ".join(namelist); return sudorun("yum -y install %s" % (nlj))
def shellexec_shell(cmd, throw_ex): v.print_v(v.PDEBUG, "shellexec_long: " + cmd) try: result = None quitEvent = Event() monitorThread = Thread(target=monitor, args=( cmd, quitEvent, )) monitorThread.start() while monitorThread.isAlive: monitorThread.join(1) if quitEvent.isSet(): logger.info("shellexec_shell: Caught the quit Event") break return monitor.result except KeyboardInterrupt: logger.info( "shellexec_shell: Caught Ctl+C. Killing all threads. Patience...") quitEvent.set() time.sleep(10) exit(0) except Exception, e: if (throw_ex): raise e else: return -1
def install(pkgname, die_if_already=False): if not check_recipe(pkgname): die("unknown package " + pkgname) if die_if_already and check_installed(pkgname): print pkgname + " already installed" return validate_write_perm(vars["prefix"]) rc = global_recipes[pkgname] pkg_missing = rc.recursive_satisfy() # remove duplicates while preserving list order (lowest nodes first) pkg_missing = list_unique_ord(pkg_missing) v.print_v( v.INFO, "Installing packages:\n" + "\n".join(["* {0}".format(x) for x in pkg_missing])) # prompt if list is ok? # provide choice of deb satisfiers or source build? for pkg in pkg_missing: global_recipes[pkg].install() if (pkg == "gnuradio"): if (confirm("Run VOLK Profile to choose fastest kernels?", "Y", 5)): run_volk_profile()
def bashexec(cmd, o_proc=None): """ Launch a bash and run 'cmd' inside it. If an output processor is given, a thread is spawned to poll the output and feed it to the processor. Otherwise, the output is displayed verbatim. """ if cmd.strip() == "": return 0 v.print_v(v.PDEBUG, "bash exec (%s):: %s" % (os.getcwd(), cmd.strip())) if (cmd[-1] != "\n"): cmd += "\n" extra_popen_args = {} if isinstance(o_proc, output_proc.OutputProcessor): extra_popen_args = o_proc.extra_popen_args from subprocess import Popen, PIPE p = subprocess.Popen(["bash"], stdin=subprocess.PIPE, shell=True, env=globals.env, **extra_popen_args) p.stdin.write(cmd) p.stdin.close() if isinstance(o_proc, output_proc.OutputProcessor): st = output_proc.run_with_output_processing(p, o_proc) else: st = p.wait() # unless background execution preferred v.print_v(v.PDEBUG, "bash return val = %d" % (st)) return st
def fetch(self): # this is not possible if we do not have sources if (len(self.source) == 0): v.print_v( v.WARN, "WARNING: no sources available for package %s!" % (self.name)) return True fetcher = fetch.fetcher(self.source, self) fetcher.fetch() if (not fetcher.success): if (len(self.source) == 0): raise PBRecipeException( "Failed to Fetch package '%s' no sources were provided! '%s'!" % (self.name, self.source)) else: raise PBRecipeException( "Failed to Fetch package '%s' sources were '%s'!" % (self.name, self.source)) # update value in inventory inv.set_state(self.name, "fetch") self.last_fetcher = fetcher v.print_v( v.DEBUG, "Setting fetched version info (%s,%s)" % (fetcher.used_source, fetcher.version)) inv.set_prop(self.name, "source", fetcher.used_source) inv.set_prop(self.name, "version", fetcher.version)
def env_init(vars): v.print_v(v.DEBUG, "Initializing environmental variables...") env = os.environ env["PATH"] = vars["prefix"] + "/bin/:" + tryenv("PATH") env["PATH"] = tryenv("PATH") + ":/usr/lib64/qt4/bin/" env["PYTHONPATH"] = vars["prefix"] + "/python/:" for pyname in ["python2.6","python2.7"]: for moddir in ["site-packages","dist-packages"]: env["PYTHONPATH"] = env["PYTHONPATH"] + vars["prefix"] + "/lib/%s/%s/:"%(pyname,moddir) env["PYTHONPATH"] = env["PYTHONPATH"] + vars["prefix"] + "/lib64/%s/%s/:"%(pyname,moddir) env["PYTHONPATH"] = env["PYTHONPATH"] + tryenv("PYTHONPATH") if env["PYTHONPATH"][-1] == ":": env["PYTHONPATH"] = env["PYTHONPATH"][:-1] v.print_v(v.DEBUG, "$PYTHONPATH = {0}".format(env["PYTHONPATH"])) env["ATLAS"] = vars["prefix"] + "/lib/libatlas.so:/usr/local/lib/:/usr/lib/" env["BLAS"] = vars["prefix"] + "/lib/libblas.so:/usr/local/lib/:/usr/lib/" env["LAPACK"] = vars["prefix"] + "/lib/liblapack.so:/usr/local/lib:/usr/lib/" env["BOOST_ROOT"] = vars["prefix"] env["BOOST_LIBRARYDIR"] = vars["prefix"] + "/lib/:" + vars["prefix"] + "/lib64/:" env["PREFIX"] = vars["prefix"] env["GTEST_DIR"] = vars["prefix"] + "/gtest" #env["PYTHONPATH"] = vars["prefix"] + "/lib/python2.6/site-packages/:" + vars["prefix"] + tryenv("PYTHONPATH") tryenv("PYTHONPATH") env["LD_LIBRARY_PATH"] = vars["prefix"] + "/lib/:" + vars["prefix"] + "/lib64/:" + tryenv("LD_LIBRARY_PATH") tryenv("LD_LIBRARY_PATH") env["PKG_CONFIG_PATH"] = vars["prefix"] + "/lib/pkgconfig/:" + vars["prefix"] + "/lib64/pkgconfig/:" + tryenv("PKG_CONFIG_PATH") tryenv("PKG_CONFIG_PATH") return env
def sudorun(cmd): if(os.geteuid() == 0): rv = bashexec("%s"%(cmd)); elif(enable_sudo): rv = bashexec("sudo %s"%(cmd)); else: v.print_v(v.ERROR, RED + " *** ERROR: re-run as root to apt-get install %s! *** "%(nlj) + ENDC) return False; return rv==0;
def sudorun(cmd): if(os.geteuid() == 0): rv = bashexec("%s"%(cmd)); elif(enable_sudo): rv = bashexec("sudo %s"%(cmd)); else: v.print_v(v.ERROR, RED + " *** ERROR: re-run as root to apt-get install %s! *** "%(nlj) + ENDC) return False; return rv==0;
def rpm_install(namelist): v.print_v(v.PDEBUG, "rpm install: "+str(namelist)) try: nlj = namelist.name; except: return True; if(namelist is list): nlj = " ".join(namelist); return sudorun("yum -y install %s"%(nlj));
def rpm_install(namelist): v.print_v(v.PDEBUG, "rpm install: "+str(namelist)) try: nlj = namelist.name; except: return True; if(namelist is list): nlj = " ".join(namelist); return sudorun("yum -y install %s"%(nlj));
def fancy_var_replace(self, s, d): finished = False while not finished: os = s for k in d.keys(): s = s.replace("$%s" % (k), d[k]) v.print_v(v.PDEBUG, (s, os)) if (os == s): finished = True return s
def fancy_var_replace(self,s,d): finished = False while not finished: os = s; for k in d.keys(): s = s.replace("$%s"%(k), d[k]); v.print_v(v.PDEBUG, (s,os)) if(os == s): finished = True; return s;
def installed(self): # perform installation, file copy v.print_v(v.PDEBUG, "installed") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) if v.VERBOSITY_LEVEL >= v.DEBUG: o_proc = None else: o_proc = output_proc.OutputProcessorMake(preamble="Installing: ") st = bashexec(self.scanner.var_replace_all(self.scr_install), o_proc) if (st != 0): raise PBRecipeException("Installation failed.")
def uninstall(self): try: if(self.satisfier == "inventory"): mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) st = bashexec(self.scanner.var_replace_all(self.scr_uninstall)); self.satisfier = None; del vars["%s.satisfier"%(self.name)] else: v.print_v(v.WARN, "pkg not installed from source, ignoring") except: v.print_v(v.DEBUG, "local build dir does not exist")
def uninstall(self): try: if (self.satisfier == "inventory"): mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) st = bashexec(self.scanner.var_replace_all(self.scr_uninstall)) self.satisfier = None del vars["%s.satisfier" % (self.name)] else: v.print_v(v.WARN, "pkg not installed from source, ignoring") except: v.print_v(v.DEBUG, "local build dir does not exist")
def installed(self): # perform installation, file copy v.print_v(v.PDEBUG, "installed") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) if v.VERBOSITY_LEVEL >= v.DEBUG: o_proc = None else: o_proc = output_proc.OutputProcessorMake(preamble="Installing: ") st = bashexec(self.scanner.var_replace_all(self.scr_install), o_proc) if (st != 0): raise PBRecipeException("Installation failed.")
def shellexec_getout(cmd, throw_ex=True): v.print_v(v.PDEBUG, "shellexec_long: " + str(cmd)) try: #p = subprocess.call([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=globals.env); p = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=globals.env); (out,err) = p.communicate(); return out; except Exception, e: if(throw_ex): raise e; else: return -1;
def shellexec_getout(cmd, throw_ex=True): v.print_v(v.PDEBUG, "shellexec_long: " + str(cmd)) try: #p = subprocess.call([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=globals.env); p = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=globals.env); (out,err) = p.communicate(); return out; except Exception, e: if(throw_ex): raise e; else: return -1;
def validate_write_perm(d): try: import tempfile fd, tmpfile = tempfile.mkstemp(dir=d); v.print_v(v.PDEBUG, "TMPFILE = %s"%(tmpfile)) f1 = open(tmpfile,"w") f1.close() os.unlink(tmpfile); v.print_v(v.PDEBUG, "WRITE PERMS OK %s"%(tmpfile)) except: logger.error("Can not write to prefix (%s)! please fix your permissions or choose another prefix!"%(d)); sys.exit(-10)
def install_deb(self): v.print_v(v.PDEBUG, "install deb called (%s)"%(self.name)) # this is not possible if we do not have deb satisfiers if((self.satisfy_deb == None) or ((type(self.satisfy_deb) == type([])) and (len(self.satisfy_deb) == 0))): v.print_v(v.PDEBUG, "no deb satisfiers available") return False elif self.satisfy_deb and not have_debs(self.satisfy_deb): v.print_v(v.PDEBUG, "deb is not available locally") v.print_v(v.PDEBUG, "check remote repositories...") if not debs_exist(self.satisfy_deb): return False v.print_v(v.INFO, "Installing from .deb: {0}".format(self.name)) return deb_install(self.satisfy_deb)
def install_deb(self): v.print_v(v.PDEBUG, "install deb called (%s)"%(self.name)) # this is not possible if we do not have deb satisfiers if((self.satisfy_deb == None) or ((type(self.satisfy_deb) == type([])) and (len(self.satisfy_deb) == 0))): v.print_v(v.PDEBUG, "no deb satisfiers available") return False elif self.satisfy_deb and not have_debs(self.satisfy_deb): v.print_v(v.PDEBUG, "deb is not available locally") v.print_v(v.PDEBUG, "check remote repositories...") if not debs_exist(self.satisfy_deb): return False v.print_v(v.INFO, "Installing from .deb: {0}".format(self.name)) return deb_install(self.satisfy_deb)
def validate_write_perm(d): try: d = os.path.expanduser(d) print d import tempfile fd, tmpfile = tempfile.mkstemp(dir=d); v.print_v(v.PDEBUG, "TMPFILE = %s"%(tmpfile)) f1 = open(tmpfile,"w") f1.close() os.unlink(tmpfile); v.print_v(v.PDEBUG, "WRITE PERMS OK %s"%(tmpfile)) except: logger.error("Can not write to prefix (%s)! please fix your permissions or choose another prefix!"%(d)); sys.exit(-10)
def deb_install(namelist): v.print_v(v.PDEBUG, "deb install: "+str(namelist)) try: nlj = namelist.name; except: if(namelist.combiner == "&&"): return deb_install(namelist.first) and deb_install(namelist.second); elif(namelist.combiner == "||"): return deb_install(namelist.first) or deb_install(namelist.second); else: print "invalid combiner logic." return false; # if(namelist is list): # nlj = " ".join(namelist); return sudorun("apt-get -y install %s"%(nlj));
def deb_install(namelist): v.print_v(v.PDEBUG, "deb install: "+str(namelist)) try: nlj = namelist.name; except: if(namelist.combiner == "&&"): return deb_install(namelist.first) and deb_install(namelist.second); elif(namelist.combiner == "||"): return deb_install(namelist.first) or deb_install(namelist.second); else: print "invalid combiner logic." return false; # if(namelist is list): # nlj = " ".join(namelist); return sudorun("apt-get -y install %s"%(nlj));
def shellexec_getout(cmd, throw_ex=True): v.print_v(v.PDEBUG, "shellexec_long: " + str(cmd)) try: if not isinstance(cmd, list): cmd = [cmd] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=globals.env) (out, err) = p.communicate() return out except Exception, e: if (throw_ex): raise e else: return -1
def rpm_install(namelist): v.print_v(v.PDEBUG, "rpm install: " + str(namelist)) try: nlj = namelist.name except: if (namelist.combiner == "&&"): return rpm_install(namelist.first) and rpm_install(namelist.second) elif (namelist.combiner == "||"): return rpm_install(namelist.first) or rpm_install(namelist.second) else: print "invalid combiner logic." return false # if(namelist is list): # nlj = " ".join(namelist); return sudorun("yum -y install %s" % (nlj))
def fetch(self): # this is not possible if we do not have sources if(len(self.source) == 0): v.print_v(v.WARN, "WARNING: no sources available for package %s!"%(self.name)) return True fetcher = fetch.fetcher(self.source, self); fetcher.fetch(); if(not fetcher.success): if(len(self.source) == 0): raise PBRecipeException("Failed to Fetch package '%s' no sources were provided! '%s'!"%(self.name, self.source)) else: raise PBRecipeException("Failed to Fetch package '%s' sources were '%s'!"%(self.name, self.source)) # update value in inventory inv.set_state(self.name, "fetch"); self.last_fetcher = fetcher; v.print_v(v.DEBUG, "Setting fetched version info (%s,%s)"%(fetcher.used_source, fetcher.version)) inv.set_prop(self.name, "source", fetcher.used_source); inv.set_prop(self.name, "version", fetcher.version);
def install_src(self): v.print_v(v.PDEBUG, "install src called (%s)" % (self.name)) # basic source installation requirements # install gcc etc before proceeding to build steps req = ["gcc"] for p in req: try: if (not global_recipes[p].satisfy()): global_recipes[p].install() except: return False v.print_v(v.INFO, "Installing from source: {0}".format(self.name)) state = inv.state(self.name) step = 0 for i in range(len(self.install_order)): if (self.install_order[i][0] == state): step = i + 1 v.print_v(v.PDEBUG, self.install_order) # iterate through the install steps of current package while (step < len(self.install_order)): v.print_v( v.PDEBUG, "Current step: (%s :: %s)" % (self.name, self.install_order[step][0])) # run the installation step try: self.install_order[step][1]() except PBRecipeException as e: # If any of these fails, we can quit. exit(1) # update value in inventory inv.set_state(self.name, self.install_order[step][0]) if (self.install_order[step][0] == "fetch"): # if we just fetched a package, store its version and source v.print_v( v.PDEBUG, "setting installed version info (%s,%s)" % (self.last_fetcher.used_source, self.last_fetcher.version)) inv.set_prop(self.name, "source", self.last_fetcher.used_source) inv.set_prop(self.name, "version", self.last_fetcher.version) step = step + 1 return True
def recursive_satisfy(self, recurse_if_installed=False): ll = []; v.print_v(v.PDEBUG, "%s dep [%s]"%(self.name, self.depends)) selfsat = self.satisfy(); # first make sure children are satisfied if(recurse_if_installed or not selfsat): for i in self.depends: try: ll.extend(global_recipes[i].recursive_satisfy()); except: die("broken package dependency %s -> %s (%s recipe not found)"%(self.name, i, i)); # then satisfy self if(not selfsat): ll.append(self.name); return ll;
def recursive_satisfy(self, recurse_if_installed=False): ll = []; v.print_v(v.PDEBUG, "%s dep [%s]"%(self.name, self.depends)) selfsat = self.satisfy(); # first make sure children are satisfied if(recurse_if_installed or not selfsat): for i in self.depends: try: ll.extend(global_recipes[i].recursive_satisfy()); except: die("broken package dependency %s -> %s (%s recipe not found)"%(self.name, i, i)); # then satisfy self if(not selfsat): ll.append(self.name); return ll;
def install(self): order = "src" if (self.name in force_build) else vars["satisfy_order"] order = order.replace(" ", "").lower() types = None if order.find(',') > 0: types = order.split(",") elif order.find('-') > 0: types = order.split( "-" ) # needed for Jenkins bug https://issues.jenkins-ci.org/browse/JENKINS-12439 else: types = order.split(",") # needed for single item case if vars.has_key("install_like"): copyFrom = vars["install_like"] types.remove(global_recipes[copyFrom].satisfier) types.insert(0, global_recipes[copyFrom].satisfier) if self.name == 'all': print "pseudo installation ok" return True if (types == None): logging.error( '\x1b[31m' + "Your satisfy order (%s) provides no way to satisfy the dependency (%s) - please consider changing your satisfy order to \"deb,src\" or \"deb,rpm\" in config.dat!!!" % (order, self.name) + '\x1b[0m') sys.exit(-1) v.print_v(v.PDEBUG, "install type priority: " + str(types)) for type in types: st = False if (type == "src"): st = self.install_src() elif (type == "rpm"): st = self.install_rpm() elif (type == "deb"): st = self.install_deb() else: die("unknown install type: %s" % (type)) if (st): print "installation ok via: %s" % (type) return True die("failed to install %s" % (self.name)) return False
def load_all(): if(not os.path.isfile("recipes/.git")): logger.warning("Recipes git submodule not checked out ... lets do that for you"); bashexec("git submodule update --init --recursive") logger.info("Recipe clone finished..."); global_recipes.clear(); files = os.listdir("recipes"); recipes = []; v.print_v(v.INFO, "Loading recipes ...") for f in files: if(re.match("[\w\d_-]+.lwr$", f)): recipes.append(f[:-4]); for r in recipes: if not global_recipes.has_key(r): try: global_recipes[r] = recipe(r); except: v.print_v(v.WARN, "Failed to load recipe {0}".format(r)) global_recipes['all'] = recipe('all') global_recipes['all'].category = "pseudo" global_recipes['all'].depends.extend(recipes) v.print_v(v.PDEBUG, "Loading recipes ... done")
def make(self, try_again=False): """ Build this recipe. If try_again is set, it will assume the build failed before and we're trying to run it again. In this case, reduce the makewidth to 1 and show the build output. """ v.print_v(v.PDEBUG, "make") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) if v.VERBOSITY_LEVEL >= v.DEBUG or try_again: o_proc = None else: o_proc = output_proc.OutputProcessorMake(preamble="Building: ") # Stash the makewidth so we can set it back later makewidth = self.scanner.lvars['makewidth'] if try_again: self.scanner.lvars['makewidth'] = '1' st = bashexec(self.scanner.var_replace_all(self.scr_make), o_proc) self.scanner.lvars['makewidth'] = makewidth if st == 0: return # If build fails, try again with more output: if try_again == False: v.print_v(v.ERROR, "Build failed. Re-trying with reduced makewidth and higher verbosity.") self.make(try_again=True) else: v.print_v(v.ERROR, "Build failed. See output above for error messages.") raise PBRecipeException("Build failed.")
def load_all(): if (not os.path.isfile("recipes/.git")): logger.warning( "Recipes git submodule not checked out ... lets do that for you") bashexec("git submodule update --init --recursive") logger.info("Recipe clone finished...") global_recipes.clear() files = os.listdir("recipes") recipes = [] v.print_v(v.INFO, "Loading recipes ...") for f in files: if (re.match("[\w\d_-]+.lwr$", f)): recipes.append(f[:-4]) for r in recipes: if not global_recipes.has_key(r): try: global_recipes[r] = recipe(r) except: v.print_v(v.WARN, "Failed to load recipe {0}".format(r)) global_recipes['all'] = recipe('all') global_recipes['all'].category = "pseudo" global_recipes['all'].depends.extend(recipes) v.print_v(v.PDEBUG, "Loading recipes ... done")
def make(self, try_again=False): """ Build this recipe. If try_again is set, it will assume the build failed before and we're trying to run it again. In this case, reduce the makewidth to 1 and show the build output. """ v.print_v(v.PDEBUG, "make") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) if v.VERBOSITY_LEVEL >= v.DEBUG or try_again: o_proc = None else: o_proc = output_proc.OutputProcessorMake(preamble="Building: ") # Stash the makewidth so we can set it back later makewidth = self.scanner.lvars['makewidth'] if try_again: self.scanner.lvars['makewidth'] = '1' st = bashexec(self.scanner.var_replace_all(self.scr_make), o_proc) self.scanner.lvars['makewidth'] = makewidth if st == 0: return # If build fails, try again with more output: if try_again == False: v.print_v( v.ERROR, "Build failed. Re-trying with reduced makewidth and higher verbosity." ) self.make(try_again=True) else: v.print_v(v.ERROR, "Build failed. See output above for error messages.") raise PBRecipeException("Build failed.")
def configure(self, try_again=False): """ Run the configuration step for this recipe. If try_again is set, it will assume the configuration failed before and we're trying to run it again. """ v.print_v(v.PDEBUG, "configure") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) if v.VERBOSITY_LEVEL >= v.DEBUG or try_again: o_proc = None else: o_proc = output_proc.OutputProcessorMake(preamble="Configuring: ") st = bashexec(self.scanner.var_replace_all(self.scr_configure), o_proc) if (st == 0): return # If configuration fails: if try_again == False: v.print_v( v.ERROR, "Configuration failed. Re-trying with higher verbosity.") self.make(try_again=True) else: v.print_v( v.ERROR, "Configuration failed. See output above for error messages.") raise PBRecipeException("Configuration failed")
def install(pkgname, die_if_already=False): if not check_recipe(pkgname): die("unknown package "+pkgname); if die_if_already and check_installed(pkgname): print pkgname + " already installed"; return; validate_write_perm(vars["prefix"]) rc = global_recipes[pkgname]; pkg_missing = rc.recursive_satisfy(); # remove duplicates while preserving list order (lowest nodes first) pkg_missing = list_unique_ord(pkg_missing); v.print_v(v.INFO, "Installing packages:\n" + "\n".join(["* {0}".format(x) for x in pkg_missing])) # prompt if list is ok? # provide choice of deb satisfiers or source build? for pkg in pkg_missing: global_recipes[pkg].install(); if(pkg == "gnuradio"): if(confirm("Run VOLK Profile to choose fastest kernels?","Y",5)): run_volk_profile();
def install_src(self): v.print_v(v.PDEBUG, "install src called (%s)"%(self.name)) # basic source installation requirements # install gcc etc before proceeding to build steps req = ["gcc"]; for p in req: try: if(not global_recipes[p].satisfy()): global_recipes[p].install(); except: return False; v.print_v(v.INFO, "Installing from source: {0}".format(self.name)) state = inv.state(self.name); step = 0; for i in range( len( self.install_order ) ): if( self.install_order[i][0] == state ): step = i+1; v.print_v(v.PDEBUG, self.install_order) # iterate through the install steps of current package while(step < len(self.install_order)): v.print_v(v.PDEBUG, "Current step: (%s :: %s)"%(self.name, self.install_order[step][0])) # run the installation step try: self.install_order[step][1](); except PBRecipeException as e: # If any of these fails, we can quit. exit(1) # update value in inventory inv.set_state(self.name, self.install_order[step][0]); if(self.install_order[step][0] == "fetch"): # if we just fetched a package, store its version and source v.print_v(v.PDEBUG, "setting installed version info (%s,%s)"%(self.last_fetcher.used_source,self.last_fetcher.version)) inv.set_prop(self.name, "source", self.last_fetcher.used_source); inv.set_prop(self.name, "version", self.last_fetcher.version); step = step + 1; return True;
def shellexec_shell(cmd, throw_ex): v.print_v(v.PDEBUG, "shellexec_long: " + cmd) try: result = None quitEvent = Event() monitorThread = Thread(target=monitor, args=(cmd,quitEvent,)) monitorThread.start() while monitorThread.isAlive: monitorThread.join(1) if quitEvent.isSet(): logger.info("shellexec_shell: Caught the quit Event") break return monitor.result except KeyboardInterrupt: logger.info("shellexec_shell: Caught Ctl+C. Killing all threads. Patience...") quitEvent.set() time.sleep(10) exit(0) except Exception, e: if(throw_ex): raise e; else: return -1;
def install(self): order = "src" if (self.name in force_build) else vars["satisfy_order"]; order = order.replace(" ","").lower(); types = None; if order.find(',') > 0: types = order.split(","); elif order.find('-') > 0: types = order.split("-") # needed for Jenkins bug https://issues.jenkins-ci.org/browse/JENKINS-12439 else: types = order.split(","); # needed for single item case if vars.has_key("install_like"): copyFrom = vars["install_like"] types.remove(global_recipes[copyFrom].satisfier) types.insert(0, global_recipes[copyFrom].satisfier) if self.name == 'all': print "pseudo installation ok" return True; if(types==None): logging.error('\x1b[31m' + "Your satisfy order (%s) provides no way to satisfy the dependency (%s) - please consider changing your satisfy order to \"deb,src\" or \"deb,rpm\" in config.dat!!!"%(order,self.name)+ '\x1b[0m'); sys.exit(-1); v.print_v(v.PDEBUG, "install type priority: " + str(types)) for type in types: st = False; if(type == "src"): st = self.install_src(); elif(type == "rpm"): st = self.install_rpm(); elif(type == "deb"): st = self.install_deb(); else: die( "unknown install type: %s"%(type) ); if(st): print "installation ok via: %s"%(type); return True; die("failed to install %s"%(self.name)); return False;
def bashexec(cmd, o_proc=None): """ Launch a bash and run 'cmd' inside it. If an output processor is given, a thread is spawned to poll the output and feed it to the processor. Otherwise, the output is displayed verbatim. """ if cmd.strip() == "": return 0 v.print_v(v.PDEBUG, "bash exec (%s):: %s"%(os.getcwd(),cmd.strip())) if(cmd[-1] != "\n"): cmd += "\n" extra_popen_args = {} if isinstance(o_proc, output_proc.OutputProcessor): extra_popen_args = o_proc.extra_popen_args from subprocess import Popen, PIPE p = subprocess.Popen(["bash"], stdin=subprocess.PIPE, shell=True, env=globals.env, **extra_popen_args) p.stdin.write(cmd) p.stdin.close() if isinstance(o_proc, output_proc.OutputProcessor): st = output_proc.run_with_output_processing(p, o_proc) else: st = p.wait() # unless background execution preferred v.print_v(v.PDEBUG, "bash return val = %d"%(st)) return st
def __init__(self, filename, recipe, lvars=None): if (not lvars): lvars = vars_copy(vars) self.lvars = lvars v.print_v(v.PDEBUG, "init scanner with lvars = %s" % (lvars)) self.recipe = recipe self.recipe.scanner = self if not os.path.exists(filename): v.print_v(v.ERROR, "Missing file %s" % (filename)) raise RuntimeError f = open(filename, "r") Scanner.__init__(self, self.lexicon, f, filename) self.begin("") v.print_v(v.PDEBUG, "Parsing " + filename) while 1: token = Scanner.read(self) if token[0] is None: break f.close()
def load_all(): global_recipes.clear() files = os.listdir("recipes") recipes = [] v.print_v(v.INFO, "Loading recipes ...") for f in files: if (re.match("[\w\d_-]+.lwr$", f)): recipes.append(f[:-4]) for r in recipes: if not global_recipes.has_key(r): try: global_recipes[r] = recipe(r) except: v.print_v(v.WARN, "Failed to load recipe {0}".format(r)) global_recipes['all'] = recipe('all') global_recipes['all'].category = "pseudo" global_recipes['all'].depends.extend(recipes) v.print_v(v.PDEBUG, "Loading recipes ... done")
def load_all(): global_recipes.clear(); files = os.listdir("recipes"); recipes = []; v.print_v(v.INFO, "Loading recipes ...") for f in files: if(re.match("[\w\d_-]+.lwr$", f)): recipes.append(f[:-4]); for r in recipes: if not global_recipes.has_key(r): try: global_recipes[r] = recipe(r); except: v.print_v(v.WARN, "Failed to load recipe {0}".format(r)) global_recipes['all'] = recipe('all') global_recipes['all'].category = "pseudo" global_recipes['all'].depends.extend(recipes) v.print_v(v.PDEBUG, "Loading recipes ... done")
def __init__(self, filename, recipe, lvars = None): if(not lvars): lvars = vars_copy(vars); self.lvars = lvars; v.print_v(v.PDEBUG, "init scanner with lvars = %s"%(lvars)) self.recipe = recipe self.recipe.scanner = self if not os.path.exists(filename): v.print_v(v.ERROR, "Missing file %s"%(filename)) raise RuntimeError f = open(filename,"r"); Scanner.__init__(self, self.lexicon, f, filename); self.begin(""); v.print_v(v.PDEBUG, "Parsing "+filename) while 1: token = Scanner.read(self); if token[0] is None: break; f.close();
def configure(self, try_again=False): """ Run the configuration step for this recipe. If try_again is set, it will assume the configuration failed before and we're trying to run it again. """ v.print_v(v.PDEBUG, "configure") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) if v.VERBOSITY_LEVEL >= v.DEBUG or try_again: o_proc = None else: o_proc = output_proc.OutputProcessorMake(preamble="Configuring: ") st = bashexec(self.scanner.var_replace_all(self.scr_configure), o_proc) if (st == 0): return # If configuration fails: if try_again == False: v.print_v(v.ERROR, "Configuration failed. Re-trying with higher verbosity.") self.make(try_again=True) else: v.print_v(v.ERROR, "Configuration failed. See output above for error messages.") raise PBRecipeException("Configuration failed")
def check_fetched(pkgname): pkg_fetched = global_recipes[pkgname].fetched() v.print_v(v.DEBUG, "Checking if {0} is fetched: {1}".format(pkgname, "Yes" if pkg_fetched else "No")) return pkg_fetched
def check_fetched(pkgname): pkg_fetched = global_recipes[pkgname].fetched() v.print_v( v.DEBUG, "Checking if {0} is fetched: {1}".format( pkgname, "Yes" if pkg_fetched else "No")) return pkg_fetched
def check_installed(pkgname): pkg_installed = global_recipes[pkgname].satisfy() v.print_v( v.DEBUG, "Checking if {0} is installed: {1}".format( pkgname, "Yes" if pkg_installed else "No")) return pkg_installed
def check_installed(pkgname): pkg_installed = global_recipes[pkgname].satisfy() v.print_v(v.DEBUG, "Checking if {0} is installed: {1}".format(pkgname, "Yes" if pkg_installed else "No")) return pkg_installed
def verify(self): # perform install verification v.print_v(v.INFO, "verify install...") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) st = bashexec(self.scanner.var_replace_all(self.scr_verify)); self.check_stat(st, "Verify");
def verify(self): # perform install verification v.print_v(v.INFO, "verify install...") mkchdir(topdir + "/src/" + self.name + "/" + self.installdir) st = bashexec(self.scanner.var_replace_all(self.scr_verify)) self.check_stat(st, "Verify")