diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-12-24 21:53:59 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-12-26 14:02:29 +0100 |
commit | 694dd200e3ad985b904952e0102a73470b4bb583 (patch) | |
tree | 823b83e3f648ec713eea6a5487f199148fac64a1 /examples | |
parent | e1f5a6da045f55e2290c4ad016209433d5ae66ac (diff) |
gbp-add-patch: simplify by using existing classes
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/gbp-add-patch | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/examples/gbp-add-patch b/examples/gbp-add-patch index 059ac9ca..5a974cde 100755 --- a/examples/gbp-add-patch +++ b/examples/gbp-add-patch @@ -32,60 +32,16 @@ commits debian/patches/0010-bla-fasel with this changelog message: Thanks: <author> """ -import email import re import sys import os, os.path -import subprocess -import tempfile from gbp.command_wrappers import (Command, CommandExecFailed, GitCommand) from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.errors import GbpError from gbp.git import (GitRepositoryError, GitRepository) - -class PatchInfo(object): - def __init__(self, patch): - t_body = tempfile.NamedTemporaryFile(prefix='gbp_add_patch_', dir='.git/') - t_patch = tempfile.NamedTemporaryFile(prefix='gbp_add_patch_', dir='.git/') - popen = subprocess.Popen(['git', 'mailinfo', t_body.name, t_patch.name], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE) - self.name = patch - try: - f = file(patch) - except IOError, msg: - raise GbpError, msg - out, dummy = popen.communicate(f.read()) - f.close() - self.header = email.message_from_string(out) - self.body = t_body.read() - t_body.close() - self.patch = t_patch.read() - t_patch.close() - - def summary(self): - return self.header['Subject'] - - def author_name(self): - return self.header['Author'] - - def author(self): - return '%(Author)s <%(Email)s>' % self.header - - -class GitCommit(GitCommand): - """Wrap git commit to commit staged changes""" - def __init__(self, verbose=False, **kwargs): - args = [ ['-q'], [] ][verbose] - GitCommand.__init__(self, cmd='commit', args=args, **kwargs) - - def __call__(self, msg='', edit=False): - args = [ [], ['-e'] ][edit] - args += [ [], ['-m', msg] ][len(msg) > 0] - self.run_error = "Couldn't %s %s" % (self.cmd, " ".join(self.args + args)) - GitCommand.__call__(self, args) +from gbp.patch_series import Patch def build_commit_msg(repo, patch, options): @@ -95,19 +51,19 @@ def build_commit_msg(repo, patch, options): closes = '' author = repo.get_author_info() - if author.name != patch.author_name(): - thanks = "Thanks: %s" % patch.author_name() + if author.name != patch.author: + thanks = "Thanks: %s" % patch.author - for line in patch.body.split('\n'): + for line in patch.long_desc.split('\n'): if bts_closes.match(line): closes += line + '\n' - patch_name = os.path.basename(patch.name) + patch_name = os.path.basename(patch.path) msg="""New patch %s %s %s -%s""" % (patch_name, patch.summary(), thanks, closes) +%s""" % (patch_name, patch.subject, thanks, closes) return msg @@ -141,11 +97,11 @@ def main(argv): else: patchfile = args[1] - patch = PatchInfo(patchfile) + patch = Patch(patchfile) repo.add_files(patchfile) msg = build_commit_msg(repo, patch, options) - GitCommit()(edit=options.edit, msg=msg) + repo.commit_staged(edit=options.edit, msg=msg) # FIXME: handle the series file except CommandExecFailed: |