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 read_dependencies(name: str) -> Set[str]:
    dep_info = new_subprocess(['pacman', '-Si', name])

    not_found = False

    for o in dep_info.stderr:
        if o:
            err_line = o.decode()

            if err_line:
                if RE_DEP_NOTFOUND.findall(err_line):
                    not_found = True

    if not_found:
        raise PackageNotFoundException(name)

    depends_on = set()
    for out in new_subprocess(['grep', '-Po', 'Depends\s+On\s+:\s\K(.+)'],
                              stdin=dep_info.stdout).stdout:
        if out:
            line = out.decode().strip()

            if line:
                depends_on.update(
                    [d for d in line.split(' ') if d and d.lower() != 'none'])

    return depends_on
Esempio n. 3
0
def read_provides(name: str) -> Set[str]:
    dep_info = new_subprocess(['pacman', '-Si', name])

    not_found = False

    for o in dep_info.stderr:
        if o:
            err_line = o.decode()

            if err_line:
                if RE_DEP_NOTFOUND.findall(err_line):
                    not_found = True

    if not_found:
        raise PackageNotFoundException(name)

    provides = None

    for out in new_subprocess(['grep', '-Po', 'Provides\s+:\s\K(.+)'],
                              stdin=dep_info.stdout).stdout:
        if out:
            provided_names = [
                p.strip() for p in out.decode().strip().split(' ') if p
            ]

            if provided_names[0].lower() == 'none':
                provides = {name}
            else:
                provides = {name, *provided_names}

    return provides
Esempio n. 4
0
    def get_required_dependencies(self, name: str) -> Set[str]:
        info = self.get_src_info(name)

        if not info:
            raise PackageNotFoundException(name)

        return self.extract_required_dependencies(info)
Esempio n. 5
0
def list_hard_requirements(
        name: str,
        logger: Optional[logging.Logger] = None) -> Optional[Set[str]]:
    code, output = system.execute(
        'pacman -Rc {} --print-format=%n'.format(name), shell=True)

    if code != 0:
        if 'HoldPkg' in output:
            raise PackageInHoldException()
        elif 'target not found' in output:
            raise PackageNotFoundException(name)
        elif logger:
            logger.error(
                "Unexpected error while listing hard requirements of: {}".
                format(name))
            print('{}{}{}'.format(Fore.RED, output, Fore.RESET))
    elif output:
        reqs = set()

        for line in output.split('\n'):
            if line:
                line_strip = line.strip()

                if line_strip and line_strip != name:
                    reqs.add(line_strip)

        return reqs
Esempio n. 6
0
def list_hard_requirements(
        name: str,
        logger: Optional[logging.Logger] = None,
        assume_installed: Optional[Set[str]] = None) -> Optional[Set[str]]:
    cmd = StringIO()
    cmd.write(f'pacman -Rc {name} --print-format=%n ')

    if assume_installed:
        cmd.write(' '.join(f'--assume-installed={provider}'
                           for provider in assume_installed))

    code, output = system.execute(cmd.getvalue(), shell=True)

    if code != 0:
        if 'HoldPkg' in output:
            raise PackageInHoldException()
        elif 'target not found' in output:
            raise PackageNotFoundException(name)
        elif logger:
            logger.error(
                "Unexpected error while listing hard requirements of: {}".
                format(name))
            print('{}{}{}'.format(Fore.RED, output, Fore.RESET))
    elif output:
        reqs = set()

        for line in output.split('\n'):
            if line:
                line_strip = line.strip()

                if line_strip and line_strip != name:
                    reqs.add(line_strip)

        return reqs
Esempio n. 7
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)