Пример #1
0
def parse_maintainer(value):
    """
    Case insensitive Regex match on the combined 'name <email>' bit of
    metadata.xml's maintainer data.
    """
    return packages.PackageRestriction(
        'maintainers',
        values.AnyMatch(
            values.UnicodeConversion(
                values.StrRegex(value.lower(), case_sensitive=False))))
Пример #2
0
def parse_maintainer_name(value):
    """
    Case insensitive Regex match on the name bit of metadata.xml's
    maintainer data.
    """
    return packages.PackageRestriction(
        'maintainers',
        values.AnyMatch(
            values.GetAttrRestriction(
                'name', values.StrRegex(value.lower(), case_sensitive=False))))
Пример #3
0
 def test_basic(self):
     for negate in (False, True):
         inst = values.FlatteningRestriction(
             tuple, values.AnyMatch(values.EqualityMatch(None)),
             negate=negate)
         self.assertEqual(not negate, inst.match([7, 8, [9, None]]))
         self.assertEqual(negate, inst.match([7, 8, (9, None)]))
         # Just check this does not raise
         self.assertTrue(str(inst))
         self.assertTrue(repr(inst))
Пример #4
0
def parse_ownsre(value):
    """Value is a regexp matched against the string form of an fs object.

    This means the object kind is prepended to the path the regexp has
    to match.
    """
    return packages.PackageRestriction(
        'contents',
        values.AnyMatch(
            values.GetAttrRestriction('location', values.StrRegex(value))))
Пример #5
0
    def check_args(cls, parser, namespace):
        if namespace.commits:
            if namespace.targets:
                targets = ' '.join(namespace.targets)
                s = pluralism(namespace.targets)
                parser.error(
                    f'--commits is mutually exclusive with target{s}: {targets}'
                )

            ref = namespace.commits
            repo = namespace.target_repo
            targets = list(repo.category_dirs)
            if os.path.isdir(pjoin(repo.location, 'eclass')):
                targets.append('eclass')
            try:
                p = subprocess.run(
                    ['git', 'diff', '--cached', ref, '--name-only'] + targets,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    cwd=repo.location,
                    encoding='utf8')
            except FileNotFoundError:
                parser.error(
                    'git not available to determine targets for --commits')

            if p.returncode != 0:
                error = p.stderr.splitlines()[0]
                parser.error(f'failed running git: {error}')
            elif not p.stdout:
                # no changes exist, exit early
                parser.exit()

            pkgs, eclasses = partition(
                p.stdout.splitlines(),
                predicate=lambda x: x.startswith('eclass/'))
            pkgs = sorted(cls._pkg_atoms(pkgs))
            eclasses = filter(None, (eclass_regex.match(x) for x in eclasses))
            eclasses = sorted(x.group('eclass') for x in eclasses)

            restrictions = []
            if pkgs:
                restrict = packages.OrRestriction(*pkgs)
                restrictions.append((base.package_scope, restrict))
            if eclasses:
                func = partial(cls._committed_eclass, frozenset(eclasses))
                restrict = values.AnyMatch(values.FunctionRestriction(func))
                restrictions.append((base.eclass_scope, restrict))

            # no pkgs or eclasses to check, exit early
            if not restrictions:
                parser.exit()

            namespace.contexts.append(GitStash(parser, repo))
            namespace.restrictions = restrictions
Пример #6
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 argparser.error(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 ('bdepend', 'depend', 'rdepend', 'pdepend')))
Пример #7
0
def revdep_pkgs_finalize(sequence, namespace):
    if not sequence:
        return []
    l = []
    for atom_inst in sequence:
        for repo in namespace.repos:
            l.extend(repo.itermatch(atom_inst))
    # have our pkgs; now build the restrict.
    any_restrict = values.AnyMatch(
        values.FunctionRestriction(partial(_revdep_pkgs_match, tuple(l))))
    r = values.FlatteningRestriction(atom.atom, any_restrict)
    return list(
        packages.PackageRestriction(dep, r)
        for dep in ('bdepend', 'depend', 'rdepend', 'pdepend'))
Пример #8
0
def parse_maintainer(value):
    """
    Case insensitive Regex match on the combined 'name <email>' bit of
    metadata.xml's maintainer data.
    """
    if value:
        return packages.PackageRestriction(
            'maintainers',
            values.AnyMatch(
                values.UnicodeConversion(
                    values.StrRegex(value.lower(), case_sensitive=False))))
    else:
        # empty string matches packages without a maintainer
        return packages.PackageRestriction('maintainers',
                                           values.EqualityMatch(()))
Пример #9
0
def parse_envmatch(value):
    """Apply a regexp to the environment."""
    return packages.PackageRestriction(
        'environment',
        DataSourceRestriction(values.AnyMatch(values.StrRegex(value))))
Пример #10
0
def parse_owns(value):
    return packages.PackageRestriction(
        'contents',
        values.AnyMatch(
            values.GetAttrRestriction('location',
                                      values.StrExactMatch(value))))
Пример #11
0
 def test_force(self):
     restrict = values.AnyMatch(values.AlwaysTrue)
     assert restrict.force_True(None, None, list(range(2)))
     assert not restrict.force_False(None, None, list(range(2)))
Пример #12
0
 def test_force(self):
     restrict = values.AnyMatch(values.AlwaysTrue)
     self.assertTrue(restrict.force_True(None, None, range(2)))
     self.assertFalse(restrict.force_False(None, None, range(2)))