From 6aaf2f5aa6e8f7eab1fc8ab94099a446baf035fa Mon Sep 17 00:00:00 2001 From: Olav Vitters Date: Thu, 23 Apr 2020 10:15:22 +0200 Subject: use specific exception for problems parsing the spec file --- mgagnome | 21 +++++++++++++++++++-- 1 file 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
Version[ \t]*:\s*)(?P.+)(?P\s*)$', re.MULTILINE + re.IGNORECASE)
     re_update_release = re.compile(r'^(?P
Release[ \t]*:\s*)(?P%mkrel [0-9.]+)(?P\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
 
-- 
cgit v1.2.1