diff options
-rw-r--r-- | gbp/rpm/__init__.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index dec4ac7b..1d24c5c2 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -117,6 +117,7 @@ class SrcRpmFile(object): class SpecFile(object): """Class for parsing/modifying spec files""" + tag_re = re.compile(r'^(?P<name>[a-z][a-z0-9]*)\s*:\s*(?P<value>\S(.*\S)?)\s*$', flags=re.I) source_re = re.compile(r'^Source(?P<srcnum>[0-9]+)?\s*:\s*(?P<name>[^\s].*[^\s])\s*$', flags=re.I) patchtag_re = re.compile(r'^Patch(?P<patchnum>[0-9]+)?\s*:\s*(?P<name>\S.*)$', flags=re.I) patchmacro_re = re.compile(r'^%patch(?P<patchnum>[0-9]+)?(\s+(?P<args>.*))?$') @@ -160,6 +161,13 @@ class SpecFile(object): f.close() loc = self.parse_content() + + # Find 'Packager' tag. Needed to circumvent a bug in python-rpm where + # spec.sourceHeader[rpm.RPMTAG_PACKAGER] is not reset when a new spec + # file is parsed + if loc['packagertag'] is None: + self.packager = None + # Update sources info (basically possible macros expanded by spec.__init__() # And, double-check that we parsed spec content correctly for (name, num, typ) in self.specinfo.sources: @@ -253,6 +261,7 @@ class SpecFile(object): """ # Check location of "interesting" tags and macros ret = {'nametag': None, + 'packagertag': None, 'setupmacro': None, 'prepmacro': None} @@ -381,12 +390,16 @@ class SpecFile(object): continue # Only search for the last occurrence of the following - if re.match("^\s*Name:.*$", line, flags=re.I): - ret['setupmacro'] = i + m = self.tag_re.match(line) + if m: + if m.group('name').lower() == 'name': + ret['nametag'] = i + if m.group('name').lower() == 'packager': + ret['packagertag'] = i + continue if re.match("^%prep(\s.*)?$", line): ret['prepmacro'] = i continue - return ret |