From 4c9b95eccf910b4b7530e2607e417508fb804e47 Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Thu, 1 Feb 2007 05:25:09 +0000 Subject: [PATCH] Round one of dep_getusedeps() svn path=/main/trunk/; revision=5855 --- pym/portage/dep.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pym/portage/dep.py b/pym/portage/dep.py index 230080b60..d194f3d12 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -20,7 +20,7 @@ import re, sys, types import portage.exception -from portage.exception import InvalidData +from portage.exception import InvalidData, InvalidAtom from portage.versions import catpkgsplit, catsplit, pkgcmp, pkgsplit, ververify def cpvequal(cpv1, cpv2): @@ -336,6 +336,36 @@ def dep_getslot(mydep): return mydep[colon+1:] return None +def dep_getusedeps( depend ): + """ + Pull a listing of USE Dependencies out of a dep atom. + + Example usage: + >>> dep_getusedeps('app-misc/test:3[foo][-bar] + ['foo','-bar'] + + @param depend: The depstring to process + @type depend: String + @rtype: List + @return: List of use flags ( or [] if no flags exist ) + """ + use_list = [] + open_bracket = depend.find('[') + # -1 = failure (think c++ string::npos) + while( open_bracket != -1 ): + close_bracket = depend.find(']', open_bracket ) + if close_bracket == -1: + raise InvalidAtom("USE Dependency with no closing bracket: %s" % depend ) + use = depend[open_bracket + 1: close_bracket] + # foo[1:1] may return '' instead of None, we don't want '' in the result + if len(use): + use_list.append(use) + else: + raise InvalidAtom("USE Dependency with no use flag ([]): %s" % depend ) + # Find next use flag + open_bracket = depend.find( '[', open_bracket+1 ) + return use_list + _invalid_atom_chars_regexp = re.compile("[()|?]") def isvalidatom(atom, allow_blockers=False): -- 2.26.2