Esempio n. 1
0
 def run(self):
     """ Go, go, go! """
     ### Sanity checks
     for pkg in self.args.packages:
         if not self.pm.installed(recipe.get_recipe(pkg)):
             self.log.error("Package {0} is not installed into current prefix. Aborting.".format(pkg))
             exit(1)
     ### Make install tree
     rb_tree = dep_manager.DepManager().make_dep_tree(
         self.args.packages,
         lambda x: bool(
             (x in self.args.packages) or \
             (self.args.deps and self.pm.installed(recipe.get_recipe(x)))
         )
     )
     self.log.debug("Install tree:")
     if self.log.getEffectiveLevel() <= 20 or self.args.print_tree:
         rb_tree.pretty_print()
     ### Recursively rebuild, starting at the leaf nodes
     while not rb_tree.empty():
         pkg = rb_tree.pop_leaf_node()
         rec = recipe.get_recipe(pkg)
         self.log.info("Rebuilding package: {0}".format(pkg))
         if not self.pm.rebuild(
             rec,
             make_clean=self.args.clean,
             nuke_builddir=not self.args.keep_build
         ):
             self.log.error("Error rebuilding package {0}. Aborting.".format(pkg))
             exit(1)
         self.log.info("Rebuild successful.")
Esempio n. 2
0
 def run(self):
     """ Go, go, go! """
     ### Sanity checks
     for pkg in self.args.packages:
         if not self.is_installed(pkg):
             self.log.error("Package {0} is not installed into current prefix. Aborting.".format(pkg))
             return -1
     ### Make install tree
     rb_tree = dep_manager.DepManager().make_dep_tree(
         self.args.packages,
         lambda x: bool(
             (x in self.args.packages) or \
             (self.args.deps and self.is_installed(x))
         )
     )
     if self.log.getEffectiveLevel() <= 10 or self.args.print_tree:
         print("Rebuild tree:")
         rb_tree.pretty_print()
     ### Recursively rebuild, starting at the leaf nodes
     node_cache = []
     while not rb_tree.empty():
         pkg = rb_tree.pop_leaf_node()
         if pkg in node_cache:
             continue
         rec = recipe.get_recipe(pkg)
         self.log.info("Rebuilding package: {0}".format(pkg))
         if not self.pm.rebuild(
                 rec,
                 make_clean=self.args.clean,
                 nuke_builddir=not (self.args.keep_build or bool(self.cfg.get('keep_builddir', False)))
         ):
             self.log.error("Error rebuilding package {0}. Aborting.".format(pkg))
             return 1
         self.log.info("Rebuild successful.")
Esempio n. 3
0
    def install(
        self,
        packages,
        mode,  # install / update
        fail_if_not_exists=False,
        update_if_exists=False,
        quiet=False,
        print_tree=False,
        deps_only=False,
        no_deps=False,
        verify=False,
        static=False,
    ):
        """
        Install packages.
        """
        def _check_if_pkg_goes_into_tree(pkg):
            " Return True if pkg has a legitimate right to be in the tree. "
            if fail_if_not_exists:
                return bool(self.pm.installed(pkg))
            return update_if_exists or not self.pm.installed(pkg)

        ### Sanity checks
        if fail_if_not_exists:
            for pkg in packages:
                if not self.pm.installed(pkg):
                    self.log.error(
                        "Package {0} is not installed. Aborting.".format(pkg))
                    return False
        ### Make install tree
        install_tree = dep_manager.DepManager(self.pm).make_dep_tree(
            packages, _check_if_pkg_goes_into_tree
            if not no_deps else lambda x: bool(x in packages))
        if len(install_tree) == 0 and not quiet:
            self.log.info("No packages to install.")
            return True
        if (self.log.getEffectiveLevel() <= 20 or print_tree) and not quiet:
            print("Install tree:")
            install_tree.pretty_print()
        ### Recursively install/update, starting at the leaf nodes
        for pkg in install_tree.serialize():
            if mode == 'install' and deps_only and pkg in packages:
                self.log.debug(
                    "Skipping `{0}' because only deps are requested.")
                continue
            if self.pm.installed(pkg):
                self.log.info("Updating package: {0}".format(pkg))
                if not self.pm.update(pkg, verify=verify):
                    self.log.error(
                        "Error updating package {0}. Aborting.".format(pkg))
                    return False
                self.log.info("Update successful.")
            else:
                self.log.info("Installing package: {0}".format(pkg))
                if not self.pm.install(pkg, static=static, verify=verify):
                    self.log.error(
                        "Error installing package {0}. Aborting.".format(pkg))
                    return False
                self.log.info("Installation successful.")
        return True
