diff options
author | Olav Vitters <olav@vitters.nl> | 2020-04-23 10:15:22 +0200 |
---|---|---|
committer | Olav Vitters <olav@vitters.nl> | 2020-04-23 10:15:22 +0200 |
commit | 6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa (patch) | |
tree | e1c15baf546815553bc835571ad2681c98f5ae78 | |
parent | cfff2a1844b636eff0dc613d2d16a67e1bced850 (diff) | |
download | mgagnome-6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa.tar mgagnome-6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa.tar.gz mgagnome-6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa.tar.bz2 mgagnome-6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa.tar.xz mgagnome-6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa.zip |
use specific exception for problems parsing the spec file
-rwxr-xr-x | mgagnome | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -301,6 +301,12 @@ def clean_pkgconfig_prov(prov): prov = re_clean_1.sub('', prov) return prov + +class SpecFileError(Exception): + """Used for problems in the spec file""" + pass + + class SpecFile(object): re_update_version = re.compile(r'^(?P<pre>Version[ \t]*:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) re_update_release = re.compile(r'^(?P<pre>Release[ \t]*:\s*)(?P<release>%mkrel [0-9.]+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) @@ -347,6 +353,9 @@ class SpecFile(object): try: srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \ else spec.sources() + except ValueError as exc + # Reraise this into a more specific exception + raise SpecFileError from exc finally: # ts.parseSpec can affect changing of internal macros, e.g. redefining things like mkrel and so on # reload the config to fix this @@ -558,7 +567,15 @@ class SpecFile(object): rpm.delMacro("_topdir" ) rpm.addMacro("_topdir", os.path.join(self.cwd, '..')) ts = rpm.ts() - spec = ts.parseSpec(self.path) + try: + spec = ts.parseSpec(self.path) + except ValueError as exc + # Reraise this into a more specific exception + raise SpecFileError from exc + finally: + # ts.parseSpec can affect changing of internal macros, e.g. redefining things like mkrel and so on + # reload the config to fix this + rpm.reloadConfig() requires = spec.sourceHeader[rpm.RPMTAG_REQUIRES] require_flags = spec.sourceHeader[rpm.RPMTAG_REQUIREFLAGS] @@ -1079,7 +1096,7 @@ class Downstream(object): for line in contents: try: srpm, version, filename = line.split("|") - except ValueError: + except SpecFileError: print(line, file=sys.stderr) continue |