Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self,):
# Set up logger:
self.log = pb_logging.logger.getChild("PackageManager")
self.cfg = config_manager
self.prefix_available = self.cfg.get_active_prefix().prefix_dir is not None
# Create a source package manager
if self.prefix_available:
self.src = packagers.Source()
self.prefix = self.cfg.get_active_prefix()
else:
self.log.debug("No prefix specified. Skipping source package manager.")
self.src = None
# Create sorted list of binary package managers
requested_packagers = [x.strip() for x in self.cfg.get('packagers').split(',')]
binary_pkgrs = []
for pkgr in requested_packagers:
self.log.debug("Attempting to add binary package manager {}".format(pkgr))
p = packagers.get_by_name(pkgr, packagers.__dict__.values())
if p is None:
self.log.warn("This binary package manager can't be instantiated: {}".format(pkgr))
def detect_pip_exe():
"""
Returns the path to the pip version used. Factors in the available Python
version.
"""
from pybombs.config_manager import config_manager
if vcompare('>=', config_manager.get_python_version(), '3'):
default_pip = 'pip3'
else:
default_pip = 'pip2'
if sysutils.which(default_pip) is not None:
return default_pip
if sysutils.which('pip') is not None:
return 'pip'
return None
def __init__(self):
Requirer.__init__(self)
self.cfg = config_manager
self.log = pb_logging.logger.getChild("Fetcher.{0}".format(self.url_type))
sh="$ " if kwargs.get('shell', False) else "",
cmd=args.strip()
)
from pybombs.config_manager import config_manager
from pybombs.utils import output_proc
_process_thread.result = 0
extra_popen_args = {}
use_oproc = False
o_proc = kwargs.get('o_proc')
if isinstance(o_proc, output_proc.OutputProcessor):
use_oproc = True
extra_popen_args = o_proc.extra_popen_args
if kwargs.get('shell', False) and isinstance(args, list):
args = ' '.join(args)
if kwargs.get('elevate'):
args = elevate_command(args, config_manager.get('elevate_pre_args'))
log = logger.getChild("_process_thread()")
cmd_pp = pretty_print_cmd(args)
if kwargs.get('elevate'):
log.info("Executing command with elevated privileges: `{cmd}'"
.format(cmd=cmd_pp))
else:
log.debug("Executing command `{cmd}'".format(cmd=cmd_pp))
try:
proc = subprocess.Popen(
args,
shell=kwargs.get('shell', False),
env=kwargs.get('env', config_manager.get_active_prefix().env),
**extra_popen_args
)
except OSError:
log.error("Failure executing command `{cmd}'!".format(cmd=cmd_pp))
def __init__(self):
self.cfg = config_manager
self.log = pb_logging.logger.getChild("Packager.{0}".format(self.name))
def get_local_package_data(self):
"""
Merges the recipe data with local config settings. Local settings
always supersede recipe settings.
This allows users to override anything in a recipe with whatever's stored
in the `package:` and `category:` sections of their local config files.
"""
return normalize_package_data(dict_merge(
self.get_dict(),
config_manager.config_manager.get_package_flags(
self.id, self.get_dict().get('category')
)
def init_arg_parser(show_help_for=None, hide_hidden=True):
"""
Create a base argument parser
"""
def dummy_error(msg):
" Bogus error handler for ArgParse in case we don't want all the output."
raise PBException('parse error')
cmd_list = get_cmd_list(hide_hidden=hide_hidden)
# Set up global options:
parser = argparse.ArgumentParser(
description='PyBOMBS: A meta-package manager integrated with CGRAN.',
epilog='Run `pybombs --help to learn about command-specific options.',
)
config_manager.setup_parser(parser)
subparsers = parser.add_subparsers(
title='PyBOMBS subcommands',
#description='valid subcommands',
help="Description:",
dest='command',
metavar='',
)
subparsers.required = True
if hide_hidden:
parser.error = dummy_error
# Set up options for each command:
for cmd in cmd_list:
for cmd_name, cmd_help in iteritems(cmd.cmds):
subparser = subparsers.add_parser(cmd_name, help=cmd_help, add_help=True)
cmd.setup_subparser(subparser, cmd_name)
if cmd_name == show_help_for:
def get_package_reqs(self, pkg_type):
"""
Return a PBPackageRequirement(Pair) object for the selected
pkg_type. E.g., if pkg_type is 'deb', you can use this to
figure out which .deb packages to install.
If pkg_type was not listed in the recipe, return None.
"""
req_string = getattr(self, 'satisfy', {}).get(pkg_type)
satisfy_tags = config_manager.config_manager.get_satisfier_tags()
for tag in satisfy_tags:
satisfy_key = 'satisfy@{}'.format(tag)
if getattr(self, satisfy_key, {}).get(pkg_type):
req_string = getattr(self, satisfy_key, {}).get(pkg_type)
if req_string is True:
return req_string
self.log.trace("Parsing requirements string: {}".format(req_string))
return PBPackageRequirementScanner(req_string).get_preq()
var_repl = lambda mo: var_replace(mo, self.vars, config_manager.config_manager)
try: