Esempio n. 1
0
 def __raise_dependency_not_found(self,
                                  dep_exp: str,
                                  watcher: Optional[ProcessWatcher],
                                  dependent: Optional[str] = None):
     if watcher:
         message.show_dep_not_found(depname=dep_exp,
                                    i18n=self.i18n,
                                    watcher=watcher,
                                    dependent=dependent)
         raise PackageNotFoundException(dep_exp)
     else:
         raise PackageNotFoundException(dep_exp)
Esempio n. 2
0
    def map_known_missing_deps(
            self,
            known_deps: Dict[str, str],
            watcher: ProcessWatcher,
            check_subdeps: bool = True) -> Optional[List[Tuple[str, str]]]:
        sorted_deps = [
        ]  # it will hold the proper order to install the missing dependencies

        repo_deps, aur_deps = set(), set()

        for dep, repo in known_deps.items():
            if repo == 'aur':
                aur_deps.add(dep)
            else:
                repo_deps.add(dep)

        if check_subdeps:
            for deps in ((repo_deps, 'repo'), (aur_deps, 'aur')):
                if deps[0]:
                    missing_subdeps = self.get_missing_subdeps_of(
                        deps[0], deps[1])

                    if missing_subdeps:
                        for dep in missing_subdeps:
                            if not dep[1]:
                                dependents = ', '.join(
                                    deps[0]
                                )  # it is not possible to know which is the exact dependent
                                message.show_dep_not_found(
                                    dep[0],
                                    self.i18n,
                                    watcher,
                                    dependent=dependents)
                                return

                        for dep in missing_subdeps:
                            if dep not in sorted_deps:
                                sorted_deps.append(dep)

        for dep, repo in known_deps.items():
            if repo != 'aur':
                data = (dep, repo)
                if data not in sorted_deps:
                    sorted_deps.append(data)

        for dep in aur_deps:
            sorted_deps.append((dep, 'aur'))

        return sorted_deps
Esempio n. 3
0
    def _map_unknown_missing_deps(
            self,
            deps: List[str],
            watcher: ProcessWatcher,
            check_subdeps: bool = True) -> List[Tuple[str, str]]:
        depnames = {RE_SPLIT_VERSION.split(dep)[0] for dep in deps}
        dep_repos = self._map_repos(depnames)

        if len(depnames) != len(
                dep_repos
        ):  # checking if a dependency could not be found in any mirror
            for dep in depnames:
                if dep not in dep_repos:
                    message.show_dep_not_found(dep, self.i18n, watcher)
                    return

        return self._map_known_missing_deps(dep_repos, watcher, check_subdeps)
Esempio n. 4
0
    def _map_known_missing_deps(
            self,
            known_deps: Dict[str, str],
            watcher: ProcessWatcher,
            check_subdeps: bool = True) -> List[Tuple[str, str]]:
        sorted_deps = [
        ]  # it will hold the proper order to install the missing dependencies

        repo_deps, aur_deps = set(), set()

        for dep, repo in known_deps.items():
            if repo == 'aur':
                aur_deps.add(dep)
            else:
                repo_deps.add(dep)

        if check_subdeps:
            for deps in ((repo_deps, 'repo'), (aur_deps, 'aur')):
                if deps[0]:
                    missing_subdeps = self.deps_analyser.get_missing_subdeps_of(
                        deps[0], deps[1])

                    if missing_subdeps:
                        for dep in missing_subdeps:
                            if not dep[1]:
                                message.show_dep_not_found(
                                    dep[0], self.i18n, watcher)
                                return

                        for dep in missing_subdeps:
                            sorted_deps.append(dep)

        for dep, repo in known_deps.items():
            if repo != 'aur':
                sorted_deps.append((dep, repo))

        for dep in aur_deps:
            sorted_deps.append((dep, 'aur'))

        return sorted_deps
