From bf9b3e70758454afa53972340abc98a248195e45 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 26 Aug 2010 14:29:34 -0700 Subject: Make the Atom class add 'EAPI.incompatible' category attributes to InvalidAtom exceptions, make use_reduce() raise InvalidDependString exceptions that encapsulate InvalidAtom exceptions, and make Package._validate_deps() use the InvalidAtom categories when recording the invalid metadata for use by repoman. Also, remove the EAPI.incompatible code from repoman that's no longer used. --- pym/_emerge/Package.py | 13 ++++++++++++- pym/portage/dep/__init__.py | 21 ++++++++++++++++----- pym/portage/exception.py | 6 ++++++ 3 files changed, 34 insertions(+), 6 deletions(-) (limited to 'pym') diff --git a/pym/_emerge/Package.py b/pym/_emerge/Package.py index e361c28be..b6f2d585a 100644 --- a/pym/_emerge/Package.py +++ b/pym/_emerge/Package.py @@ -76,7 +76,18 @@ class Package(Task): use_reduce(v, eapi=eapi, is_valid_flag=self.iuse.is_valid_flag, token_class=Atom) except portage.exception.InvalidDependString as e: - self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e)) + categorized_error = False + if e.errors: + for error in e.errors: + if getattr(error, 'category', None) is None: + continue + categorized_error = True + self._invalid_metadata(error.category, + "%s: %s" % (k, error)) + + if not categorized_error: + self._invalid_metadata(k + ".syntax", + "%s: %s" % (k, e)) k = 'REQUIRED_USE' v = self.metadata.get(k) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 8a31b3f6d..55dd822c1 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -481,7 +481,10 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i token = token_class(token, eapi=eapi) except InvalidAtom as e: raise portage.exception.InvalidDependString( - _("Invalid atom (%s) in '%s', token %s") % (e, depstr, pos+1)) + _("Invalid atom (%s) in '%s', token %s") \ + % (e, depstr, pos+1), errors=(e,)) + except SystemExit: + raise except Exception as e: raise portage.exception.InvalidDependString( _("Invalid token '%s' in '%s', token %s") % (token, depstr, pos+1)) @@ -1049,15 +1052,23 @@ class Atom(_atom_base): if eapi is not None: if self.slot and not eapi_has_slot_deps(eapi): - raise InvalidAtom("Slot deps are not allowed in EAPI %s: '%s'" % (eapi, self)) + raise InvalidAtom( + _("Slot deps are not allowed in EAPI %s: '%s'") \ + % (eapi, self), category='EAPI.incompatible') if self.use: if not eapi_has_use_deps(eapi): - raise InvalidAtom("Use deps are not allowed in EAPI %s: '%s'" % (eapi, self)) + raise InvalidAtom( + _("Use deps are not allowed in EAPI %s: '%s'") \ + % (eapi, self), category='EAPI.incompatible') elif not eapi_has_use_dep_defaults(eapi) and \ (self.use.missing_enabled or self.use.missing_disabled): - raise InvalidAtom("Use dep defaults are not allowed in EAPI %s: '%s'" % (eapi, self)) + raise InvalidAtom( + _("Use dep defaults are not allowed in EAPI %s: '%s'") \ + % (eapi, self), category='EAPI.incompatible') if self.blocker and self.blocker.overlap.forbid and not eapi_has_strong_blocks(eapi): - raise InvalidAtom("Strong blocks are not allowed in EAPI %s: '%s'" % (eapi, self)) + raise InvalidAtom( + _("Strong blocks are not allowed in EAPI %s: '%s'") \ + % (eapi, self), category='EAPI.incompatible') def __setattr__(self, name, value): raise AttributeError("Atom instances are immutable", diff --git a/pym/portage/exception.py b/pym/portage/exception.py index f8388e2b6..b289b6285 100644 --- a/pym/portage/exception.py +++ b/pym/portage/exception.py @@ -31,6 +31,9 @@ class CorruptionError(PortageException): class InvalidDependString(PortageException): """An invalid depend string has been encountered""" + def __init__(self, value, errors=None): + PortageException.__init__(self, value) + self.errors = errors class InvalidVersionString(PortageException): """An invalid version string has been encountered""" @@ -102,6 +105,9 @@ class InvalidPackageName(PortagePackageException): class InvalidAtom(PortagePackageException): """Malformed atom spec""" + def __init__(self, value, category=None): + PortagePackageException.__init__(self, value) + self.category = category class UnsupportedAPIException(PortagePackageException): """Unsupported API""" -- cgit v1.2.3-1-g7c22