Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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("Storing new recipe location to {cfg_file}".format(cfg_file=cfg_file))
assert cfg_file is not None
assert os.path.isdir(recipe_cache_top_level)
assert recipe_cache is not None
assert alias
# Now make sure we don't already have a cache dir
if os.path.isdir(recipe_cache):
self.log.warn("Cache dir {cdir} for remote recipe location {alias} already exists! Deleting.".format(
cdir=recipe_cache, alias=alias
))
shutil.rmtree(recipe_cache)
if not os.path.isdir(os.path.normpath(os.path.expanduser(uri))):
# Let the fetcher download the location
self.log.debug("Fetching into directory: {0}/{1}".format(recipe_cache_top_level, alias))
try:
Fetcher().fetch_url(uri, recipe_cache_top_level, alias, {}) # No args
except PBException as ex:
self.log.error("Could not fetch recipes: {s}".format(s=str(ex)))
return False
# Write this to config file
self.cfg.update_cfg_file({'recipes': {alias: uri}}, cfg_file=cfg_file)
return True
if not os.path.isdir(self.prefix.src_dir):
os.makedirs(self.prefix.src_dir)
self.static = static
recipe.set_static(static)
cwd = os.getcwd()
get_state = lambda: (self.inventory.get_state(recipe.id) or 0)
set_state = lambda state: self.inventory.set_state(recipe.id, state) or self.inventory.save()
if not hasattr(recipe, 'source') or len(recipe.source) == 0:
self.log.warn("Cannot find a source URI for package {0}".format(recipe.id))
return False
from pybombs.fetcher import Fetcher
try:
if update:
if get_state() < self.inventory.STATE_CONFIGURED:
raise PBException("Can't update package {0}, it's not yet configured.".format(recipe.id))
Fetcher().update(recipe)
set_state(self.inventory.STATE_CONFIGURED)
self.log.debug("State on package {0} is {1}".format(recipe.id, get_state()))
# First, make sure we have the sources
if not update and get_state() < self.inventory.STATE_FETCHED:
Fetcher().fetch(recipe)
else:
self.log.debug("Package {0} is already fetched.".format(recipe.id))
# If we know the package is fetched, we can attempt to build:
self.run_build(
recipe,
nuke_builddir=False,
warn_if_builddir_exists=not bool(update),
fail_if_builddir_missing=update,
)
except PBException as err:
os.chdir(cwd)
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
# Go, go, go!
self.log.debug("Getting recipes for: {0}".format(self.args.packages))
recipe_list = [ \
recipe.Recipe(self.recipe_manager.get_recipe_filename(x)) \
for x in self.args.packages if len(x) \
]
except KeyError as e:
self.log.error("Package has no recipe: {0}".format(e))
return 1
for r in recipe_list:
if (not hasattr(r,'source')) or (not len(r.source)):
self.log.warn("Package {0} has no sources listed.".format(r.id))
continue
self.log.info("Downloading source for package {0}".format(r.id))
try:
if self.cmd == 'refetch':
Fetcher().update(r)
else:
Fetcher().fetch(r)
except PBException as ex:
self.log.error("Unable to fetch package {0}. Skipping.".format(r.id))
self.log.error(ex)