Esempio n. 5
0
    def _install_missings_deps_and_keys(self, pkgname: str, root_password: str,
                                        handler: ProcessHandler,
                                        pkgdir: str) -> bool:
        handler.watcher.change_substatus(
            self.i18n['arch.checking.deps'].format(bold(pkgname)))
        check_res = makepkg.check(pkgdir, handler)

        if check_res:
            if check_res.get('missing_deps'):
                depnames = {
                    RE_SPLIT_VERSION.split(dep)[0]
                    for dep in check_res['missing_deps']
                }
                dep_mirrors = self._map_mirrors(depnames)

                for dep in depnames:  # cheking if a dependency could not be found in any mirror
                    if dep not in dep_mirrors:
                        message.show_dep_not_found(dep, self.i18n,
                                                   handler.watcher)
                        return False

                handler.watcher.change_substatus(
                    self.i18n['arch.missing_deps_found'].format(bold(pkgname)))

                if not confirmation.request_install_missing_deps(
                        pkgname, dep_mirrors, handler.watcher, self.i18n):
                    handler.watcher.print(self.i18n['action.cancelled'])
                    return False

                dep_not_installed = self._install_deps(depnames,
                                                       dep_mirrors,
                                                       root_password,
                                                       handler,
                                                       change_progress=False)

                if dep_not_installed:
                    message.show_dep_not_installed(handler.watcher, pkgname,
                                                   dep_not_installed,
                                                   self.i18n)
                    return False

                # it is necessary to re-check because missing PGP keys are only notified when there are none missing
                return self._install_missings_deps_and_keys(
                    pkgname, root_password, handler, pkgdir)

            if check_res.get('gpg_key'):
                if handler.watcher.request_confirmation(
                        title=self.i18n['arch.aur.install.unknown_key.title'],
                        body=self.i18n['arch.install.aur.unknown_key.body'].
                        format(bold(pkgname), bold(check_res['gpg_key']))):
                    handler.watcher.change_substatus(
                        self.i18n['arch.aur.install.unknown_key.status'].
                        format(bold(check_res['gpg_key'])))
                    if not handler.handle(gpg.receive_key(
                            check_res['gpg_key'])):
                        handler.watcher.show_message(
                            title=self.i18n['error'],
                            body=self.
                            i18n['arch.aur.install.unknown_key.receive_error'].
                            format(bold(check_res['gpg_key'])))
                        return False
                else:
                    handler.watcher.print(self.i18n['action.cancelled'])
                    return False

        return True
Esempio n. 6
0
    def _fill_missing_dep(self, dep_name: str, dep_exp: str,
                          aur_index: Iterable[str],
                          missing_deps: Set[Tuple[str, str]],
                          remote_provided_map: Dict[str, Set[str]],
                          remote_repo_map: Dict[str, str], repo_deps: Set[str],
                          aur_deps: Set[str], deps_data: Dict[str, dict],
                          watcher: ProcessWatcher, automatch_providers: bool):

        if dep_name == dep_exp:
            providers = remote_provided_map.get(dep_name)

            if not providers:  # try to find the package through the pacman's search mechanism
                match = pacman.find_one_match(dep_name)

                if match:
                    providers = {match}

        else:  # handling cases when the dep has an expression ( e.g: xpto>=0.12 )
            providers = remote_provided_map.get(dep_exp)

            if providers is None:
                providers = remote_provided_map.get(dep_name)

                if not providers:  # try to find the package through the pacman's search mechanism
                    match = pacman.find_one_match(dep_name)

                    if match:
                        providers = {match}

                if providers and len(providers) > 1:
                    no_mapped_data = {
                        p
                        for p in providers if p not in deps_data
                    }  # checking providers with no mapped data

                    if no_mapped_data:
                        providers_data = pacman.map_updates_data(
                            no_mapped_data)

                        if not providers_data:
                            raise Exception(
                                "Could not retrieve the info from providers: {}"
                                .format(no_mapped_data))

                        deps_data.update(
                            providers_data)  # adding missing providers data

                    matched_providers = set()
                    split_informed_dep = self.re_dep_operator.split(dep_exp)
                    try:
                        version_informed = parse_version(split_informed_dep[2])
                        exp_op = split_informed_dep[
                            1] if split_informed_dep[1] != '=' else '=='

                        for p in providers:
                            provided = deps_data[p]['p']

                            for provided_exp in provided:
                                split_dep = self.re_dep_operator.split(
                                    provided_exp)

                                if len(split_dep
                                       ) == 3 and split_dep[0] == dep_name:
                                    provided_version = parse_version(
                                        split_dep[2])

                                    if eval('provided_version {} version_informed'
                                            .format(exp_op)):
                                        matched_providers.add(p)
                                        break

                        providers = matched_providers
                    except:
                        traceback.print_exc()

        if providers:
            if len(providers) > 1:
                dep_data = None

                if automatch_providers:
                    exact_matches = [p for p in providers if p == dep_name]

                    if exact_matches:
                        dep_data = (exact_matches[0],
                                    remote_repo_map.get(exact_matches[0]))

                if not dep_data:
                    dep_data = (dep_name, '__several__')
            else:
                real_name = providers.pop()
                dep_data = (real_name, remote_repo_map.get(real_name))

            repo_deps.add(dep_data[0])
            missing_deps.add(dep_data)

        elif aur_index and dep_name in aur_index:
            aur_deps.add(dep_name)
            missing_deps.add((dep_name, 'aur'))
        else:
            if watcher:
                message.show_dep_not_found(dep_exp, self.i18n, watcher)
                raise PackageNotFoundException(dep_exp)
            else:
                raise PackageNotFoundException(dep_exp)