Esempio n. 4
0
 def run(self):
     """ Go, go, go! """
     ### Sanity checks
     if self.fail_if_not_exists:
         for pkg in self.args.packages:
             if not self.pm.installed(pkg):
                 self.log.error("Package {0} is not installed. Aborting.".format(pkg))
                 exit(1)
     ### Make install tree
     install_tree = dep_manager.DepManager().make_dep_tree(
         self.args.packages,
         self._check_if_pkg_goes_into_tree if not self.args.no_deps else lambda x: bool(x in self.args.packages)
     )
     if len(install_tree) == 0 and not hasattr(self.args, 'quiet_install'):
         self.log.info("No packages to install.")
         return 0
     self.log.debug("Install tree:")
     if self.log.getEffectiveLevel() <= 20 or self.args.print_tree:
         install_tree.pretty_print()
     ### Recursively install/update, starting at the leaf nodes
     install_cache = []
     while len(install_tree):
         pkg = install_tree.pop_leaf_node()
         if pkg in install_cache:
             continue
         install_cache.append(pkg)
         if self.cmd == 'install' and self.args.deps_only and pkg in self.args.packages:
             self.log.debug("Skipping `{0}' because only deps are requested.")
             continue
         if self.pm.installed(pkg):
             self.log.info("Updating package: {0}".format(pkg))
             if not self.pm.update(pkg, verify=self.args.verify):
                 self.log.error("Error updating package {0}. Aborting.".format(pkg))
                 exit(1)
             self.log.info("Update successful.")
         else:
             self.log.info("Installing package: {0}".format(pkg))
             if not self.pm.install(pkg, static=self.args.static, verify=self.args.verify):
                 self.log.error("Error installing package {0}. Aborting.".format(pkg))
                 exit(1)
             self.log.info("Installation successful.")
Esempio n. 5
0
 def run(self):
     """ Go, go, go! """
     ### Sanity checks
     for pkg in self.args.packages:
         if not self.is_installed(pkg):
             self.log.error("Package {0} is not installed. Aborting.".format(pkg))
             return 1
     dep_tree = dep_manager.DepManager().make_dep_tree(
         self.args.packages,
         lambda x: bool(x in self.args.packages),
     )
     ### Remove packages
     for pkg in reversed(dep_tree.serialize()):
         self.log.info("Removing package {0}.".format(pkg))
         # Uninstall:
         self.log.debug("Uninstalling.")
         if not self.pm.uninstall(pkg):
             self.log.warn("Could not uninstall {0} from prefix.".format(pkg))
         # Remove entry from inventory:
         self.log.debug("Removing package from inventory.")
         self.inventory.remove(pkg)
         self.inventory.save()
