diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-08-26 16:08:15 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-26 16:08:15 -0700 |
commit | f37424319b32ea3eede9ec21194622d80747848c (patch) | |
tree | ec3288db269cf2d69dc90ce16f4ea8857bb43dfd | |
parent | 666c4e75360313c0297d54b86f6bb07ef6b3f764 (diff) | |
download | portage-f37424319b32ea3eede9ec21194622d80747848c.tar.gz portage-f37424319b32ea3eede9ec21194622d80747848c.tar.bz2 portage-f37424319b32ea3eede9ec21194622d80747848c.zip |
Various parse_metadata_use() fixes:
* Allow empty descriptions (backward compatibility).
* Support multiple 'use' elements.
* If multiple 'flag' elements have the same name attribute, use
the first occurance.
-rw-r--r-- | pym/repoman/utilities.py | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 50576d9b9..3df437a01 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -121,35 +121,45 @@ def parse_metadata_use(xml_tree): """ uselist = {} - usetag = xml_tree.findall("use") - if not usetag: + usetags = xml_tree.findall("use") + if not usetags: return uselist - flags = usetag[0].findall("flag") - if not flags: - raise exception.ParseError("missing 'flag' tag(s)") - - for flag in flags: - pkg_flag = flag.get("name") - if pkg_flag is None: - raise exception.ParseError("missing 'name' attribute for 'flag' tag") - - # emulate the Element.itertext() method from python-2.7 - inner_text = [] - stack = [] - stack.append(flag) - while stack: - obj = stack.pop() - if isinstance(obj, basestring): - inner_text.append(obj) + # It's possible to have multiple 'use' elements. + for usetag in usetags: + flags = usetag.findall("flag") + if not flags: + raise exception.ParseError("missing 'flag' tag(s)") + + for flag in flags: + pkg_flag = flag.get("name") + if pkg_flag is None: + raise exception.ParseError("missing 'name' attribute for 'flag' tag") + + if uselist.get(pkg_flag): + # It's possible to have multiple elements with the same + # flag name, but different 'restrict' attributes that + # specify version restrictions. We use only the first + # occurance. continue - if isinstance(obj.text, basestring): - inner_text.append(obj.text) - if isinstance(obj.tail, basestring): - stack.append(obj.tail) - stack.extend(reversed(obj)) - uselist[pkg_flag] = " ".join("".join(inner_text).split()) + # emulate the Element.itertext() method from python-2.7 + inner_text = [] + stack = [] + stack.append(flag) + while stack: + obj = stack.pop() + if isinstance(obj, basestring): + inner_text.append(obj) + continue + if isinstance(obj.text, basestring): + inner_text.append(obj.text) + if isinstance(obj.tail, basestring): + stack.append(obj.tail) + stack.extend(reversed(obj)) + + uselist[pkg_flag] = " ".join("".join(inner_text).split()) + return uselist class UnknownHerdsError(ValueError): |