portage.dep: Integrate the functionality of dep_opconvert into use_reduce
authorSebastian Luther <SebastianLuther@gmx.de>
Sat, 14 Aug 2010 14:34:25 +0000 (16:34 +0200)
committerZac Medico <zmedico@gentoo.org>
Sat, 14 Aug 2010 14:40:51 +0000 (07:40 -0700)
pym/portage/dep/__init__.py
pym/portage/dep/dep_check.py
pym/portage/package/ebuild/config.py
pym/portage/tests/dep/testStandalone.py
pym/portage/tests/dep/test_use_reduce.py

index 9e4242edf3802027b97fd70e9893ee34d9826d9f..82c0c4e718f8db341feb172bbd60f03c68e98f54 100644 (file)
@@ -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):
+       allow_src_uri_file_renames=False, opconvert=False):
        """
        Takes a dep string and reduces the use? conditionals out, leaving an array
        with subarrays. All redundant brackets are removed.
@@ -313,7 +313,11 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
                                                stack[level].pop()
                                                stack[level].extend(l)
                                        else:
-                                               stack[level].append(l)
+                                               if opconvert and stack[level] and stack[level][-1] == "||":
+                                                       stack[level].pop()
+                                                       stack[level].append(["||"] + l)
+                                               else:
+                                                       stack[level].append(l)
                        else:
                                raise portage.exception.InvalidDependString(
                                        _("malformed syntax: '%s'") % depstr)
@@ -372,6 +376,8 @@ def dep_opconvert(deplist):
        @return:
                The new list with the new ordering
        """
+       warnings.warn(_("%s is deprecated. Use %s with the opconvert parameter set to True instead.") % \
+               ('portage.dep.dep_opconvert', 'portage.dep.use_reduce'), DeprecationWarning, stacklevel=2)
 
        retlist = []
        x = 0
index 28d5771a7e7afb303359403ee5e422d56c7d5c31..74e14882b0d6c3fd72ecdfec221e572e9493c6f7 100644 (file)
@@ -6,7 +6,7 @@ __all__ = ['dep_check', 'dep_eval', 'dep_wordreduce', 'dep_zapdeps']
 import logging
 
 import portage
-from portage.dep import Atom, dep_opconvert, match_from_list, \
+from portage.dep import Atom, match_from_list, \
        remove_slot, use_reduce
 from portage.eapi import eapi_has_strong_blocks, eapi_has_use_deps, eapi_has_slot_deps, \
        eapi_has_use_dep_defaults
@@ -543,13 +543,10 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None,
                useforce.difference_update(mymasks)
        try:
                mysplit = use_reduce(depstring, uselist=myusesplit,
-                       masklist=mymasks, matchall=(use=="all"), excludeall=useforce)
+                       masklist=mymasks, matchall=(use=="all"), excludeall=useforce, opconvert=True)
        except InvalidDependString as e:
                return [0, str(e)]
 
-       # Do the || conversions
-       mysplit = dep_opconvert(mysplit)
-
        if mysplit == []:
                #dependencies were reduced to nothing
                return [1,[]]
index 3b8ee10b54bf0113ff82db2a9a666772597ba370..495e3d1b84f301fb81169777ce320f57fef34132 100644 (file)
@@ -31,7 +31,7 @@ from portage.const import CACHE_PATH, CUSTOM_PROFILE_PATH, \
 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, dep_opconvert, \
+from portage.dep import Atom, best_match_to_list, \
        flatten, 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
@@ -1926,8 +1926,7 @@ class config(object):
                else:
                        use = []
 
-               license_struct = use_reduce(license_str, uselist=use)
-               license_struct = dep_opconvert(license_struct)
+               license_struct = use_reduce(license_str, uselist=use, opconvert=True)
                return self._getMaskedLicenses(license_struct, acceptable_licenses)
 
        def _getMaskedLicenses(self, license_struct, acceptable_licenses):
@@ -2016,8 +2015,7 @@ class config(object):
                else:
                        use = []
 
-               properties_struct = use_reduce(properties_str, uselist=use)
-               properties_struct = dep_opconvert(properties_struct)
+               properties_struct = use_reduce(properties_str, uselist=use, opconvert=True)
                return self._getMaskedProperties(properties_struct, acceptable_properties)
 
        def _getMaskedProperties(self, properties_struct, acceptable_properties):
index f018902e59092032df49b3dc7831455d9cd6b122..a5d661cc32318055548f1bf30dd8b731685a29e7 100644 (file)
@@ -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, dep_opconvert, flatten
+from portage.dep import cpvequal, flatten
 from portage.exception import PortageException
 
 class TestStandalone(TestCase):
@@ -48,15 +48,3 @@ class TestStandalone(TestCase):
 
                for not_flat, flat in test_cases:
                        self.assertEqual(flatten(not_flat), flat)
