Replace the settings and herdstree parameters for the MetaDataXML
authorZac Medico <zmedico@gentoo.org>
Mon, 6 Sep 2010 22:11:42 +0000 (15:11 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 6 Sep 2010 22:11:42 +0000 (15:11 -0700)
constructor with a single herds parameter that can be either a
path to a herds.xml, or a pre-parsed ElementTree.

pym/_emerge/EbuildPhase.py
pym/portage/xml/metadata.py

index 75dd123ff540c2e73c40536d320768a452af0807..1174713352dabcb84f7361e648184a244f671f32 100644 (file)
@@ -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 = "<invalid metadata.xml>"
index ca523e4f156dc666d0a578b114536610e4d3ac43..0515c6929b2069a8b9f089246b2c7997d49a7ab0 100644 (file)
@@ -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