Esempio n. 6
0
    def install(
            self,
            packages,
            mode,  # install / update
            fail_if_not_exists=False,  # Fail if any package in `packages' is not already installed
            update_if_exists=False,
            quiet=False,
            print_tree=False,
            deps_only=False,
            no_deps=False,
            verify=False,
            static=False,
            install_type=None):
        """
        Install packages.
        """
        def _check_if_pkg_goes_into_tree(pkg):
            " Return True if pkg has a legitimate right to be in the tree. "
            if fail_if_not_exists:
                return bool(self.pm.installed(pkg))
            if no_deps and pkg not in packages:
                return False
            if not self.pm.installed(pkg):
                # If it's not installed, we'll try a binary install...
                self.log.debug(
                    "Testing binary install for package {pkg}.".format(
                        pkg=pkg))
                if self.pm.install(pkg,
                                   install_type="binary",
                                   static=static,
                                   verify=verify,
                                   fail_silently=True):
                    # ...and if that worked, it doesn't have to go into the tree.
                    return False
                # Now it's still not installed, so it has to go into the tree:
                return True
            else:
                # If a package is already installed, but not flagged for
                # updating, it does not go into the tree:
                if not update_if_exists or not pkg in packages:
                    return False
                # OK, so it needs updating. But only if it's a source package:
                if self.pm.installed(pkg, install_type="source"):
                    return True
                # Otherwise, we should give it a shot:
                self.pm.update(pkg, install_type="binary")
            assert False  # Should never reach this line

        ####### install() starts here #########
        ### Sanity checks
        if fail_if_not_exists:
            for pkg in packages:
                if not self.pm.installed(pkg):
                    self.log.error(
                        "Package {0} is not installed. Aborting.".format(pkg))
                    return False
        extra_info_logger = self.log.info if not quiet else self.log.debug
        ### Make install tree and install binary packages
        extra_info_logger(
            "Phase 1: Creating install tree and installing binary packages:")
        install_tree = dep_manager.DepManager(self.pm).make_dep_tree(
            packages, _check_if_pkg_goes_into_tree)
        if len(install_tree) == 0 and not quiet:
            self.log.info("No packages to install.")
            return True
        if (self.log.getEffectiveLevel() <= 20 or print_tree) and not quiet:
            print("Install tree:")
            install_tree.pretty_print()
        if len(install_tree) > 0 and install_type == "binary":
            self.log.error(
                "Install method was `binary', but source packages are left over!"
            )
            return False
        ### Recursively install/update source packages, starting at the leaf nodes
        extra_info_logger(
            "Phase 2: Recursively installing source packages to prefix:")
        for pkg in install_tree.serialize():
            if mode == 'install' and deps_only and pkg in packages:
                self.log.debug(
                    "Skipping `{0}' because only deps are requested.")
                continue
            if self.pm.installed(pkg):
                self.log.info("Updating package: {0}".format(pkg))
                if not self.pm.update(
                        pkg, install_type="source", verify=verify):
                    self.log.error(
                        "Error updating package {0}. Aborting.".format(pkg))
                    return False
                self.log.info("Update successful.")
            else:
                self.log.info("Installing package: {0}".format(pkg))
                if not self.pm.install(
                        pkg, install_type="source", static=static,
                        verify=verify):
                    self.log.error(
                        "Error installing package {0}. Aborting.".format(pkg))
                    return False
                self.log.info("Installation successful.")
        return True
Esempio n. 7
0
    def install(
            self,
            packages,
            mode,  # install / update
            fail_if_not_exists=False,  # Fail if any package in `packages' is not already installed
            update_if_exists=False,
            quiet=False,
            print_tree=False,
            deps_only=False,
            no_deps=False,
            verify=False,
            static=False,
            install_type=None):
        """
        Install packages.
        """
        def _check_if_pkg_goes_into_tree(pkg):
            " Return True if pkg has a legitimate right to be in the tree. "
            self.log.trace(
                "Checking if package `{pkg}' goes into tree...".format(
                    pkg=pkg))
            if fail_if_not_exists and not bool(self.pm.installed(pkg)):
                self.log.trace(
                    "Only installed packages need to into tree, and this one is not."
                )
                return False
            if no_deps and pkg not in packages:
                self.log.trace("Not installing, because it's not in the list.")
                return False
            if not self.pm.exists(pkg):
                self.log.error(
                    "Package has no install method: {0}".format(pkg))
                raise PBException("Unresolved install path.")
            if not self.pm.installed(pkg):
                # If it's not installed, we'll try a binary install...
                self.log.debug(
                    "Testing binary install for package {pkg}.".format(
                        pkg=pkg))
                if self.pm.install(pkg,
                                   install_type="binary",
                                   static=static,
                                   verify=verify,
                                   fail_silently=True):
                    self.log.trace(
                        "Binary install successful, so we don't put it into tree."
                    )
                    # ...and if that worked, it doesn't have to go into the tree.
                    return False
                self.log.trace("Not installed: It goes into tree.")
                # Now it's still not installed, so it has to go into the tree:
                return True
            else:
                # If a package is already installed, but not flagged for
                # updating, it does not go into the tree:
                if not update_if_exists or pkg not in packages:
                    self.log.trace(
                        "Installed, but no update requested. Does not go into tree."
                    )
                    return False
                # OK, so it needs updating. But only if it's a source package:
                if self.pm.installed(pkg, install_type="source"):
                    self.log.trace(
                        "Package was source-installed, and needs update.")
                    return True
                # Otherwise, we should give it a shot:
                self.log.trace(
                    "Doesn't go into tree, but we'll try a packager update.")
                self.pm.update(pkg, install_type="binary")
                return False
            assert False  # Should never reach this line

        _checker_cache = {}

        def _cached_check_if_pkg_goes_into_tree(pkg, check_callback):
            if pkg in _checker_cache:
                return _checker_cache[pkg]
            ret_val = check_callback(pkg)
            _checker_cache[pkg] = ret_val
            return ret_val

        ####### install() starts here #########
        ### Sanity checks
        if fail_if_not_exists:
            for pkg in packages:
                if not self.pm.installed(pkg):
                    self.log.error(
                        "Package {0} is not installed. Aborting.".format(pkg))
                    return False
        extra_info_logger = self.log.info if not quiet else self.log.debug
        ### Make install tree and install binary packages
        extra_info_logger(
            "Phase 1: Creating install tree and installing binary packages:")
        install_tree = dep_manager.DepManager().make_dep_tree(
            packages, lambda pkg: _cached_check_if_pkg_goes_into_tree(
                pkg, _check_if_pkg_goes_into_tree))
        if len(install_tree) == 0 and not quiet:
            extra_info_logger("No packages to install.")
            return True
        if (self.log.getEffectiveLevel() <= 20 or print_tree) and not quiet:
            print("Install tree:")
            install_tree.pretty_print()
        if len(install_tree) > 0 and install_type == "binary":
            self.log.error(
                "Install method was `binary', but source packages are left over!"
            )
            return False
        extra_info_logger(
            "Phase 1 complete: All binary dependencies installed.")
        ### Recursively install/update source packages, starting at the leaf nodes
        extra_info_logger(
            "Phase 2: Recursively installing source packages to prefix:")
        for pkg in install_tree.serialize():
            if mode == 'install' and deps_only and pkg in packages:
                self.log.debug(
                    "Skipping `{0}' because only deps are requested.")
                continue
            if self.pm.installed(pkg):
                self.log.info("Updating package: {0}".format(pkg))
                if not self.pm.update(
                        pkg, install_type="source", verify=verify):
                    self.log.error(
                        "Error updating package {0}. Aborting.".format(pkg))
                    return False
                self.log.info("Update successful.")
            else:
                self.log.info("Installing package: {0}".format(pkg))
                if not self.pm.install(
                        pkg, install_type="source", static=static,
                        verify=verify):
                    self.log.error(
                        "Error installing package {0}. Aborting.".format(pkg))
                    return False
                self.log.info("Installation successful.")
        extra_info_logger("Phase 2 complete: All source packages installed.")
        return True
