Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
patch: extract d/rules manipulations
Browse files Browse the repository at this point in the history
Try to break apart that monolithic _run() method.
  • Loading branch information
ktdreyer committed Jul 5, 2017
1 parent ffc9094 commit 46b1f69
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions rhcephpkg/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
BZ_REGEX = r'rhbz#(\d+)'


def read_rules_file():
""" Return contents of debian/rules as a single multiline string. """
with open('debian/rules') as fh:
return fh.read()


def read_commit():
"""
Return the current $COMMIT sha1 from debian/rules, or None if not found.
"""
commit_re = r'export COMMIT=([0-9a-f]{40})'
rules = read_rules_file()
m = re.search(commit_re, rules)
if m:
return m.group(1)


class Patch(object):
help_menu = 'apply patches from patch-queue branch'
_help = """
Expand Down Expand Up @@ -70,12 +87,11 @@ def _run(self):
subprocess.check_call(cmd)

# Replace $COMMIT sha1 in d/rules
with open('debian/rules') as rules:
rules_file = rules.read()
old = r'export COMMIT=[0-9a-f]{40}'
new = 'export COMMIT=%s' % patches_sha1
with open('debian/rules', 'w') as fileh:
fileh.write(re.sub(old, new, rules_file))
old_sha1 = read_commit()
if old_sha1:
rules = read_rules_file()
with open('debian/rules', 'w') as fileh:
fileh.write(rules.replace(old_sha1, patches_sha1))

# Get the new patch series
new_series = self.read_series_file('debian/patches/series')
Expand Down

0 comments on commit 46b1f69

Please sign in to comment.