From 39c89b95ba4843fd746a23717638f6ede8fb86ad Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 18 Jul 2008 12:40:58 +0000 Subject: [PATCH] Bug #199788 - Make repoman parse GLEP 56 USE flag descriptions from metadata.xml (in addition to use.local.desc). Thanks to Doug Goldstein for this patch. svn path=/main/trunk/; revision=11126 --- bin/repoman | 15 +++++++++++++++ pym/repoman/utilities.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/bin/repoman b/bin/repoman index 2c34ac919..e53ae076a 100755 --- a/bin/repoman +++ b/bin/repoman @@ -1072,6 +1072,16 @@ for x in scanlist: stats["metadata.bad"]+=1 fails["metadata.bad"].append(x+"/metadata.xml") + #load USE flags from metadata.xml + muselist=[] + try: + f = open(os.path.join(checkdir, "metadata.xml")) + utilities.parse_metadata_use(f, muselist) + f.close() + except (IOError, OSError, ParseError), e: + logging.exception("Couldn't read from metadata.xml", e) + sys.exit(1) + allmasked = True for y in ebuildlist: @@ -1354,6 +1364,11 @@ for x in scanlist: if flag_name not in uselist: myuse.append(flag_name) + # uselist checks - metadata + for mypos in range(len(myuse)-1,-1,-1): + if myuse[mypos] and (myuse[mypos] in muselist): + del myuse[mypos] + # uselist checks - local mykey = portage.dep_getkey(catpkg) if mykey in luselist: diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index f6c50326b..c32f69fed 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -13,6 +13,8 @@ import logging import os import sys +from xml.dom import minidom +from xml.dom import NotFoundErr from portage import output from portage.output import red, green from portage.process import find_binary @@ -111,6 +113,37 @@ def parse_use_local_desc(mylines, usedict=None): usedict[pkg].add(flag) return usedict +def parse_metadata_use(mylines, uselist=None): + """ + Records are wrapped in XML as per GLEP 56 + returns a dict of the form a list of flags""" + if uselist is None: + uselist = [] + metadatadom = minidom.parse(mylines) + + try: + usetag = metadatadom.getElementsByTagName("use") + if not usetag: + return uselist + except NotFoundErr: + return uselist + + try: + flags = usetag[0].getElementsByTagName("flag") + except NotFoundErr: + raise exception.ParseError("metadata.xml: " + \ + "Malformed input: missing 'flag' tag(s)") + + for flag in flags: + pkg_flag = flag.getAttribute("name") + if not pkg_flag: + raise exception.ParseError("metadata.xml: " + \ + "Malformed input: missing 'name' attribute for 'flag' tag") + uselist.append(pkg_flag) + + metadatadom.unlink() + return uselist + def FindPackagesToScan(settings, startdir, reposplit): """ Try to find packages that need to be scanned -- 2.26.2