Exemplo n.º 1
0
 def run(self):
     """ Go, go, go! """
     from pybombs.fetcher import Fetcher
     from pybombs import recipe
     if self.args.all:
         self.log.debug("Loading all recipes!")
         self.args.packages = self.recipe_manager.list_all()
     try:
         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)
Exemplo n.º 2
0
    def install(self, recipe, static=False, update=False):
        """
        Run the source installation process for package 'recipe'.

        May raise an exception if things go terribly wrong.
        Otherwise, return True on success and False if installing failed.
        """
        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:
                    self.log.error(
                        "Can't update package {0}, it's not yet configured.".
                        format(recipe.id))
                    exit(1)
                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 {} 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)
            self.log.error(
                "Problem occurred while building package {}:\n{}".format(
                    recipe.id,
                    str(err).strip()))
            return False
        ### Housekeeping
        os.chdir(cwd)
        return True
Exemplo n.º 3
0
 def _update_recipes(self):
     """
     Update a remote recipe location.
     """
     try:
         uri = self.cfg.get_named_recipe_sources()[self.args.alias]
         recipes_dir = self.cfg.get_named_recipe_dirs()[self.args.alias]
     except KeyError:
         self.log.error("Error looking up recipe alias '{alias}'".format(
             alias=self.args.alias))
         return -1
     if not os.path.isdir(recipes_dir):
         self.log.error(
             "Recipe location does not exist. Run `recipes add --force' to add recipes."
         )
         return -1
     cache_dir_top_level, cache_dir = os.path.split(
         os.path.normpath(recipes_dir))
     # Do actual update
     self.log.info("Updating recipe location `{alias}'...".format(
         alias=self.args.alias))
     if not Fetcher().update_src(uri, cache_dir_top_level, cache_dir, {}):
         self.log.error(
             "Failed to update recipe location `{alias}'...".format(
                 alias=self.args.alias))
         return -1
Exemplo n.º 4
0
 def update_recipe_repo(self, alias):
     """
     Update a remote recipe location by its alias name.
     """
     try:
         uri = self.cfg.get_named_recipe_sources()[alias]
         recipes_dir = self.cfg.get_named_recipe_dirs()[alias]
     except KeyError:
         self.log.error(
             "Error looking up recipe alias '{alias}'".format(alias=alias))
         return False
     if os.path.isdir(uri):
         self.log.debug(
             "`{0}' is a directory, can't run an update operation.".format(
                 uri))
         return True
     if not os.path.isdir(recipes_dir):
         self.log.error(
             "Recipe location does not exist. Run `recipes add --force' to add recipes."
         )
         return False
     cache_dir_top_level, cache_dir = os.path.split(
         os.path.normpath(recipes_dir))
     # Do actual update
     self.log.info(
         "Updating recipe location `{alias}'...".format(alias=alias))
     if not Fetcher().update_src(uri, cache_dir_top_level, cache_dir, {}):
         self.log.error(
             "Failed to update recipe location `{alias}'...".format(
                 alias=alias))
         return False
     return True
Exemplo n.º 5
0
 def _add_recipes(self):
     """
     Add recipe location:
     - If a prefix was explicitly selected, install it there
     - Otherwise, use local config file
     - Check alias is not already used
     """
     alias = self.args.alias
     uri = self.args.uri[0]
     self.log.debug(
         "Preparing to add recipe location {name} -> {uri}".format(
             name=alias, uri=uri))
     # Check recipe location alias is valid:
     if re.match(r'[a-z][a-z0-9_]*', alias) is None:
         self.log.error("Invalid recipe alias: {alias}".format(alias=alias))
         exit(1)
     if self.cfg.get_named_recipe_dirs().has_key(alias):
         if self.args.force:
             self.log.info(
                 "Overwriting existing recipe alias `{0}'".format(alias))
         elif not confirm(
                 "Alias `{0}' already exists, overwrite?".format(alias)):
             self.log.warn('Aborting.')
             return -1
     store_to_prefix = self.prefix is not None and self.prefix.prefix_src in (
         "cli", "cwd")
     cfg_file = None
     recipe_cache = None
     if store_to_prefix:
         cfg_file = self.prefix.cfg_file
         recipe_cache_top_level = os.path.join(self.prefix.prefix_cfg_dir,
                                               self.cfg.recipe_cache_dir)
     else:
         cfg_file = self.cfg.local_cfg
         recipe_cache_top_level = os.path.join(self.cfg.local_cfg_dir,
                                               self.cfg.recipe_cache_dir)
     if not os.path.isdir(recipe_cache_top_level):
         self.log.debug(
             "Recipe cache dir does not exist, creating {0}".format(
                 recipe_cache_top_level))
         os.mkdir(recipe_cache_top_level)
     recipe_cache = os.path.join(recipe_cache_top_level, alias)
     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)
     # Let the fetcher download the location
     self.log.debug("Fetching into directory: {0}/{1}".format(
         recipe_cache_top_level, alias))
     Fetcher().fetch_url(uri, recipe_cache_top_level, alias, {})  # No args
     # Write this to config file
     self.cfg.update_cfg_file({'recipes': {alias: uri}}, cfg_file=cfg_file)
