def parse_download_link(self, line, in_download):
     """Parse ADT download link, expect to find a md5sum and a url"""
     if get_current_arch() == "i386":
         tag = 'id="linux-bundle32"'
     else:
         tag = 'id="linux-bundle64"'
     return self.category.parse_download_link(tag, line, in_download)
    def test_install_multi_arch_current_arch(self):
        """We install a multi_arch package corresponding to current arch"""
        multi_arch_name = "testpackage:{}".format(tools.get_current_arch())
        self.handler.install_bucket([multi_arch_name], lambda x: "", self.done_callback)
        self.wait_for_callback(self.done_callback)

        self.assertEqual(self.done_callback.call_args[0][0].bucket, [multi_arch_name])
        self.assertIsNone(self.done_callback.call_args[0][0].error)
        self.assertTrue(self.handler.is_bucket_installed(["testpackage"]))
    def is_bucket_installed(self, bucket):
        """Check if the bucket is installed

        The bucket is a list of packages to check if installed."""
        logger.debug("Check if {} is installed".format(bucket))
        is_installed = True
        for pkg_name in bucket:
            # /!\ danger: if current arch == ':appended_arch', on a non multiarch system, dpkg doesn't
            # understand that. strip :arch then
            if ":" in pkg_name:
                (pkg_without_arch_name, arch) = pkg_name.split(":", -1)
                if arch == get_current_arch():
                    pkg_name = pkg_without_arch_name
            if pkg_name not in self.cache or not self.cache[pkg_name].is_installed:
                logger.info("{} isn't installed".format(pkg_name))
                is_installed = False
        return is_installed
 def is_bucket_available(self, bucket):
     """Check if bucket available on the platform"""
     all_in_cache = True
     for pkg_name in bucket:
         if pkg_name not in self.cache:
             # this can be also a foo:arch and we don't have <arch> added. Tell is may be available
             if ":" in pkg_name:
                 # /!\ danger: if current arch == ':appended_arch', on a non multiarch system, dpkg doesn't
                 # understand that. strip :arch then
                 (pkg_without_arch_name, arch) = pkg_name.split(":", -1)
                 if arch == get_current_arch() and pkg_without_arch_name in self.cache:  # false positive, available
                     continue
                 elif arch not in get_foreign_archs():  # relax the constraint
                     logger.info("{} isn't available on this platform, but {} isn't enabled. So it may be available "
                                 "later on".format(pkg_name, arch))
                     continue
             logger.info("{} isn't available on this platform".format(pkg_name))
             all_in_cache = False
     return all_in_cache
 def is_installable(self):
     """Return if the framework can be installed on that arch"""
     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 len(self.only_ubuntu_version) > 0:
             current_version = get_current_ubuntu_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
 def test_get_current_arch_twice(self):
     """Current arch is reported twice and the same"""
     with self.create_dpkg("echo fooarch"):
         self.assertEquals(get_current_arch(), "fooarch")
         self.assertEquals(get_current_arch(), "fooarch")
 def test_get_current_arch(self):
     """Current arch is reported"""
     with self.create_dpkg("echo fooarch"):
         self.assertEquals(get_current_arch(), "fooarch")
    def _really_install_bucket(self, current_bucket):
        """Really install current bucket and bind signals"""
        bucket = current_bucket["bucket"]
        logger.debug("Starting {} installation".format(bucket))

        # exchange file output for apt and dpkg after the fork() call (open it empty)
        self.apt_fd = tempfile.NamedTemporaryFile(delete=False)
        self.apt_fd.close()

        if self.is_bucket_uptodate(bucket):
            return True

        for pkg_name in bucket:
            if ":" in pkg_name:
                arch = pkg_name.split(":", -1)[-1]
                # try to add the arch
                if arch not in get_foreign_archs() and arch != get_current_arch():
                    logger.info("Adding foreign arch: {}".format(arch))
                    with open(os.devnull, "w") as f:
                        try:
                            os.seteuid(0)
                            os.setegid(0)
                            if subprocess.call(["dpkg", "--add-architecture", arch], stdout=f) != 0:
                                msg = "Can't add foreign foreign architecture {}".format(arch)
                                raise BaseException(msg)
                            self.cache.update()
                        finally:
                            switch_to_current_user()
                        self._force_reload_apt_cache()

        # mark for install and so on
        for pkg_name in bucket:
            # /!\ danger: if current arch == ':appended_arch', on a non multiarch system, dpkg doesn't understand that
            # strip :arch then
            if ":" in pkg_name:
                (pkg_without_arch_name, arch) = pkg_name.split(":", -1)
                if arch == get_current_arch():
                    pkg_name = pkg_without_arch_name
            try:
                pkg = self.cache[pkg_name]
                if pkg.is_installed and pkg.is_upgradable:
                    logger.debug("Marking {} for upgrade".format(pkg_name))
                    pkg.mark_upgrade()
                else:
                    logger.debug("Marking {} for install".format(pkg_name))
                    pkg.mark_install(auto_fix=False)
            except Exception as msg:
                message = "Can't mark for install {}: {}".format(pkg_name, msg)
                raise BaseException(message)

        # this can raise on installedArchives() exception if the commit() fails
        try:
            os.seteuid(0)
            os.setegid(0)
            self.cache.commit(fetch_progress=self._FetchProgress(current_bucket,
                                                                 self.STATUS_DOWNLOADING,
                                                                 current_bucket["progress_callback"]),
                              install_progress=self._InstallProgress(current_bucket,
                                                                     self.STATUS_INSTALLING,
                                                                     current_bucket["progress_callback"],
                                                                     self._force_reload_apt_cache,
                                                                     self.apt_fd.name))
        finally:
            switch_to_current_user()

        return True
 def test_is_bucket_available_multi_arch_current_arch(self):
     """We return a package is available on the current platform"""
     self.assertTrue(self.handler.is_bucket_available(['testpackage:{}'.format(tools.get_current_arch())]))
 def test_is_bucket_uptodate_multi_arch_current_arch(self):
     """Installed bucket should return as being uptodate even if contains multi-arch part with current package"""
     self.handler.install_bucket(["testpackage"], lambda x: "", self.done_callback)
     self.wait_for_callback(self.done_callback)
     self.assertTrue(self.handler.is_bucket_uptodate(["testpackage:{}".format(tools.get_current_arch())]))