Esempio n. 8
0
    def run(self):
        self.pid = os.getpid()
        self.pid_info.emit(self.pid)
        instaman = install_manager.InstallManager()
        if 'install' in self.package_list:
            install_list = self.package_list.get('install')
            for package in install_list:
                self.worker_log.info('Preparing {} for installation'.format(package))
                if instaman.install([package], 'install'):
                    self.worker_log.info("Install {} successful".format(package))
                    pkg_index = install_list.index(package)+1
                    progress = (pkg_index/len(install_list))* 100.0
                    self.progress_tick.emit(pkg_index, progress,
                                            len(install_list), 'install')
                else:
                    self.worker_log.error("Install Failed")
                    self.error_info.emit('install',
                                         "Install {} failed. Check logs !".format(package))

        if 'update' in self.package_list:
            update_list = self.package_list.get('update')
            for package in update_list:
                self.worker_log.info("Preparing {} to update".format(package))
                if instaman.install([package], 'update', update_if_exists=True):
                    self.worker_log.info("Update {} successful".format(package))
                    pkg_index = update_list.index(package)+1
                    progress = (pkg_index/len(update_list))* 100.0
                    self.progress_tick.emit(pkg_index, progress,
                                            len(update_list), 'update')
                else:
                    self.worker_log.error("Update Failed")
                    self.error_info.emit(
                        "Update {} failed. Check logs !".format(package))

        if 'remove' in self.package_list:
            remove_list = self.package_list.get('remove')
            pm = package_manager.PackageManager()
            dep_tree = dep_manager.DepManager().make_dep_tree(
            self.package_list.get('remove'),
            lambda x: bool(x in self.package_list.get('remove')))
            remove = reversed(dep_tree.serialize())
            ### Remove packages
            for pkg in remove:
                #Uninstall:
                self.worker_log.info("Preparing {} to remove".format(pkg))
                if pm.uninstall(pkg):
                    self.worker_log.info("Uninstall {} successful !".format(pkg))
                    pkg_index = remove_list.index(pkg)+1
                    progress = (pkg_index/len(remove_list))* 100.0
                    self.progress_tick.emit(pkg_index, progress,
                                            len(remove_list), 'remove')
                    #Remove entry from inventory:
                    self.inventory.remove(pkg)
                    self.inventory.save()
                else:
                    self.worker_log.error("Failed to remove {}".format(pkg))
                    self.error_info.emit(
                        "Removing {} unsuccessful. Check logs !".format(pkg))

        self.info_tick.emit("Tasks Completed successfully !")
        return