Exemplo n.º 6
0
    def update_recipe_repo(self, alias):
        """
        Update a remote recipe location by its alias name.
        """
        uri = self.cfg.get_named_recipe_sources()[alias]
        recipes_dir = self.cfg.get_named_recipe_dirs()[alias]

        cache_dir_top_level, cache_dir = os.path.split(
            os.path.normpath(recipes_dir))
        # Do actual update
        if not Fetcher().update_src(uri, cache_dir_top_level, cache_dir, {}):
            failure_msg = 'Failed to update {}'.format(alias)
            self.color_strips(failure_msg, 'red')
        else:
            update_msg = 'Successfully updated {}'.format(alias)
            self.color_strips(update_msg, 'blue')
        return True
Exemplo n.º 7
0
    def add_recipe_repo(self):
        """
        Add recipe location:
        - If a prefix was explicitly selected, install it there
        - Otherwise, use local config file
        - Check alias is not already used

        Works similar to the pybombs.commands.Recipes.add_recipe_dir()
        """
        prefix = self.cfg.get_active_prefix()
        cfg_file = None
        recipe_cache = None
        if self.recipeconfig_dialogui.checkBox.isChecked():
            cfg_file = prefix.cfg_file
            recipe_cache_top_level = os.path.join(prefix.prefix_cfg_dir,
                                                  self.cfg.recipe_cache_dir)
        else:
            cfg_file = self.cfg.local_cfg
            recipe_cache_top_level = os.path.join(self.cfg.local_cfg_dir,
                                                  self.cfg.recipe_cache_dir)

        if not os.path.isdir(recipe_cache_top_level):
            #self.log.debug("Recipe cache dir does not exist, creating" \
            #               "{0}".format(recipe_cache_top_level))
            os.mkdir(recipe_cache_top_level)
        recipe_cache = os.path.join(recipe_cache_top_level, self.recipe_alias)
        #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 self.recipe_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=self.recipe_alias))
            shutil.rmtree(recipe_cache)

        if not os.path.isdir(
                os.path.normpath(os.path.expanduser(self.recipe_uri))):
            #Let the fetcher download the location
            #self.log.debug("Fetching into directory: {0}/{1}".format(
            #    recipe_cache_top_level, self.recipe_alias))

            try:
                Fetcher().fetch_url(self.recipe_uri, recipe_cache_top_level,
                                    self.recipe_alias, {})  # No args
            except PBException as ex:
                #self.log.error("Could not fetch recipes: {s}".format(str(ex)))
                fetch_err_msg = 'Oops ! Could not fetch the recipes'
                self.color_strips(fetch_err_msg, 'red')
                return False

        # Write this to config file
        self.cfg.update_cfg_file(
            {'recipes': {
                self.recipe_alias: self.recipe_uri
            }},
            cfg_file=cfg_file)
        self.generate_recipe_data()
        self.set_table_widget()
        self.recipeconfig_dialogui.tableWidget.viewport().update()
        success_msg = 'Recipe added successfully !'
        self.color_strips(success_msg, 'blue')
        self.recipeconfig_dialogui.pushButton_2.setText("Add Recipe Repo")
        return True