def installed(self, name, return_pkgr_name=False): """ Check to see if this recipe is installed (identified by its name). If not, return False. If yes, return value depends on return_pkgr_name and is either a list of packager name that installed it, or a version string (if the version string can't be determined, returns True instead). """ if not return_pkgr_name and name in self.pmc.known_installed: self.log.obnoxious("{0} is cached and known to be installed.".format(name)) return True self.log.debug("Checking if package {} is installed.".format(name)) if self.check_package_flag(name, 'forceinstalled'): self.log.debug("Package {} is forced to state 'installed'.".format(name)) # TODO maybe we can figure out a version string return ['force-installed'] if return_pkgr_name else True r = recipe.get_recipe(name) self.current_prefix = self.cfg.get_active_prefix() virtualenv = config_manager.extract_cfg_items(self.current_prefix.cfg_file, 'virtualenv') self.log.debug("Checking if the prefix has a virtualenv") if virtualenv and 'python' in r.depends: try: if 'pip' in r.satisfy: #This pip list is specific to virtualenv pip_output = subproc.check_output(["pip", "list"]) pip_list = [x.split(' ')[0] for x in str(pip_output).strip(). lower().split("\n")] if not name in pip_list: return False except AttributeError: self.log.debug("Package depends on python, but isn't pip installable") pkgrs = [] for pkgr in self.get_packagers(name): pkg_version = pkgr.installed(r) if pkg_version is None or not pkg_version: continue else: self.pmc.known_installed.add(name) if return_pkgr_name: pkgrs.append(pkgr.name) else: return pkg_version else: pkgrs = [] for pkgr in self.get_packagers(name): pkg_version = pkgr.installed(r) if pkg_version is None or not pkg_version: continue else: self.pmc.known_installed.add(name) if return_pkgr_name: pkgrs.append(pkgr.name) else: return pkg_version if return_pkgr_name and len(pkgrs): return pkgrs return False
def _run_config(self): " Handle `pybombs config' " if self.args.config_only: cfg_data = extract_cfg_items(self.cfg_file, 'config', False) else: cfg_data = self.cfg keys = [self.args.key] if self.args.key is None: keys = cfg_data.keys() elif self.args.value is not None: self.cfg.set(self.args.key, self.args.value) self.cfg.update_cfg_file( new_data={'config': {self.args.key: self.args.value}}, cfg_file=self.cfg_file, ) for key in keys: print("{key}: {value}".format(key=key, value=cfg_data.get(key, ""))) print(" - {help}".format(help=self.cfg.get_help(key) or " Undocumented config option"))
def run(self): """ Go, go, go! """ if self.args.config_only: cfg_data = extract_cfg_items(self.cfg_file, 'config', False) else: cfg_data = self.cfg keys = [self.args.key] if self.args.key is None: keys = cfg_data.keys() elif self.args.value is not None: self.cfg.set(self.args.key, self.args.value) self.cfg.update_cfg_file( new_data={'config': {self.args.key: self.args.value}}, cfg_file=self.cfg_file, ) for key in keys: print("{key}: {value}\n - {help}".format( key=key, value=cfg_data.get(key, ""), help=self.cfg.get_help(key), ))
def _run_config(self): " Handle `pybombs config' " if self.args.config_only: cfg_data = extract_cfg_items(self.cfg_file, 'config', False) else: cfg_data = self.cfg keys = [self.args.key] if self.args.key is None: keys = cfg_data.keys() elif self.args.value is not None: self.cfg.set(self.args.key, self.args.value) self.cfg.update_cfg_file( new_data={'config': { self.args.key: self.args.value }}, cfg_file=self.cfg_file, ) for key in keys: print("{key}: {value}".format(key=key, value=cfg_data.get(key, ""))) print(" - {help}".format( help=self.cfg.get_help(key) or " Undocumented config option"))
def run(self): """ Go, go, go! """ if self.args.config_only: cfg_data = extract_cfg_items(self.cfg_file, 'config', False) else: cfg_data = self.cfg keys = [self.args.key] if self.args.key is None: keys = cfg_data.keys() elif self.args.value is not None: self.cfg.set(self.args.key, self.args.value) self.cfg.update_cfg_file( new_data={'config': { self.args.key: self.args.value }}, cfg_file=self.cfg_file, ) for key in keys: print("{key}: {value}\n - {help}".format( key=key, value=cfg_data.get(key, ""), help=self.cfg.get_help(key), ))
def _std_package_operation(self, name, operation, pkgrs, verify=False, **kwargs): """ Standard package operation: Try an operation on all packagers. """ rec = recipe.get_recipe(name) virtualenv = config_manager.extract_cfg_items(self.current_prefix.cfg_file, 'virtualenv') #If the following condition is satisfied, pybombs uses pip explicity #to install those packages specific to the virtualenv if virtualenv and 'python' in rec.depends: try: if 'pip' in rec.satisfy: pkgr = pkgrs[0] self.log.debug("Using packager {}".format(pkgr.name)) try: result = getattr(pkgr, operation)(rec, **kwargs) if result: if verify and not pkgr.verify(rec): self.log.warn("Package reported successful {0},' \ 'but verification failed.".format(operation)) return True except PBException as ex: self.log.error( "Something went wrong while trying to {} {} using {}: {}".format( operation, name, pkgr.name, str(ex).strip())) except: for pkgr in pkgrs: self.log.debug("Using packager {}".format(pkgr.name)) try: result = getattr(pkgr, operation)(rec, **kwargs) if result: if verify and not pkgr.verify(rec): self.log.warn("Package reported successful {0},' \ 'but verification failed.".format(operation)) continue return True except PBException as ex: self.log.error( "Something went wrong while trying to {} {} using {}: {}".format( operation, name, pkgr.name, str(ex).strip())) #This works exactly like the above piece of code, but with all the #available packagers else: for pkgr in pkgrs: self.log.debug("Using packager {}".format(pkgr.name)) try: result = getattr(pkgr, operation)(rec, **kwargs) if result: if verify and not pkgr.verify(rec): self.log.warn("Package reported successful {0},' \ 'but verification failed.".format(operation)) continue return True except PBException as ex: self.log.error( "Something went wrong while trying to {} {} using {}: {}".format( operation, name, pkgr.name, str(ex).strip())) return False