def test_install_pending_order(self):
        """Installation order of pending requests are respected"""
        done_callback = Mock()
        done_callback.side_effect = self.done_callback
        done_callback0 = Mock()
        done_callback0.side_effect = self.done_callback
        ordered_progress_callback = Mock()
        progress_callback = Mock()
        progress_callback.side_effect = ordered_progress_callback
        progress_callback0 = Mock()
        progress_callback0.side_effect = ordered_progress_callback
        self.handler.install_bucket(["testpackage"], progress_callback,
                                    done_callback)
        self.handler.install_bucket(["testpackage0"], progress_callback0,
                                    done_callback0)
        self.wait_for_callback(done_callback)
        self.wait_for_callback(done_callback0)

        self.assertEqual(self.done_callback.call_args_list, [
            call(
                RequirementsHandler.RequirementsResult(bucket=['testpackage'],
                                                       error=None)),
            call(
                RequirementsHandler.RequirementsResult(bucket=['testpackage0'],
                                                       error=None))
        ])
        # we will get progress with 0, 1 (first bucket), 0, 1 (second bucket). So 4 progress signal status change
        current_status = RequirementsHandler.STATUS_DOWNLOADING
        current_status_change_count = 1
        calls = ordered_progress_callback.call_args_list
        for current_call in calls[1:]:
            if current_call[0][0]['step'] != current_status:
                current_status = current_call[0][0]['step']
                current_status_change_count += 1
        self.assertEqual(current_status_change_count, 4)
Exemple #2
0
 def is_installable(self):
     """Return if the framework can be installed on that arch"""
     if self.only_for_removal:
         return False
     try:
         if len(self.only_on_archs) > 0:
             # we have some restricted archs, check we support it
             current_arch = get_current_arch()
             if current_arch not in self.only_on_archs:
                 logger.debug(
                     "{} only supports {} archs and you are on {}.".format(
                         self.name, self.only_on_archs, current_arch))
                 return False
         if self.only_ubuntu:
             # set framework installable only on ubuntu
             if get_current_distro_id() != "ubuntu":
                 return False
         if len(self.only_ubuntu_version) > 0:
             current_version = get_current_distro_version()
             if current_version not in self.only_ubuntu_version:
                 logger.debug(
                     "{} only supports {} and you are on {}.".format(
                         self.name, self.only_ubuntu_version,
                         current_version))
                 return False
         if not RequirementsHandler().is_bucket_available(
                 self.packages_requirements):
             return False
     except:
         logger.error(
             "An error occurred when detecting platform, don't register {}".
             format(self.name))
         return False
     return True
Exemple #3
0
 def is_installed(self):
     """Method call to know if the framework is installed"""
     if not os.path.isdir(self.install_path):
         return False
     if not RequirementsHandler().is_bucket_installed(self.packages_requirements):
         return False
     return True
Exemple #4
0
    def setUpClass(cls):
        super().setUpClass()
        cls.handler = RequirementsHandler()

        apt.apt_pkg.config.set("Dir::Cache::pkgcache", "")
        apt.apt_pkg.config.set("Dir::Cache::srcpkgcache", "")
        apt.apt_pkg.config.clear("APT::Update::Post-Invoke")
        apt.apt_pkg.config.clear("APT::Update::Post-Invoke-Success")
        apt.apt_pkg.config.clear("DPkg::Post-Invoke")
        cls.apt_package_dir = os.path.join(get_data_dir(), "apt")
        cls.apt_status_dir = os.path.join(cls.apt_package_dir, "states")
 def start_download_and_install(self):
     self.last_progress_download = None
     self.last_progress_requirement = None
     self.balance_requirement_download = None
     self.pkg_size_download = 0
     self.result_requirement = None
     self.result_download = None
     self._download_done_callback_called = False
     UI.display(DisplayMessage("Downloading and installing requirements"))
     self.pbar = ProgressBar().start()
     self.pkg_to_install = RequirementsHandler().install_bucket(self.packages_requirements,
                                                                self.get_progress_requirement,
                                                                self.requirement_done)
     DownloadCenter(urls=self.download_requests, on_done=self.download_done, report=self.get_progress_download)
    def __init__(self, name, description, category, logo_path=None, is_category_default=False, install_path_dir=None,
                 only_on_archs=None, only_ubuntu_version=None, packages_requirements=None):
        self.name = name
        self.description = description
        self.logo_path = None
        self.category = category
        self.is_category_default = is_category_default
        self.only_on_archs = [] if only_on_archs is None else only_on_archs
        self.only_ubuntu_version = [] if only_ubuntu_version is None else only_ubuntu_version
        self.packages_requirements = [] if packages_requirements is None else packages_requirements
        self.packages_requirements.extend(self.category.packages_requirements)

        # don't detect anything for completion mode (as we need to be quick), so avoid opening apt cache and detect
        # if it's installed.
        if is_completion_mode():
            category.register_framework(self)
            return

        self.need_root_access = False
        with suppress(KeyError):
            self.need_root_access = not RequirementsHandler().is_bucket_installed(self.packages_requirements)

        if self.is_category_default:
            if self.category == BaseCategory.main_category:
                logger.error("Main category can't have default framework as {} requires".format(name))
                self.is_category_default = False
            elif self.category.default_framework is not None:
                logger.error("Can't set {} as default for {}: this category already has a default framework ({}). "
                             "Don't set any as default".format(category.name, name,
                                                               self.category.default_framework.name))
                self.is_category_default = False
                self.category.default_framework.is_category_default = False

        if not install_path_dir:
            install_path_dir = os.path.join("" if category.is_main_category else category.prog_name, self.prog_name)
        self.default_install_path = os.path.join(DEFAULT_INSTALL_TOOLS_PATH, install_path_dir)
        self.install_path = self.default_install_path
        # check if we have an install path previously set
        config = ConfigHandler().config
        try:
            self.install_path = config["frameworks"][category.prog_name][self.prog_name]["path"]
        except (TypeError, KeyError, FileNotFoundError):
            pass

        # This requires install_path and will register need_root or not
        if not self.is_installed and not self.is_installable:
            logger.info("Don't register {} as it's not installable on this configuration.".format(name))
            return

        category.register_framework(self)
 def test_singleton(self):
     """Ensure we are delivering a singleton for RequirementsHandler"""
     other = RequirementsHandler()
     self.assertEqual(self.handler, other)
 def setUpClass(cls):
     super().setUpClass()
     cls.handler = RequirementsHandler()