summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlav Vitters <olav@vitters.nl>2020-04-23 10:15:22 +0200
committerOlav Vitters <olav@vitters.nl>2020-04-23 10:15:22 +0200
commit6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa (patch)
treee1c15baf546815553bc835571ad2681c98f5ae78
parentcfff2a1844b636eff0dc613d2d16a67e1bced850 (diff)
downloadmgagnome-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-xmgagnome21
1 files changed, 19 insertions, 2 deletions
diff --git a/mgagnome b/mgagnome
index a947188..9973a86 100755
--- a/mgagnome
+++ b/mgagnome
@@ -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