[entropy.tools] remove unused functions

This commit is contained in:
Fabio Erculiani
2010-07-04 18:59:45 +02:00
parent fd3449d6ce
commit 5f09d66a1e
4 changed files with 23 additions and 201 deletions
+1 -3
View File
@@ -293,9 +293,7 @@ def enlightenatom(atom):
clean_atom = entropy.tools.remove_entropy_revision(atom)
clean_atom = entropy.tools.remove_tag(clean_atom)
only_cpv = entropy.tools.dep_getcpv(clean_atom)
operator = entropy.tools.get_operator(clean_atom)
if operator is None:
operator = ''
operator = clean_atom[:len(clean_atom)-len(only_cpv)]
cat, name, pv, rev = entropy.tools.catpkgsplit(only_cpv)
if rev == "r0":
rev = ''
+22 -173
View File
@@ -1399,159 +1399,14 @@ endversion_keys = ["pre", "p", "alpha", "beta", "rc"]
valid_category = re.compile("^\w[\w-]*")
invalid_atom_chars_regexp = re.compile("[()|@]")
def isjustpkgname(mypkg):
"""
docstring_title
@param mypkg:
@type mypkg:
@return:
@rtype:
"""
myparts = mypkg.split('-')
for x in myparts:
if ververify(x):
return 0
return 1
def ververify(myverx, silent = 1):
"""
docstring_title
@param myverx:
@type myverx:
@keyword silent:
@type silent:
@return:
@rtype:
"""
myver = myverx[:]
def _ververify(myver):
if myver.endswith("*"):
myver = myver[:-1]
if ver_regexp.match(myver):
return 1
m = ver_regexp.match(myver[:-1])
else:
if not silent:
print_generic("!!! syntax error in version: %s" % myver)
return 0
def isvalidatom(myatom, allow_blockers = True):
"""
Check to see if a depend atom is valid
Example usage:
>>> isvalidatom('media-libs/test-3.0')
0
>>> isvalidatom('>=media-libs/test-3.0')
1
@param atom: The depend atom to check against
@type atom: String
@rtype: Integer
@return: One of the following:
1) 0 if the atom is invalid
2) 1 if the atom is valid
"""
atom = remove_tag(myatom)
atom = remove_usedeps(atom)
if invalid_atom_chars_regexp.search(atom):
return 0
if allow_blockers and atom[:1] == "!":
if atom[1:2] == "!":
atom = atom[2:]
else:
atom = atom[1:]
# media-sound/amarok/x ?
if atom.count("/") > 1:
return 0
cpv = dep_getcpv(atom)
cpv_catsplit = catsplit(cpv)
mycpv_cps = None
if cpv:
if len(cpv_catsplit) == 2:
if valid_category.match(cpv_catsplit[0]) is None:
return 0
if cpv_catsplit[0] == "null":
# "null" category is valid, missing category is not.
mycpv_cps = catpkgsplit(cpv.replace("null/", "cat/", 1))
if mycpv_cps:
mycpv_cps = list(mycpv_cps)
mycpv_cps[0] = "null"
if not mycpv_cps:
mycpv_cps = catpkgsplit(cpv)
operator = get_operator(atom)
if operator:
if operator[0] in "<>" and remove_slot(atom).endswith("*"):
return 0
if mycpv_cps:
if len(cpv_catsplit) == 2:
# >=cat/pkg-1.0
return 1
else:
return 0
else:
# >=cat/pkg or >=pkg-1.0 (no category)
return 0
if mycpv_cps:
# cat/pkg-1.0
return 0
if len(cpv_catsplit) == 2:
# cat/pkg
return 1
return 0
def catsplit(mydep):
"""
docstring_title
@param mydep:
@type mydep:
@return:
@rtype:
"""
return mydep.split("/", 1)
def get_operator(mydep):
"""
Return the operator used in a depstring.
Example usage:
>>> from portage.dep import *
>>> get_operator(">=test-1.0")
'>='
@param mydep: The dep string to check
@type mydep: String
@rtype: String
@return: The operator. One of:
'~', '=', '>', '<', '=*', '>=', or '<='
"""
if mydep:
mydep = remove_slot(mydep)
if not mydep:
return None
if mydep[0] == "~":
operator = "~"
elif mydep[0] == "=":
if mydep[-1] == "*":
operator = "=*"
else:
operator = "="
elif mydep[0] in "><":
if len(mydep) > 1 and mydep[1] == "=":
operator = mydep[0:2]
else:
operator = mydep[0]
else:
operator = None
return operator
m = ver_regexp.match(myver)
if m:
return True
return False
def isjustname(mypkg):
"""
@@ -1567,28 +1422,24 @@ def isjustname(mypkg):
@param mypkg: The package atom to check
@param mypkg: String
@rtype: Integer
@return: One of the following:
1) 0 if the package string is not just the package name
2) 1 if it is
@rtype: int
@return: if the package string is not just the package name
"""
for chunk in mypkg.split('-'):
if _ververify(chunk):
return False
return True
myparts = mypkg.split('-')
for x in myparts:
if ververify(x):
return 0
return 1
def isspecific(mypkg):
def _isspecific(mypkg):
"""
Checks to see if a package is in category/package-version or package-version format,
possibly returning a cached result.
Example usage:
>>> isspecific('media-libs/test')
0
>>> isspecific('media-libs/test-3.0')
1
>>> _isspecific('media-libs/test')
False
>>> _isspecific('media-libs/test-3.0')
True
@param mypkg: The package depstring to check against
@type mypkg: String
@@ -1599,18 +1450,16 @@ def isspecific(mypkg):
"""
mysplit = mypkg.split("/")
if not isjustname(mysplit[-1]):
return 1
return 0
return True
return False
def catpkgsplit(mydata, silent = 1):
def catpkgsplit(mydata):
"""
Takes a Category/Package-Version-Rev and returns a list of each.
@param mydata: Data to split
@type mydata: string
@param silent: suppress error messages
@type silent: Boolean (integer)
@type mydata: string
@rype: tuple
@return:
1. If each exists, it returns (cat, pkgname, version, rev)
@@ -1675,7 +1524,7 @@ def dep_getkey(mydepx):
mydep = remove_usedeps(mydep)
mydep = dep_getcpv(mydep)
if mydep and isspecific(mydep):
if mydep and _isspecific(mydep):
mysplit = catpkgsplit(mydep)
if not mysplit:
return mydep
-22
View File
@@ -400,37 +400,15 @@ class ToolsTest(unittest.TestCase):
os.remove(tmp_path)
os.remove(sha_path)
def test_isjustpkgname(self):
self.assert_(et.isjustpkgname("foo"))
self.assert_(not et.isjustpkgname("app-misc/foo-1.2.3"))
def test_isvalidatom(self):
self.assert_(not et.isvalidatom('media-libs/test-3.0'))
self.assert_(et.isvalidatom('>=media-libs/test-3.0'))
def test_md5string(self):
mystring = "ciao"
out_str = et.md5string(mystring)
self.assertEqual(out_str, "6e6bc4e49dd477ebc98ef4046c067b5f")
def test_get_operator(self):
ops = {
'>=': "media-libs/foo",
'<': "media-libs/foo",
'<=': "media-libs/foo",
'~': "media-libs/foo",
}
for op, key in ops.items():
self.assertEqual(op, et.get_operator(op + key))
def test_isjustname(self):
self.assert_(not et.isjustname("app-foo/foo-1.2.3"))
self.assert_(et.isjustname("app-foo/foo"))
def test_isspecific(self):
self.assert_(et.isspecific("app-foo/foo-1.2.3"))
self.assert_(not et.isspecific("app-foo/foo"))
def test_catpkgsplit(self):
data = {
'app-foo/foo-1.2.3': ("app-foo", "foo", "1.2.3", "r0"),
-3
View File
@@ -246,9 +246,6 @@ def repositories(options):
def dep_check_cb(s):
if not entropy.tools.isvalidatom(s):
return False
input_params = [
('dep_type', ('combo', (_("Dependency type"), avail_dep_type_desc),),
pkg_dep_types_cb, False)