How to use the pybombs.config_file.PBConfigFile function in PyBOMBS

To help you get started, we’ve selected a few PyBOMBS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnuradio / pybombs / pybombs / commands / recipes.py View on Github external
def remove_recipe_dir(self, alias):
        """
        Remove a recipe alias and, if applicable, its cache.
        """
        if alias not in self.cfg.get_named_recipe_dirs():
            self.log.error("Unknown recipe alias: {alias}".format(alias=alias))
            return False
        # Remove from config file
        cfg_filename = self.cfg.get_named_recipe_cfg_file(alias)
        cfg_file = PBConfigFile(cfg_filename)
        cfg_data = cfg_file.get()
        cfg_data['recipes'].pop(alias, None)
        cfg_file.save(cfg_data)
        recipe_cache_dir = os.path.join(
            os.path.split(cfg_filename)[0],
            self.cfg.recipe_cache_dir,
            alias,
        )
        # If the recipe cache is not inside a PyBOMBS dir, don't delete it.
        if self.cfg.pybombs_dir not in recipe_cache_dir:
            return True
        if os.path.exists(recipe_cache_dir):
            self.log.info("Removing directory: {cdir}".format(cdir=recipe_cache_dir))
            shutil.rmtree(recipe_cache_dir)
        return True
github gnuradio / pybombs / pybombs / config_manager.py View on Github external
for r_loc in args.recipes:
            if r_loc:
                self._recipe_locations.append(npath(r_loc))
        # From environment variable:
        if os.environ.get("PYBOMBS_RECIPE_DIR", "").strip():
            self._recipe_locations += [
                npath(x) \
                for x in os.environ.get("PYBOMBS_RECIPE_DIR").split(os.pathsep) \
                if len(x.strip())
            ]
        # From prefix info:
        if self._prefix_info.recipe_dir is not None:
            self._recipe_locations.append(self._prefix_info.recipe_dir)
        # From config files (from here, recipe locations are named):
        for cfg_file in cfg_files:
            recipe_locations = PBConfigFile(cfg_file).get('recipes')
            for name, uri in reversed(recipe_locations.items()):
                local_recipe_dir = self.resolve_recipe_uri(
                    uri, name, os.path.join(os.path.split(cfg_file)[0], 'recipes')
                )
                self._recipe_locations.append(local_recipe_dir)
                self._named_recipe_dirs[name] = local_recipe_dir
                self._named_recipe_sources[name] = uri
                self._named_recipe_cfg_files[name] = cfg_file
        # Internal recipe list:
        self._recipe_locations.append(os.path.join(self.module_dir, 'recipes'))
        self.log.debug("Full list of recipe locations: {0}".format(self._recipe_locations))
        self.log.debug("Named recipe locations: {0}".format(self._named_recipe_sources))
        # Detect Python version of the prefix (this is *not* necessarily
        # the Python version that is used for executing this script! The
        # prefix could be, for example, a virtualenv with its custom Python
        # version.)
github gnuradio / pybombs / pybombs / commands / config.py View on Github external
def _run_pkg_or_cat(self):
        " Handle `pybombs config --package or --category' "
        if self.args.package is not None and self.args.category is not None:
            self.log.error("Cannot provide both --package and --category!")
            return -1
        if self.args.package is not None:
            config_target = 'packages'
            pkg_cat = self.args.package
        elif self.args.category is not None:
            config_target = 'categories'
            pkg_cat = self.args.category
        cfg_file = PBConfigFile(self.cfg_file)
        keys = [self.args.key]
        verb = "Getting"
        if self.args.key is None:
            keys = cfg_file.data.get(config_target, {}).get(pkg_cat, {}).keys()
        elif self.args.value is not None:
            cfg_file.update({config_target: {pkg_cat: {self.args.key: self.args.value}}})
            verb = "Setting"
        print("{verb} keys for {target} {pkgcat}:".format(verb=verb, target=config_target, pkgcat=pkg_cat))
        for key in keys:
            print("{key}: {value}".format(
                key=key,
                value=cfg_file.data.get(config_target, {}).get(pkg_cat, {}).get(key))
            )
github gnuradio / pybombs / pybombs / commands / prefix.py View on Github external
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
github gnuradio / pybombs / pybombs / commands / prefix.py View on Github external
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
github gnuradio / pybombs / pybombs / commands / config.py View on Github external
def _run_env(self):
        " Handle `pybombs config --env` "
        cfg_file = PBConfigFile(self.cfg_file)
        keys = [self.args.key]
        verb = "Getting"
        config_target = 'env'
        if self.args.key is None:
            keys = cfg_file.data.get(config_target, {}).keys()
        elif self.args.value is not None:
            cfg_file.update({config_target: {self.args.key: self.args.value}})
            verb = "Setting"
        print("{verb} environment variables:".format(verb=verb))
        for key in keys:
            print("{key}: {value}".format(
                key=key,
                value=cfg_file.data.get(config_target, {}).get(key))
            )
github gnuradio / pybombs / pybombs / config_manager.py View on Github external
def _merge_config_info_from_file(self, cfg_file, cfg_data):
        """
        Load a config file, load its contents, and merge it into cfg_info.
        Return the result.
        """
        try:
            self.log.debug('Inspecting config file: {0}'.format(cfg_file))
            cfg_data_new = PBConfigFile(cfg_file).get()
        except Exception:
            self.log.debug('Well, looks like that failed.')
            return cfg_data
        return dict_merge(cfg_data, cfg_data_new)