From: Zac Medico Date: Mon, 6 Sep 2010 22:11:42 +0000 (-0700) Subject: Replace the settings and herdstree parameters for the MetaDataXML X-Git-Tag: v2.2_rc76~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d67b2f75cd77984282e6e8d454c98e015619d125;p=portage.git Replace the settings and herdstree parameters for the MetaDataXML constructor with a single herds parameter that can be either a path to a herds.xml, or a pre-parsed ElementTree. --- diff --git a/pym/_emerge/EbuildPhase.py b/pym/_emerge/EbuildPhase.py index 75dd123ff..117471335 100644 --- a/pym/_emerge/EbuildPhase.py +++ b/pym/_emerge/EbuildPhase.py @@ -39,8 +39,10 @@ class EbuildPhase(CompositeTask): maint_str = "" metadata_xml_path = os.path.join(os.path.dirname(self.settings['EBUILD']), "metadata.xml") if os.path.isfile(metadata_xml_path): + herds_path = os.path.join(self.settings['PORTDIR'], + 'metadata/herds.xml') try: - metadata_xml = MetaDataXML(metadata_xml_path, self.settings) + metadata_xml = MetaDataXML(metadata_xml_path, herds_path) maint_str = metadata_xml.format_maintainer_string() except SyntaxError: maint_str = "" diff --git a/pym/portage/xml/metadata.py b/pym/portage/xml/metadata.py index ca523e4f1..0515c6929 100644 --- a/pym/portage/xml/metadata.py +++ b/pym/portage/xml/metadata.py @@ -159,28 +159,34 @@ class _Upstream(object): class MetaDataXML(object): """Access metadata.xml""" - def __init__(self, metadata_xml_path, settings=None, herdstree=None): + def __init__(self, metadata_xml_path, herds): """Parse a valid metadata.xml file. @type metadata_xml_path: str @param metadata_xml_path: path to a valid metadata.xml file + @type herds: str or ElementTree + @param herds: path to a herds.xml, or a pre-parsed ElementTree @raise IOError: if C{metadata_xml_path} can not be read """ self.metadata_xml_path = metadata_xml_path - self.settings = settings self._xml_tree = None - if self.settings is None: - self.settings = portage.settings - try: self._xml_tree = etree.parse(metadata_xml_path) except ImportError: pass + if isinstance(herds, etree.ElementTree): + herds_etree = herds + herds_path = None + else: + herds_etree = None + herds_path = herds + # Used for caching - self._herdstree = herdstree + self._herdstree = herds_etree + self._herds_path = herds_path self._descriptions = None self._maintainers = None self._herds = None @@ -201,9 +207,8 @@ class MetaDataXML(object): """ if self._herdstree is None: - herds_path = os.path.join(self.settings['PORTDIR'], 'metadata/herds.xml') try: - self._herdstree = etree.parse(herds_path) + self._herdstree = etree.parse(self._herds_path) except (ImportError, IOError, SyntaxError): return None