From: Zac Medico Date: Sat, 22 Jul 2006 11:39:24 +0000 (-0000) Subject: Move best_match_to_list, match_from_list, and match_to_list from the core portage... X-Git-Tag: v2.1.1~150 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=29fdcf864826264868a8ef6db17865337ff9659f;p=portage.git Move best_match_to_list, match_from_list, and match_to_list from the core portage module to portage_dep. svn path=/main/trunk/; revision=3991 --- diff --git a/pym/portage.py b/pym/portage.py index ab52fda42..c46aea9f9 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -55,7 +55,8 @@ try: import getbinpkg import portage_dep from portage_dep import dep_getcpv, dep_getkey, get_operator, \ - isjustname, isspecific, isvalidatom + isjustname, isspecific, isvalidatom, \ + match_from_list, match_to_list, best_match_to_list # XXX: This needs to get cleaned up. import output @@ -3633,117 +3634,6 @@ class packagetree: populated=1 pass -def match_to_list(mypkg,mylist): - """(pkgname,list) - Searches list for entries that matches the package. - """ - matches=[] - for x in mylist: - if match_from_list(x,[mypkg]): - if x not in matches: - matches.append(x) - return matches - -def best_match_to_list(mypkg,mylist): - """(pkgname,list) - Returns the most specific entry (assumed to be the longest one) - that matches the package given. - """ - # XXX Assumption is wrong sometimes. - maxlen = 0 - bestm = None - for x in match_to_list(mypkg,mylist): - if len(x) > maxlen: - maxlen = len(x) - bestm = x - return bestm - -def match_from_list(mydep,candidate_list): - if mydep[0] == "!": - mydep = mydep[1:] - - mycpv = dep_getcpv(mydep) - mycpv_cps = catpkgsplit(mycpv) # Can be None if not specific - - if not mycpv_cps: - cat,pkg = catsplit(mycpv) - ver = None - rev = None - else: - cat,pkg,ver,rev = mycpv_cps - if mydep == mycpv: - raise KeyError, "Specific key requires an operator (%s) (try adding an '=')" % (mydep) - - if ver and rev: - operator = get_operator(mydep) - if not operator: - writemsg("!!! Invalid atom: %s\n" % mydep, noiselevel=-1) - return [] - else: - operator = None - - mylist = [] - - if operator is None: - for x in candidate_list: - xs = pkgsplit(x) - if xs is None: - if x != mycpv: - continue - elif xs[0] != mycpv: - continue - mylist.append(x) - - elif operator == "=": # Exact match - if mycpv in candidate_list: - mylist = [mycpv] - - elif operator == "=*": # glob match - # The old verion ignored _tag suffixes... This one doesn't. - for x in candidate_list: - if x[0:len(mycpv)] == mycpv: - mylist.append(x) - - elif operator == "~": # version, any revision, match - for x in candidate_list: - xs = catpkgsplit(x) - if xs[0:2] != mycpv_cps[0:2]: - continue - if xs[2] != ver: - continue - mylist.append(x) - - elif operator in [">", ">=", "<", "<="]: - for x in candidate_list: - try: - result = pkgcmp(pkgsplit(x), [cat+"/"+pkg,ver,rev]) - except SystemExit, e: - raise - except: - writemsg("\nInvalid package name: %s\n" % x, noiselevel=-1) - sys.exit(73) - if result is None: - continue - elif operator == ">": - if result > 0: - mylist.append(x) - elif operator == ">=": - if result >= 0: - mylist.append(x) - elif operator == "<": - if result < 0: - mylist.append(x) - elif operator == "<=": - if result <= 0: - mylist.append(x) - else: - raise KeyError, "Unknown operator: %s" % mydep - else: - raise KeyError, "Unknown operator: %s" % mydep - - - return mylist - class portagetree: def __init__(self, root="/", virtual=None, clone=None, settings=None): diff --git a/pym/portage_dep.py b/pym/portage_dep.py index 619caccb7..f5ea8e72d 100644 --- a/pym/portage_dep.py +++ b/pym/portage_dep.py @@ -20,7 +20,7 @@ import os,string,types,sys,copy import portage_exception -from portage_versions import catpkgsplit, ververify +from portage_versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify def strip_empty(myarr): for x in range(len(myarr)-1, -1, -1): @@ -259,3 +259,115 @@ def dep_getkey(mydep): return mysplit[0] + "/" + mysplit[1] else: return mydep + +def match_to_list(mypkg, mylist): + """(pkgname, list) + Searches list for entries that matches the package. + """ + matches = [] + for x in mylist: + if match_from_list(x, [mypkg]): + if x not in matches: + matches.append(x) + return matches + +def best_match_to_list(mypkg, mylist): + """(pkgname, list) + Returns the most specific entry (assumed to be the longest one) + that matches the package given. + """ + # XXX Assumption is wrong sometimes. + maxlen = 0 + bestm = None + for x in match_to_list(mypkg, mylist): + if len(x) > maxlen: + maxlen = len(x) + bestm = x + return bestm + +def match_from_list(mydep, candidate_list): + from portage_util import writemsg + if mydep[0] == "!": + mydep = mydep[1:] + + mycpv = dep_getcpv(mydep) + mycpv_cps = catpkgsplit(mycpv) # Can be None if not specific + + if not mycpv_cps: + cat, pkg = catsplit(mycpv) + ver = None + rev = None + else: + cat, pkg, ver, rev = mycpv_cps + if mydep == mycpv: + raise KeyError("Specific key requires an operator" + \ + " (%s) (try adding an '=')" % (mydep)) + + if ver and rev: + operator = get_operator(mydep) + if not operator: + writemsg("!!! Invalid atom: %s\n" % mydep, noiselevel=-1) + return [] + else: + operator = None + + mylist = [] + + if operator is None: + for x in candidate_list: + xs = pkgsplit(x) + if xs is None: + if x != mycpv: + continue + elif xs[0] != mycpv: + continue + mylist.append(x) + + elif operator == "=": # Exact match + if mycpv in candidate_list: + mylist = [mycpv] + + elif operator == "=*": # glob match + # The old verion ignored _tag suffixes... This one doesn't. + for x in candidate_list: + if x[0:len(mycpv)] == mycpv: + mylist.append(x) + + elif operator == "~": # version, any revision, match + for x in candidate_list: + xs = catpkgsplit(x) + if xs[0:2] != mycpv_cps[0:2]: + continue + if xs[2] != ver: + continue + mylist.append(x) + + elif operator in [">", ">=", "<", "<="]: + for x in candidate_list: + try: + result = pkgcmp(pkgsplit(x), [cat + "/" + pkg, ver, rev]) + except SystemExit: + raise + except: + writemsg("\nInvalid package name: %s\n" % x, noiselevel=-1) + raise + if result is None: + continue + elif operator == ">": + if result > 0: + mylist.append(x) + elif operator == ">=": + if result >= 0: + mylist.append(x) + elif operator == "<": + if result < 0: + mylist.append(x) + elif operator == "<=": + if result <= 0: + mylist.append(x) + else: + raise KeyError("Unknown operator: %s" % mydep) + else: + raise KeyError("Unknown operator: %s" % mydep) + + return mylist