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.
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)
@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
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
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,[]]
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
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):
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):
# 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):
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)
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
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):
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 = (