示例#1
0
def parse_revdep(value):
    """Value should be an atom, packages with deps intersecting that match."""
    try:
        targetatom = atom.atom(value)
    except atom.MalformedAtom as e:
        raise parserestrict.ParseError(str(e))
    val_restrict = values.FlatteningRestriction(
        atom.atom,
        values.AnyMatch(values.FunctionRestriction(targetatom.intersects)))
    return packages.OrRestriction(*list(
        packages.PackageRestriction(dep, val_restrict)
        for dep in ('depends', 'rdepends', 'post_rdepends')))
示例#2
0
def unmerge(out, err, vdb, targets, options, formatter, world_set=None):
    """Unmerge tokens. hackish, should be rolled back into the resolver"""
    matches = set()
    unknown = set()
    for token, restriction in targets:
        # Catch restrictions matching across more than one category.
        # Multiple matches in the same category are acceptable.

        # The point is that matching across more than one category is
        # nearly always unintentional ("pmerge -C spork" without
        # realising there are sporks in more than one category), but
        # matching more than one cat/pkg is impossible without
        # explicit wildcards.
        installed = vdb.match(restriction)
        if not installed:
            unknown.add(token)
        categories = set(pkg.category for pkg in installed)
        if len(categories) > 1:
            raise parserestrict.ParseError(
                "%r is in multiple categories (%s)" %
                (token, ', '.join(sorted(set(pkg.key for pkg in installed)))))
        matches.update(installed)

    # fail out if no matches are found, otherwise just output a notification
    if unknown:
        if matches:
            err.write("Skipping unknown matches: %s\n" %
                      ', '.join(map(repr, unknown)))
        else:
            raise Failure("no matches found: %s" %
                          ', '.join(map(repr, unknown)))

    out.write(out.bold, 'The following packages are to be unmerged:')
    out.prefix = [out.bold, ' * ', out.reset]
    for pkg in matches:
        out.write(pkg.cpvstr)
    out.prefix = []

    repo_obs = observer.repo_observer(observer.formatter_output(out),
                                      not options.debug)

    if options.pretend:
        return

    if (options.ask and
            not formatter.ask("Would you like to unmerge these packages?")):
        return
    return do_unmerge(options, out, err, vdb, matches, world_set, repo_obs)
示例#3
0
def unmerge(out, err, vdb, restrictions, options, formatter, world_set=None):
    """Unmerge tokens. hackish, should be rolled back into the resolver"""
    all_matches = set()
    for restriction in restrictions:
        # Catch restrictions matching across more than one category.
        # Multiple matches in the same category are acceptable.

        # The point is that matching across more than one category is
        # nearly always unintentional ("pmerge -C spork" without
        # realising there are sporks in more than one category), but
        # matching more than one cat/pkg is impossible without
        # explicit wildcards.
        matches = vdb.match(restriction)
        if not matches:
            raise Failure('Nothing matches %s' % (restriction, ))
        categories = set(pkg.category for pkg in matches)
        if len(categories) > 1:
            raise parserestrict.ParseError(
                '%s is in multiple categories (%s)' %
                (restriction, ', '.join(set(pkg.key for pkg in matches))))
        all_matches.update(matches)

    matches = sorted(all_matches)
    out.write(out.bold, 'The following packages are to be unmerged:')
    out.prefix = [out.bold, ' * ', out.reset]
    for match in matches:
        out.write(match.cpvstr)
    out.prefix = []

    repo_obs = observer.repo_observer(observer.formatter_output(out),
                                      not options.debug)

    if options.pretend:
        return

    if (options.ask and
            not formatter.ask("Would you like to unmerge these packages?")):
        return
    return do_unmerge(options, out, err, vdb, matches, world_set, repo_obs)
示例#4
0
文件: pmerge.py 项目: ulm/pkgcore
def unmerge(out,
            err,
            installed_repos,
            targets,
            options,
            formatter,
            world_set=None):
    """Unmerge tokens. hackish, should be rolled back into the resolver"""
    # split real and virtual repos
    vdb = installed_repos.real.combined
    fake_vdb = installed_repos.virtual.combined

    matches = set()
    fake = set()
    unknown = set()
    for token, restriction in targets:
        # Catch restrictions matching across more than one category.
        # Multiple matches in the same category are acceptable.

        # The point is that matching across more than one category is
        # nearly always unintentional ("pmerge -C spork" without
        # realising there are sporks in more than one category), but
        # matching more than one cat/pkg is impossible without
        # explicit wildcards.
        installed = vdb.match(restriction)
        if not installed:
            fake_pkgs = fake_vdb.match(restriction)
            if fake_pkgs:
                fake.update(fake_pkgs)
            else:
                unknown.add(token)
            continue
        categories = set(pkg.category for pkg in installed)
        if len(categories) > 1:
            raise parserestrict.ParseError(
                "%r is in multiple categories (%s)" %
                (token, ', '.join(sorted(set(pkg.key for pkg in installed)))))
        matches.update(installed)

    # fail out if no matches are found, otherwise just output a notification
    if unknown:
        unknowns = ', '.join(map(repr, unknown))
        if matches:
            err.write(f"Skipping unknown matches: {unknowns}\n")
        else:
            raise Failure(f"no matches found: {unknowns}")

    if fake:
        err.write(
            'Skipping virtual pkg%s: %s' %
            (pluralism(fake_pkgs), ', '.join(f'{x.versioned_atom}::{x.repo_id}'
                                             for x in fake)))

    if matches:
        out.write(out.bold, 'The following packages are to be unmerged:')
        out.prefix = [out.bold, ' * ', out.reset]
        for pkg in matches:
            out.write(pkg.cpvstr)
        out.prefix = []

        repo_obs = observer.repo_observer(observer.formatter_output(out),
                                          debug=options.debug)

        if options.pretend:
            return

        if (options.ask and
                not formatter.ask("Would you like to unmerge these packages?")
            ):
            return
        return do_unmerge(options, out, err, vdb, matches, world_set, repo_obs)