diff options
author | 2015-02-21 04:25:27 -0500 | |
---|---|---|
committer | 2015-02-21 04:28:29 -0500 | |
commit | 136daae639a51124c0d51963a0627c21b8df2e6b (patch) | |
tree | 737d85b47e1806b58dfd96b58f2613c8fc38fa96 | |
parent | pmerge: use more readable variants of restrictions for error messages (diff) | |
download | pkgcore-136daae639a51124c0d51963a0627c21b8df2e6b.tar.gz pkgcore-136daae639a51124c0d51963a0627c21b8df2e6b.tar.bz2 pkgcore-136daae639a51124c0d51963a0627c21b8df2e6b.zip |
pmerge: rename parse_atom() to parse_target() and update related docs
To make it more obvious that it doesn't return a single atom anymore in
certain cases.
-rw-r--r-- | pkgcore/scripts/pmerge.py | 12 | ||||
-rw-r--r-- | pkgcore/test/scripts/test_pmerge.py | 16 |
2 files changed, 14 insertions, 14 deletions
diff --git a/pkgcore/scripts/pmerge.py b/pkgcore/scripts/pmerge.py index ad898c3c..d18793d9 100644 --- a/pkgcore/scripts/pmerge.py +++ b/pkgcore/scripts/pmerge.py @@ -356,8 +356,8 @@ def _validate(parser, namespace): namespace.targets = f(namespace.targets) -def parse_atom(restriction, repo, livefs_repos, return_none=False): - """Use :obj:`parserestrict.parse_match` to produce a single atom. +def parse_target(restriction, repo, livefs_repos, return_none=False): + """Use :obj:`parserestrict.parse_match` to produce a list of matches. This matches the restriction against a repo. If multiple pkgs match and a simple package name was provided, then the restriction is applied against @@ -371,7 +371,7 @@ def parse_atom(restriction, repo, livefs_repos, return_none=False): :param livefs_repos: :obj:`pkgcore.config.domain.all_livefs_repos` instance to search in. :param return_none: indicates if no matches raises or returns C{None} - :return: an atom or C{None}. + :return: a list of matches or C{None}. """ key_matches = set(x.key for x in repo.itermatch(restriction)) if not key_matches: @@ -461,11 +461,11 @@ def main(options, out, err): atoms = [] for token in options.targets: try: - a = parse_atom(token, source_repos.combined, livefs_repos, return_none=True) + matches = parse_target(token, source_repos.combined, livefs_repos, return_none=True) except parserestrict.ParseError as e: out.error(str(e)) return 1 - if a is None: + if matches is None: if token in config.pkgset: out.error( 'No package matches %s, but there is a set with ' @@ -476,7 +476,7 @@ def main(options, out, err): else: return -1 else: - atoms.extend(a) + atoms.extend(matches) if not atoms and not options.newuse: out.error('No targets specified; nothing to do') diff --git a/pkgcore/test/scripts/test_pmerge.py b/pkgcore/test/scripts/test_pmerge.py index ca5cc427..38f48d14 100644 --- a/pkgcore/test/scripts/test_pmerge.py +++ b/pkgcore/test/scripts/test_pmerge.py @@ -16,17 +16,17 @@ default_formatter = basics.HardCodedConfigSection({ class AtomParsingTest(TestCase): - def test_parse_atom(self): + def test_parse_target(self): repo = util.SimpleTree({'spork': {'foon': ('1', '1.0.1', '2')}}) livefs_repos = util.SimpleTree({'foo': {'bar': ('1')}}) for cat in ('', 'spork/'): - a = pmerge.parse_atom(parse_match('=%sfoon-1' % (cat,)), repo, livefs_repos) + a = pmerge.parse_target(parse_match('=%sfoon-1' % (cat,)), repo, livefs_repos) self.assertEqual(len(a), 1) self.assertEqual(a[0].key, 'spork/foon') self.assertEqual( [x.fullver for x in repo.itermatch(a[0])], ['1']) - a = pmerge.parse_atom(parse_match('%sfoon' % (cat,)), repo, livefs_repos) + a = pmerge.parse_target(parse_match('%sfoon' % (cat,)), repo, livefs_repos) self.assertEqual(len(a), 1) self.assertEqual(a[0].key, 'spork/foon') self.assertEqual( @@ -38,24 +38,24 @@ class AtomParsingTest(TestCase): 'spork2': {'foon': ('2',)}}) self.assertRaises( pmerge.NoMatches, - pmerge.parse_atom, parse_match("foo"), repo, livefs_repos) + pmerge.parse_target, parse_match("foo"), repo, livefs_repos) self.assertRaises( pmerge.AmbiguousQuery, - pmerge.parse_atom, parse_match("foon"), repo, livefs_repos) + pmerge.parse_target, parse_match("foon"), repo, livefs_repos) # test unicode conversion. - a = pmerge.parse_atom(parse_match(u'=spork/foon-1'), repo, livefs_repos) + a = pmerge.parse_target(parse_match(u'=spork/foon-1'), repo, livefs_repos) self.assertEqual(len(a), 1) self.assertEqual(a[0].key, 'spork/foon') self.assertTrue(isinstance(a[0].key, str)) # test globbing - a = pmerge.parse_atom(parse_match(u'*/foon'), repo, livefs_repos) + a = pmerge.parse_target(parse_match(u'*/foon'), repo, livefs_repos) self.assertEqual(len(a), 2) # test pkg name collisions between real and virtual pkgs on livefs # repos, the real pkg will be selected over the virtual livefs_repos = util.SimpleTree({'foo': {'bar': ('1')}, 'virtual': {'bar': ('0')}}) repo = util.SimpleTree({'foo': {'bar': ('1',)}, 'virtual': {'bar': ('1',)}}) - a = pmerge.parse_atom(parse_match("bar"), repo, livefs_repos) + a = pmerge.parse_target(parse_match("bar"), repo, livefs_repos) self.assertEqual(len(a), 1) self.assertEqual(a[0].key, 'foo/bar') self.assertTrue(isinstance(a[0].key, str)) |