def _install_sdk_to_prefix(self, sdkname): """ Read recipe for sdkname, and install the SDK to the prefix. """ from pybombs import recipe src_dir = self.prefix.src_dir cfg_file = self.prefix.cfg_file ### Get the recipe r = recipe.get_recipe(sdkname, target='sdk') try: self.log.trace("Switching CWD to {0}".format(src_dir)) if not op.isdir(src_dir): os.mkdir(src_dir) os.chdir(src_dir) except: self.log.error("Source dir required to install SDK.") return False ### Install the actual SDK file self.log.debug("Fetching SDK `{sdk}'".format(sdk=sdkname)) fetcher.Fetcher().fetch(r) self.log.info("Installing SDK `{sdk}'".format(sdk=sdkname)) # Install command cmd = r.var_replace_all(r.get_command('install')) if subproc.monitor_process(cmd, shell=True, env=os.environ) == 0: self.log.debug("Installation successful") else: self.log.error("Error installing SDK. Aborting.") return False # Clean up files_to_delete = [op.normpath(op.join(src_dir, r.var_replace_all(x))) for x in r.clean] if len(files_to_delete): self.log.info("Cleaning up files...") for ftd in files_to_delete: if op.commonprefix((src_dir, ftd)) != src_dir: self.log.warn("Not removing {ftd} -- outside source dir!".format(ftd=ftd)) continue self.log.debug("Removing {ftd}...".format(ftd=ftd)) if op.isdir(ftd): shutil.rmtree(ftd) elif op.isfile(ftd): os.remove(ftd) else: self.log.error("Not sure what this is: {ftd}".format(ftd=ftd)) return False ### Update the prefix-local config file self.log.debug("Updating config file with SDK recipe info.") try: old_cfg_data = PBConfigFile(cfg_file).get() except IOError: self.log.debug("There doesn't seem to be a config file yet for this prefix.") old_cfg_data = {} # Filter out keys we don't care about: sdk_recipe_keys_for_config = ('config', 'packages', 'categories', 'env') sdk_cfg_data = {k: v for k, v in iteritems(r.get_dict()) if k in sdk_recipe_keys_for_config} self.log.trace("New data: {new}".format(new=sdk_cfg_data)) cfg_data = dict_merge(old_cfg_data, sdk_cfg_data) self.log.debug("Writing updated prefix config to `{0}'".format(cfg_file)) PBConfigFile(cfg_file).save(cfg_data) return True
def _get_git_remotes(packages): """ Return a dict pkgname -> git remote for every package that has a git remote given. """ the_fetcher = fetcher.Fetcher() recipes = {pkg: recipe.get_recipe(pkg, fail_easy=True) for pkg in packages} sources = {pkg: recipes[pkg].source for pkg in recipes if recipes[pkg] is not None} git_sources = {} for pkg in sources: try: for src in sources[pkg]: url_type, url = the_fetcher.parse_uri(src) if url_type == 'git': git_sources[pkg] = url break except PBException: pass return git_sources