class SpecFile(object):
"""Class for parsing/modifying spec files"""
source_re = re.compile(r'^Source(?P<srcnum>[0-9]+)?:\s*(?P<filename>[^\s].*[^\s])\s*$', flags=re.I)
- patchfile_re = re.compile(r'^(Patch(?P<patchnum>[0-9]+))?:\s*(?P<filename>.+)\s*$', flags=re.I)
+ patchfile_re = re.compile(r'^Patch(?P<patchnum>[0-9]+)?:\s*(?P<filename>.+)\s*$', flags=re.I)
applypatch_re = re.compile(r'^%patch(?P<patchnum>[0-9]+)?(\s+(?P<args>.*))?$')
marker_re = re.compile(r'^#\s+(?P<marker>>>|<<)\s+(?P<what>gbp-[^\s]+)\s*(?P<comment>.*)$')
for (name, num, typ) in self.specinfo.sources:
# only add files of patch type
if typ == 2:
- self.patches[num] = {'filename': name, 'strip': '0', 'apply': False}
+ self.patches[num] = {'filename': name, 'strip': '0', 'apply': False, 'autoupdate': False}
# Parse info from spec file
f = file(self.specfile)
+ autoupdate = False
for line in f:
m = self.applypatch_re.match(line)
if m:
self.patches[patchnum]['apply'] = True
continue
+ # Find patch tags inside autoupdate markers
+ m = self.marker_re.match(line)
+ if m:
+ if m.group('what') == "gbp-patch-tags":
+ if m.group('marker') == '>>':
+ autoupdate = True
+ else:
+ autoupdate = False
+ continue
+ m = self.patchfile_re.match(line)
+ if m:
+ if m.group('patchnum'):
+ patchnum = int(m.group('patchnum'))
+ else:
+ patchnum = 0
+ self.patches[patchnum]['autoupdate'] = autoupdate
+ continue
+
f.close()
# RPMTODO: complete this
tmpffd, tmpfpath = tempfile.mkstemp(suffix='.spec', dir='.')
tmpf = os.fdopen(tmpffd, 'w')
+ # Check the max patchnumber of non-autoupdate patches
+ start_patch_tag_num = 0
+ for n, p in self.patches.iteritems():
+ if (not p['autoupdate']) and (n >= start_patch_tag_num):
+ start_patch_tag_num = n + 1
+ gbp.log.debug("Starting autoupdate patch macro numbering from %s" % start_patch_tag_num)
+
autoupdate = False
for line in f:
m = self.marker_re.match(line)
if autoupdate == 'gbp-patch-tags':
for i in range(len(patchfilenames)):
+ tag_num = start_patch_tag_num + i
# "PatchXYZ:" text 12 chars wide, left aligned
- tmpf.write("%-12s%s\n" % ("Patch%d:" % i, patchfilenames[i]))
+ tmpf.write("%-12s%s\n" % ("Patch%d:" % tag_num, patchfilenames[i]))
elif autoupdate == 'gbp-apply-patches':
for i in range(len(patchfilenames)):
+ tag_num = start_patch_tag_num + i
tmpf.write("# %s\n" % patchfilenames[i])
- tmpf.write("%%patch%d -p1\n" % i)
+ tmpf.write("%%patch%d -p1\n" % tag_num)
else:
# Unknown autoupdate marker, we shouldn't end up here
gbp.log.warn("Hmm, found a bug - don't know what to do with marker '%s'" % autoupdate)
gbp.log.debug("Orig file: %s" % self.orig_file)
for n, p in sorted(self.patches.iteritems()):
- gbp.log.debug("Patch %s: %s, strip: %s, apply: %s" %
- (n, p['filename'], p['strip'], p['apply']))
+ gbp.log.debug("Patch %s: %s, strip: %s, apply: %s, autoupdate: %s" %
+ (n, p['filename'], p['strip'], p['apply'], p['autoupdate']))
def parse_srpm(srpmfile):
# Remove all old patches
for n, p in spec.patches.iteritems():
- f = spec.specdir+"/"+p['filename']
- gbp.log.debug("Removing '%s'" % f)
- try:
- os.unlink(f)
- except OSError, (e, msg):
- if e != errno.ENOENT:
- raise GbpError, "Failed to remove patch: %s" % msg
- else:
- gbp.log.debug("%s does not exist." % f)
+ if p['autoupdate']:
+ f = spec.specdir+"/"+p['filename']
+ gbp.log.debug("Removing '%s'" % f)
+ try:
+ os.unlink(f)
+ except OSError, (e, msg):
+ if e != errno.ENOENT:
+ raise GbpError, "Failed to remove patch: %s" % msg
+ else:
+ gbp.log.debug("%s does not exist." % f)
gbp.log.info("Generating patches from git (%s..%s)" % (upstream_tree, totree))
if repo.get_obj_type(totree) in ['tag', 'commit']:
raise GbpError, ("Couldn't find upstream version %s. Don't know on what base to import." % spec.version)
for n, p in spec.patches.iteritems():
- f = options.packaging_dir+"/"+p['filename']
- gbp.log.debug("Removing '%s'" % f)
- try:
- os.unlink(f)
- except OSError, (e, msg):
- if e != errno.ENOENT:
- raise GbpError, "Failed to remove patch: %s" % msg
- else:
- gbp.log.debug("%s does not exist." % f)
+ if p['autoupdate']:
+ f = options.packaging_dir+"/"+p['filename']
+ gbp.log.debug("Removing '%s'" % f)
+ try:
+ os.unlink(f)
+ except OSError, (e, msg):
+ if e != errno.ENOENT:
+ raise GbpError, "Failed to remove patch: %s" % msg
+ else:
+ gbp.log.debug("%s does not exist." % f)
gbp.log.info("Exporting patches from git (%s..%s)" % (upstream_commit, pq_branch))
patches = repo.format_patches(upstream_commit, pq_branch, options.packaging_dir,