From ee3bf6f9773c0afbd494c657d253241f79d98044 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 4 Jun 2012 14:59:12 -0700 Subject: [PATCH] Handle more import exceptions involving xml. See http://bugs.python.org/issue14988 --- bin/repoman | 6 +++++- pym/_emerge/EbuildPhase.py | 13 +++++++++++-- pym/portage/xml/metadata.py | 10 ++++++++-- pym/repoman/herdbase.py | 6 +++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/bin/repoman b/bin/repoman index 052ec9436..e43fa1cd5 100755 --- a/bin/repoman +++ b/bin/repoman @@ -45,7 +45,11 @@ portage.dep._internal_warnings = True try: import xml.etree.ElementTree from xml.parsers.expat import ExpatError -except (ImportError, SystemError): +except (SystemExit, KeyboardInterrupt): + raise +except (ImportError, SystemError, RuntimeError, Exception): + # broken or missing xml support + # http://bugs.python.org/issue14988 msg = ["Please enable python's \"xml\" USE flag in order to use repoman."] from portage.output import EOutput out = EOutput() diff --git a/pym/_emerge/EbuildPhase.py b/pym/_emerge/EbuildPhase.py index 27944f413..741f6083e 100644 --- a/pym/_emerge/EbuildPhase.py +++ b/pym/_emerge/EbuildPhase.py @@ -12,7 +12,16 @@ from _emerge.MiscFunctionsProcess import MiscFunctionsProcess from _emerge.EbuildProcess import EbuildProcess from _emerge.CompositeTask import CompositeTask from portage.util import writemsg -from portage.xml.metadata import MetaDataXML + +try: + from portage.xml.metadata import MetaDataXML +except (SystemExit, KeyboardInterrupt): + raise +except (ImportError, SystemError, RuntimeError, Exception): + # broken or missing xml support + # http://bugs.python.org/issue14988 + MetaDataXML = None + import portage portage.proxy.lazyimport.lazyimport(globals(), 'portage.elog:messages@elog_messages', @@ -71,7 +80,7 @@ class EbuildPhase(CompositeTask): maint_str = "" upstr_str = "" metadata_xml_path = os.path.join(os.path.dirname(self.settings['EBUILD']), "metadata.xml") - if os.path.isfile(metadata_xml_path): + if MetaDataXML is not None and os.path.isfile(metadata_xml_path): herds_path = os.path.join(self.settings['PORTDIR'], 'metadata/herds.xml') try: diff --git a/pym/portage/xml/metadata.py b/pym/portage/xml/metadata.py index 25f801a47..f820e5414 100644 --- a/pym/portage/xml/metadata.py +++ b/pym/portage/xml/metadata.py @@ -42,12 +42,18 @@ if sys.hexversion < 0x2070000 or \ else: try: import xml.etree.cElementTree as etree - except (ImportError, SystemError): + except (SystemExit, KeyboardInterrupt): + raise + except (ImportError, SystemError, RuntimeError, Exception): + # broken or missing xml support + # http://bugs.python.org/issue14988 import xml.etree.ElementTree as etree try: from xml.parsers.expat import ExpatError -except (ImportError, SystemError): +except (SystemExit, KeyboardInterrupt): + raise +except (ImportError, SystemError, RuntimeError, Exception): ExpatError = SyntaxError import re diff --git a/pym/repoman/herdbase.py b/pym/repoman/herdbase.py index 91a32cb00..fcf58b36c 100644 --- a/pym/repoman/herdbase.py +++ b/pym/repoman/herdbase.py @@ -7,7 +7,11 @@ import errno import xml.etree.ElementTree try: from xml.parsers.expat import ExpatError -except (ImportError, SystemError): +except (SystemExit, KeyboardInterrupt): + raise +except (ImportError, SystemError, RuntimeError, Exception): + # broken or missing xml support + # http://bugs.python.org/issue14988 # This means that python is built without xml support. # We tolerate global scope import failures for optional # modules, so that ImportModulesTestCase can succeed (or -- 2.26.2