diff options
author | Sebastian Luther <SebastianLuther@gmx.de> | 2010-08-15 01:24:24 +0200 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-14 16:31:28 -0700 |
commit | 249631f872e854a379319e5c6d5f871830c80860 (patch) | |
tree | 70c599ab8fc2ef2a00f39831c8ee010f4a3c518e /pym/portage | |
parent | 724421343eb64987e054c255527e40be73162a83 (diff) | |
download | portage-249631f872e854a379319e5c6d5f871830c80860.tar.gz portage-249631f872e854a379319e5c6d5f871830c80860.tar.bz2 portage-249631f872e854a379319e5c6d5f871830c80860.zip |
portage.dep: Integrate the functionality of flatten into use_reduce
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/dbapi/porttree.py | 3 | ||||
-rw-r--r-- | pym/portage/dbapi/vartree.py | 4 | ||||
-rw-r--r-- | pym/portage/dep/__init__.py | 33 | ||||
-rw-r--r-- | pym/portage/package/ebuild/config.py | 36 | ||||
-rw-r--r-- | pym/portage/tests/dep/testStandalone.py | 16 | ||||
-rw-r--r-- | pym/portage/tests/dep/test_use_reduce.py | 90 |
6 files changed, 140 insertions, 42 deletions
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 4b266b48b..a8866794c 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -10,7 +10,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.checksum', 'portage.data:portage_gid,secpass', 'portage.dbapi.dep_expand:dep_expand', - 'portage.dep:dep_getkey,flatten,match_from_list,use_reduce', + 'portage.dep:dep_getkey,match_from_list,use_reduce', 'portage.env.loaders:KeyValuePairFileLoader', 'portage.package.ebuild.doebuild:doebuild', 'portage.util:ensure_dirs,shlex_split,writemsg,writemsg_level', @@ -658,7 +658,6 @@ class portdbapi(dbapi): myuris = use_reduce(myuris, uselist=useflags, matchall=(useflags is None), \ is_src_uri=True, allow_src_uri_file_renames=eapi_has_src_uri_arrows(eapi)) - myuris = flatten(myuris) uri_map = OrderedDict() diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 6f587f7b4..ccb48dc76 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -10,7 +10,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.checksum:_perform_md5_merge@perform_md5', 'portage.data:portage_gid,portage_uid,secpass', 'portage.dbapi.dep_expand:dep_expand', - 'portage.dep:dep_getkey,isjustname,flatten,match_from_list,' + \ + 'portage.dep:dep_getkey,isjustname,match_from_list,' + \ 'use_reduce,_slot_re', 'portage.elog:elog_process', 'portage.locks:lockdir,unlockdir', @@ -1795,7 +1795,7 @@ class vartree(object): mylines, myuse = self.dbapi.aux_get(mycpv, ["PROVIDE", "USE"]) if mylines: myuse = myuse.split() - mylines = flatten(use_reduce(mylines, uselist=myuse)) + mylines = use_reduce(mylines, uselist=myuse, flat=True) for myprovide in mylines: mys = catpkgsplit(myprovide) if not mys: diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 82c0c4e71..4b6c2d0b0 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -221,7 +221,7 @@ def paren_enclose(mylist): return " ".join(mystrparts) def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], is_src_uri=False, \ - allow_src_uri_file_renames=False, opconvert=False): + allow_src_uri_file_renames=False, opconvert=False, flat=False): """ Takes a dep string and reduces the use? conditionals out, leaving an array with subarrays. All redundant brackets are removed. @@ -234,8 +234,16 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i @type masklist: List @param matchall: Treat all conditionals as active. Used by repoman. @type matchall: Bool - @param matchall: List of flags for which negated conditionals are always treated as inactive. - @type matchall: List + @param excludeall: List of flags for which negated conditionals are always treated as inactive. + @type excludeall: List + @param is_src_uri: Indicates if depstr represents a SRC_URI + @type is_src_uri: Bool + @param allow_src_uri_file_renames: Indicates if EAPI-2 SRC_URI arrows are allowed when parsing a SRC_URI + @type allow_src_uri_file_renames: Bool + @param opconvert: Put every operator as first element into it's argument list + @type opconvert: Bool + @param flat: Create a flat list of all tokens + @type flat: Bool @rtype: List @return: The use reduced depend array """ @@ -244,7 +252,10 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i "Pass the original dep string instead.") % \ ('portage.dep.use_reduce',), DeprecationWarning, stacklevel=2) depstr = paren_enclose(depstr) - + + if opconvert and flat: + raise ValueError("portage.dep.use_reduce: 'opconvert' and 'flat' are mutually exclusive") + def is_active(conditional): if conditional.startswith("!"): flag = conditional[1:-1] @@ -292,6 +303,17 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i l = stack.pop() ignore = False + if flat: + if stack[level] and stack[level][-1][-1] == "?": + if is_active(stack[level][-1]): + stack[level].pop() + stack[level].extend(l) + else: + stack[level].pop() + else: + stack[level].extend(l) + continue + if stack[level]: if stack[level][-1] == "||" and not l: stack[level].pop() @@ -406,6 +428,9 @@ def flatten(mylist): @rtype: List @return: A single list containing only non-list elements. """ + warnings.warn(_("%s is deprecated and will be removed without replacement.") % \ + ('portage.dep.flatten',), DeprecationWarning, stacklevel=2) + newlist = [] for x in mylist: if isinstance(x, list): diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 081bad3f4..20b3186ec 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -32,7 +32,7 @@ from portage.dbapi import dbapi from portage.dbapi.porttree import portdbapi from portage.dbapi.vartree import vartree from portage.dep import Atom, best_match_to_list, \ - flatten, isvalidatom, match_from_list, match_to_list, \ + isvalidatom, match_from_list, match_to_list, \ remove_slot, use_reduce from portage.eapi import eapi_exports_AA, eapi_supports_prefix, eapi_exports_replace_vars from portage.env.loaders import KeyValuePairFileLoader @@ -1278,7 +1278,7 @@ class config(object): E2BIG errors as in bug #262647. """ try: - licenses = set(flatten(use_reduce(settings['LICENSE'],uselist=use))) + licenses = set(use_reduce(settings['LICENSE'], uselist=use, flat=True)) except InvalidDependString: licenses = set() licenses.discard('||') @@ -1303,7 +1303,7 @@ class config(object): def _restrict(self, use, settings): try: - restrict = set(flatten(use_reduce(settings['RESTRICT'],uselist=use))) + restrict = set(use_reduce(settings['RESTRICT'], uselist=use, flat=True)) except InvalidDependString: restrict = set() return ' '.join(sorted(restrict)) @@ -1917,7 +1917,7 @@ class config(object): """ - licenses = set(flatten(use_reduce(metadata["LICENSE"], matchall=1))) + licenses = set(use_reduce(metadata["LICENSE"], matchall=1, flat=True)) licenses.discard('||') acceptable_licenses = set() @@ -1948,17 +1948,17 @@ class config(object): for element in license_struct[1:]: if isinstance(element, list): if element: - ret.append(self._getMaskedLicenses( - element, acceptable_licenses)) - if not ret[-1]: + tmp = self._getMaskedLicenses(element, acceptable_licenses) + if not tmp: return [] + ret.extend(tmp) else: if element in acceptable_licenses: return [] ret.append(element) # Return all masked licenses, since we don't know which combination # (if any) the user will decide to unmask. - return flatten(ret) + return ret ret = [] for element in license_struct: @@ -2006,7 +2006,7 @@ class config(object): for x in pproperties_list: accept_properties.extend(x) - properties = set(flatten(use_reduce(metadata["PROPERTIES"], matchall=1))) + properties = set(use_reduce(metadata["PROPERTIES"], matchall=1, flat=True)) properties.discard('||') acceptable_properties = set() @@ -2037,17 +2037,18 @@ class config(object): for element in properties_struct[1:]: if isinstance(element, list): if element: - ret.append(self._getMaskedProperties( - element, acceptable_properties)) - if not ret[-1]: + tmp = self._getMaskedProperties( + element, acceptable_properties) + if not tmp: return [] + ret.extend(tmp) else: if element in acceptable_properties: return[] ret.append(element) # Return all masked properties, since we don't know which combination # (if any) the user will decide to unmask - return flatten(ret) + return ret ret = [] for element in properties_struct: @@ -2117,7 +2118,7 @@ class config(object): myuse = mydbapi["USE"] else: myuse = mydbapi.aux_get(mycpv, ["USE"])[0] - virts = flatten(use_reduce(provides, uselist=myuse.split())) + virts = use_reduce(provides, uselist=myuse.split(), flat=True) modified = False cp = Atom(cpv_getkey(mycpv)) @@ -2681,8 +2682,11 @@ class config(object): return self._thirdpartymirrors def archlist(self): - return flatten([[myarch, "~" + myarch] \ - for myarch in self["PORTAGE_ARCHLIST"].split()]) + _archlist = [] + for myarch in self["PORTAGE_ARCHLIST"].split(): + _archlist.append(myarch) + _archlist.append("~" + myarch) + return _archlist def selinux_enabled(self): if getattr(self, "_selinux_enabled", None) is None: diff --git a/pym/portage/tests/dep/testStandalone.py b/pym/portage/tests/dep/testStandalone.py index a5d661cc3..e9f01df03 100644 --- a/pym/portage/tests/dep/testStandalone.py +++ b/pym/portage/tests/dep/testStandalone.py @@ -2,7 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 from portage.tests import TestCase -from portage.dep import cpvequal, flatten +from portage.dep import cpvequal from portage.exception import PortageException class TestStandalone(TestCase): @@ -34,17 +34,3 @@ class TestStandalone(TestCase): for cpv1, cpv2 in test_cases_xfail: self.assertRaisesMsg("cpvequal("+cpv1+", "+cpv2+")", \ PortageException, cpvequal, cpv1, cpv2) - - - def testFlattenl(self): - - test_cases = ( - ( [], [] ), - ( [[]], [] ), - ( [[], 1], [1] ), - ( [1, [2, 3, [4]]], [1, 2, 3, 4] ), - ( [1, [2], 3, [4]], [1, 2, 3, 4] ), - ) - - for not_flat, flat in test_cases: - self.assertEqual(flatten(not_flat), flat) diff --git a/pym/portage/tests/dep/test_use_reduce.py b/pym/portage/tests/dep/test_use_reduce.py index e952e93d0..d95663663 100644 --- a/pym/portage/tests/dep/test_use_reduce.py +++ b/pym/portage/tests/dep/test_use_reduce.py @@ -8,7 +8,7 @@ from portage.dep import use_reduce class UseReduceTestCase(object): def __init__(self, deparray, uselist=[], masklist=[], \ matchall=0, excludeall=[], is_src_uri=False, \ - allow_src_uri_file_renames=False, opconvert=False, expected_result=None): + allow_src_uri_file_renames=False, opconvert=False, flat=False, expected_result=None): self.deparray = deparray self.uselist = uselist self.masklist = masklist @@ -17,11 +17,13 @@ class UseReduceTestCase(object): self.is_src_uri = is_src_uri self.allow_src_uri_file_renames = allow_src_uri_file_renames self.opconvert = opconvert + self.flat = flat self.expected_result = expected_result def run(self): return use_reduce(self.deparray, self.uselist, self.masklist, \ - self.matchall, self.excludeall, self.is_src_uri, self.allow_src_uri_file_renames, self.opconvert) + self.matchall, self.excludeall, self.is_src_uri, self.allow_src_uri_file_renames, \ + self.opconvert, self.flat) class UseReduce(TestCase): @@ -318,6 +320,83 @@ class UseReduce(TestCase): uselist = ["foo"], opconvert = True, expected_result = ["A", "B"]), + + #flat test + UseReduceTestCase( + "A", + flat = True, + expected_result = ["A"]), + UseReduceTestCase( + "( A )", + flat = True, + expected_result = ["A"]), + UseReduceTestCase( + "|| ( A B )", + flat = True, + expected_result = [ "||", "A", "B" ] ), + UseReduceTestCase( + "|| ( A || ( B C ) )", + flat = True, + expected_result = [ "||", "A", "||", "B", "C" ]), + UseReduceTestCase( + "|| ( A || ( B C D ) )", + flat = True, + expected_result = [ "||", "A", "||", "B", "C", "D" ]), + UseReduceTestCase( + "|| ( A || ( B || ( C D ) E ) )", + flat = True, + expected_result = [ "||", "A", "||", "B", "||", "C", "D", "E" ]), + UseReduceTestCase( + "( || ( ( ( A ) B ) ) )", + flat = True, + expected_result = [ "||", "A", "B"] ), + UseReduceTestCase( + "( || ( || ( ( A ) B ) ) )", + flat = True, + expected_result = [ "||", "||", "A", "B" ]), + UseReduceTestCase( + "( || ( || ( ( A ) B ) ) )", + flat = True, + expected_result = [ "||", "||", "A", "B" ]), + UseReduceTestCase( + "|| ( A )", + flat = True, + expected_result = ["||", "A"]), + UseReduceTestCase( + "( || ( || ( || ( A ) foo? ( B ) ) ) )", + expected_result = ["A"]), + UseReduceTestCase( + "( || ( || ( || ( A ) foo? ( B ) ) ) )", + uselist = ["foo"], + flat = True, + expected_result = [ "||", "||","||", "A", "B" ]), + UseReduceTestCase( + "( || ( || ( bar? ( A ) || ( foo? ( B ) ) ) ) )", + flat = True, + expected_result = ["||", "||","||"]), + UseReduceTestCase( + "( || ( || ( bar? ( A ) || ( foo? ( B ) ) ) ) )", + uselist = ["foo", "bar"], + flat = True, + expected_result = [ "||", "||", "A", "||", "B" ]), + UseReduceTestCase( + "A || ( ) foo? ( ) B", + flat = True, + expected_result = ["A", "||", "B"]), + UseReduceTestCase( + "|| ( A ) || ( B )", + flat = True, + expected_result = ["||", "A", "||", "B"]), + UseReduceTestCase( + "foo? ( A ) foo? ( B )", + flat = True, + expected_result = []), + UseReduceTestCase( + "foo? ( A ) foo? ( B )", + uselist = ["foo"], + flat = True, + expected_result = ["A", "B"]), + ) test_cases_xfail = ( @@ -348,10 +427,15 @@ class UseReduce(TestCase): UseReduceTestCase("http://foo/bar -> foo? ( http://foo.com/foo )", is_src_uri = True, allow_src_uri_file_renames = True), UseReduceTestCase("foo? ( http://foo/bar -> ) blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = True), UseReduceTestCase("http://foo/bar -> foo/blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = True), + + UseReduceTestCase( + "A", + opconvert = True, + flat = True), ) for test_case in test_cases: self.assertEqual(test_case.run(), test_case.expected_result) for test_case in test_cases_xfail: - self.assertRaisesMsg(test_case.deparray, InvalidDependString, test_case.run) + self.assertRaisesMsg(test_case.deparray, (InvalidDependString, ValueError), test_case.run) |