-
-       def testDep_opconvert(self):
-
-               test_cases = (
-                       ( [], [] ),
-                       ( ["blah", "||", ["foo", "bar", "baz"]], ["blah", ["||", "foo", "bar", "baz"]] ),
-                       ( [["a", "b"], "||", ["c", "d", "e"]], [["a", "b"], ["||", "c", "d", "e"]] ),
-                       ( ["||", ["a", "b"], "||", ["c", "d", "e"]], [["||", "a", "b"], ["||", "c", "d", "e"]] ),
-               )
-
-               for orig, expected in test_cases:
-                       self.assertEqual(dep_opconvert(orig), expected)
index ed77c40a3493853b40c673d2243aa05c9f3ac6df..e952e93d05bcf4a47f18d4a3dd05f4f53999aa95 100644 (file)
@@ -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, expected_result=None):
+               allow_src_uri_file_renames=False, opconvert=False, expected_result=None):
                self.deparray = deparray
                self.uselist = uselist
                self.masklist = masklist
@@ -16,11 +16,12 @@ class UseReduceTestCase(object):
                self.excludeall = excludeall
                self.is_src_uri = is_src_uri
                self.allow_src_uri_file_renames = allow_src_uri_file_renames
+               self.opconvert = opconvert
                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.matchall, self.excludeall, self.is_src_uri, self.allow_src_uri_file_renames, self.opconvert)
                                
 class UseReduce(TestCase):
 
@@ -242,6 +243,81 @@ class UseReduce(TestCase):
                                is_src_uri = True,
                                allow_src_uri_file_renames = True,
                                expected_result = ["http://foo.com/foo", "http://foo/bar", "->", "blah.tbz2"]),
+
+                       #opconvert tests
+                       UseReduceTestCase(
+                               "A",
+                               opconvert = True,
+                               expected_result = ["A"]),
+                       UseReduceTestCase(
+                               "( A )",
+                               opconvert = True,
+                               expected_result = ["A"]),
+                       UseReduceTestCase(
+                               "|| ( A B )",
+                               opconvert = True,
+                               expected_result = [ ["||", "A", "B"] ]),
+                       UseReduceTestCase(
+                               "|| ( A || ( B C ) )",
+                               opconvert = True,
+                               expected_result = [ ["||", "A", ["||", "B", "C"]] ]),
+                       UseReduceTestCase(
+                               "|| ( A || ( B C D ) )",
+                               opconvert = True,
+                               expected_result = [ ["||", "A", ["||", "B", "C", "D"]] ]),
+                       UseReduceTestCase(
+                               "|| ( A || ( B || ( C D ) E ) )",
+                               expected_result = [ "||", ["A", "||", ["B", "||", ["C", "D"], "E"]] ]),
+                       UseReduceTestCase(
+                               "( || ( ( ( A ) B ) ) )",
+                               opconvert = True,
+                               expected_result = [ ["||", "A", "B"] ] ),
+                       UseReduceTestCase(
+                               "( || ( || ( ( A ) B ) ) )",
+                               opconvert = True,
+                               expected_result = [ ["||", "A", "B"] ]),
+                       UseReduceTestCase(
+                               "( || ( || ( ( A ) B ) ) )",
+                               opconvert = True,
+                               expected_result = [ ["||", "A", "B"] ]),
+                       UseReduceTestCase(
+                               "|| ( A )",
+                               opconvert = True,
+                               expected_result = ["A"]),
+                       UseReduceTestCase(
+                               "( || ( || ( || ( A ) foo? ( B ) ) ) )",
+                               expected_result = ["A"]),
+                       UseReduceTestCase(
+                               "( || ( || ( || ( A ) foo? ( B ) ) ) )",
+                               uselist = ["foo"],
+                               opconvert = True,
+                               expected_result = [ ["||", "A", "B"] ]),
+                       UseReduceTestCase(
+                               "( || ( || ( bar? ( A ) || ( foo? ( B ) ) ) ) )",
+                               opconvert = True,
+                               expected_result = []),
+                       UseReduceTestCase(
+                               "( || ( || ( bar? ( A ) || ( foo? ( B ) ) ) ) )",
+                               uselist = ["foo", "bar"],
+                               opconvert = True,
+                               expected_result = [ ["||", "A", "B"] ]),
+                       UseReduceTestCase(
+                               "A || ( ) foo? ( ) B",
+                               opconvert = True,
+                               expected_result = ["A", "B"]),
+                       UseReduceTestCase(
+                               "|| ( A ) || ( B )",
+                               opconvert = True,
+                               expected_result = ["A", "B"]),
+                       UseReduceTestCase(
+                               "foo? ( A ) foo? ( B )",
+                               opconvert = True,
+                               expected_result = []),
+                       UseReduceTestCase(
+                               "foo? ( A ) foo? ( B )",
+                               uselist = ["foo"],
+                               opconvert = True,
+                               expected_result = ["A", "B"]),
                )
                
                test_cases_xfail = (