From 41e6419dfd337165e679ece4ae3ba310abc94db3 Mon Sep 17 00:00:00 2001 From: Guido Guenther Date: Sun, 11 Feb 2007 23:07:41 +0100 Subject: use GBPError everywhere and move commands from __init__ to command_wrappers.py Furthermore pass '-v' in git import-orig on to git_load_dirs --- TODO | 2 + debian/changelog | 9 +++ gbp/__init__.py | 188 +---------------------------------------------- gbp/command_wrappers.py | 191 ++++++++++++++++++++++++++++++++++++++++++++++++ gbp/config.py | 5 +- gbp/deb_utils.py | 5 +- gbp/errors.py | 10 +++ gbp/git_utils.py | 4 +- git-buildpackage | 29 +++----- git-import-dsc | 104 ++++++++++++++------------ git-import-orig | 171 +++++++++++++++++++++++-------------------- setup.py | 6 +- 12 files changed, 383 insertions(+), 341 deletions(-) create mode 100644 gbp/command_wrappers.py create mode 100644 gbp/errors.py diff --git a/TODO b/TODO index 7301b776..47fdbec1 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ - git-buildpackage: - allow to export the hole source tree to tmpdir before building - git-import-orig: + - don't use git_load_dirs but use new branches for new upstream versions + and merge them to 'upstream' - this will trace renames, etc. properly - allow to import from an unpacked source tree - git-import-dsc: - allow to import into a git repository for backports diff --git a/debian/changelog b/debian/changelog index e94c00ab..b2f5cfeb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +git-buildpackage (0.2.25.gbp0) unstable; urgency=low + + * use GbpError everywhere + * move commands into a submodule + * git-import-orig: pass --verbose on to git_load_dirs + * use default python version in setup.py + + -- Guido Guenther Sun, 11 Feb 2007 22:52:31 +0100 + git-buildpackage (0.2.25) unstable; urgency=low * posttag support for git-buildpackage: use --git-posttag to run a command diff --git a/gbp/__init__.py b/gbp/__init__.py index 99251094..fe0ca3dd 100644 --- a/gbp/__init__.py +++ b/gbp/__init__.py @@ -1,187 +1,5 @@ -# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 : # -# (C) 2006 Guido Guenther -"""Simple class wrappers for the various commands needed by git-buildpackage""" +# (C) 2006,2007 Guido Guenther +"""The various things needed by git-buildpackage and friends""" -import subprocess -import sys - - -class CommandExecFailed(Exception): - """Exception raised by the Command class""" - pass - - -class Command(object): - """ - Wraps a shell command, so we don't have to store any kind of command line options in - one of the git-buildpackage commands - """ - verbose = False - - def __init__(self, cmd, args=[], shell=False): - self.cmd = cmd - self.args = args - self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args)) - self.shell = shell - - def __run(self, args): - """run self.cmd adding args as additional arguments""" - try: - if self.verbose: - print self.cmd, self.args, args - cmd = [ self.cmd ] + self.args + args - if self.shell: # subprocess.call only cares about the first argument if shell=True - cmd = " ".join(cmd) - retcode = subprocess.call(cmd, shell=self.shell) - if retcode < 0: - print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd, -retcode) - elif retcode > 0: - print >>sys.stderr, "%s returned %d" % (self.cmd, retcode) - except OSError, e: - print >>sys.stderr, "Execution failed:", e - retcode = 1 - if retcode: - print >>sys.stderr,self.run_error - return retcode - - def __call__(self, args=[]): - if self.__run(args): - raise CommandExecFailed - - -class UnpackTGZ(Command): - """Wrap tar to Unpack a gzipped tar archive""" - def __init__(self, tgz, dir): - self.tgz = tgz - self.dir = dir - Command.__init__(self, 'tar', [ '-C', dir, '-zxf', tgz ]) - self.run_error = "Couldn't unpack %s" % self.tgz - - -class RemoveTree(Command): - "Wrap rm to remove a whole directory tree" - def __init__(self, tree): - self.tree = tree - Command.__init__(self, 'rm', [ '-rf', tree ]) - self.run_error = "Couldn't remove %s" % self.tree - - -class Dch(Command): - """Wrap dch and set a specific version""" - def __init__(self, version, msg): - args = ['-v', version] - if msg: - args.append(msg) - Command.__init__(self, 'dch', args) - self.run_error = "Dch failed." - - -class DpkgSourceExtract(Command): - """ - Wrap dpkg-source to extract a Debian source package into a certain - directory, this needs - """ - def __init__(self): - Command.__init__(self, 'dpkg-source', ['-x']) - - def __call__(self, dsc, output_dir): - self.run_error = "Couldn't extract %s" % dsc - Command.__call__(self, [dsc, output_dir]) - - -class GitLoadDirs(Command): - """Wrap git_load_dirs""" - def __init__(self): - Command.__init__(self, 'git_load_dirs') - - def __call__(self, dir, log=''): - self.dir = dir - self.run_error = "Couldn't import %s" % self.dir - args = [ [], ['-L', log] ] [len(log) > 0] - Command.__call__(self, args+[dir]) - - -class GitCommand(Command): - "Mother/Father of all git commands" - def __init__(self, cmd, args=[]): - Command.__init__(self, 'git-'+cmd, args) - - -class GitInitDB(GitCommand): - """Wrap git-init-db""" - def __init__(self): - GitCommand.__init__(self, 'init-db') - self.run_error = "Couldn't init git repository" - - -class GitShowBranch(GitCommand): - """Wrap git-show-branch""" - def __init__(self): - GitCommand.__init__(self, 'branch') - self.run_error = "Couldn't list branches" - - -class GitBranch(GitCommand): - """Wrap git-branch""" - def __init__(self): - GitCommand.__init__(self, 'branch') - - def __call__(self, branch): - self.run_error = "Couldn't create branch %s" % (branch,) - GitCommand.__call__(self, [branch]) - - -class GitCheckoutBranch(GitCommand): - """Wrap git-checkout in order tos switch to a certain branch""" - def __init__(self, branch): - GitCommand.__init__(self, 'checkout', [branch]) - self.branch = branch - self.run_error = "Couldn't switch to %s branch" % self.branch - - -class GitPull(GitCommand): - """Wrap git-pull""" - def __init__(self, repo, branch): - GitCommand.__init__(self, 'pull', [repo, branch]) - self.run_error = "Couldn't pull %s to %s" % (branch, repo) - - -class GitTag(GitCommand): - """Wrap git-tag""" - def __init__(self, sign_tag=False, keyid=None): - GitCommand.__init__(self,'tag') - self.sign_tag = sign_tag - self.keyid = keyid - - def __call__(self, version, msg="Tagging %(version)s"): - self.run_error = "Couldn't tag %s" % (version,) - if self.sign_tag: - if self.keyid: - sign_opts = [ '-u', self.keyid ] - else: - sign_opts = [ '-s' ] - else: - sign_opts = [] - GitCommand.__call__(self, sign_opts+[ '-m', msg % locals(), version]) - - -class GitAdd(GitCommand): - """Wrap git-add to add new files""" - def __init__(self): - GitCommand.__init__(self,'add') - self.run_error = "Couldn't add files" - - -class GitCommitAll(GitCommand): - """Wrap git-commit to commit all changes""" - def __init__(self): - GitCommand.__init__(self, 'commit', ['-a']) - - def __call__(self, msg=''): - args = [ [], ['-m', msg] ][len(msg) > 0] - self.run_error = "Couldn't commit -a %s" % " ".join(args) - GitCommand.__call__(self, args) - - -# vim:et:ts=4:sw=4: diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py new file mode 100644 index 00000000..58da2906 --- /dev/null +++ b/gbp/command_wrappers.py @@ -0,0 +1,191 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2007 Guido Guenther +""" +Simple class wrappers for the various external commands needed by +git-buildpackage and friends +""" + +import subprocess +import sys + +class CommandExecFailed(Exception): + """Exception raised by the Command class""" + pass + + +class Command(object): + """ + Wraps a shell command, so we don't have to store any kind of command line options in + one of the git-buildpackage commands + """ + verbose = False + + def __init__(self, cmd, args=[], shell=False): + self.cmd = cmd + self.args = args + self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args)) + self.shell = shell + + def __run(self, args): + """run self.cmd adding args as additional arguments""" + try: + if self.verbose: + print self.cmd, self.args, args + cmd = [ self.cmd ] + self.args + args + if self.shell: # subprocess.call only cares about the first argument if shell=True + cmd = " ".join(cmd) + retcode = subprocess.call(cmd, shell=self.shell) + if retcode < 0: + print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd, -retcode) + elif retcode > 0: + print >>sys.stderr, "%s returned %d" % (self.cmd, retcode) + except OSError, e: + print >>sys.stderr, "Execution failed:", e + retcode = 1 + if retcode: + print >>sys.stderr,self.run_error + return retcode + + def __call__(self, args=[]): + if self.__run(args): + raise CommandExecFailed + + +class UnpackTGZ(Command): + """Wrap tar to Unpack a gzipped tar archive""" + def __init__(self, tgz, dir): + self.tgz = tgz + self.dir = dir + Command.__init__(self, 'tar', [ '-C', dir, '-zxf', tgz ]) + self.run_error = "Couldn't unpack %s" % self.tgz + + +class RemoveTree(Command): + "Wrap rm to remove a whole directory tree" + def __init__(self, tree): + self.tree = tree + Command.__init__(self, 'rm', [ '-rf', tree ]) + self.run_error = "Couldn't remove %s" % self.tree + + +class Dch(Command): + """Wrap dch and set a specific version""" + def __init__(self, version, msg): + args = ['-v', version] + if msg: + args.append(msg) + Command.__init__(self, 'dch', args) + self.run_error = "Dch failed." + + +class DpkgSourceExtract(Command): + """ + Wrap dpkg-source to extract a Debian source package into a certain + directory, this needs + """ + def __init__(self): + Command.__init__(self, 'dpkg-source', ['-x']) + + def __call__(self, dsc, output_dir): + self.run_error = "Couldn't extract %s" % dsc + Command.__call__(self, [dsc, output_dir]) + + +class GitLoadDirs(Command): + """Wrap git_load_dirs""" + def __init__(self, verbose=False): + Command.__init__(self, 'git_load_dirs') + if verbose: + self.args = [ '-v' ] + + def __call__(self, dir, log=''): + self.dir = dir + self.run_error = "Couldn't import %s" % self.dir + args = [ [], ['-L', log] ] [len(log) > 0] + Command.__call__(self, self.args + args + [dir]) + + +class GitCommand(Command): + "Mother/Father of all git commands" + def __init__(self, cmd, args=[]): + Command.__init__(self, 'git-'+cmd, args) + + +class GitInitDB(GitCommand): + """Wrap git-init-db""" + def __init__(self): + GitCommand.__init__(self, 'init-db') + self.run_error = "Couldn't init git repository" + + +class GitShowBranch(GitCommand): + """Wrap git-show-branch""" + def __init__(self): + GitCommand.__init__(self, 'branch') + self.run_error = "Couldn't list branches" + + +class GitBranch(GitCommand): + """Wrap git-branch""" + def __init__(self): + GitCommand.__init__(self, 'branch') + + def __call__(self, branch): + self.run_error = "Couldn't create branch %s" % (branch,) + GitCommand.__call__(self, [branch]) + + +class GitCheckoutBranch(GitCommand): + """Wrap git-checkout in order tos switch to a certain branch""" + def __init__(self, branch): + GitCommand.__init__(self, 'checkout', [branch]) + self.branch = branch + self.run_error = "Couldn't switch to %s branch" % self.branch + + +class GitPull(GitCommand): + """Wrap git-pull""" + def __init__(self, repo, branch): + GitCommand.__init__(self, 'pull', [repo, branch]) + self.run_error = "Couldn't pull %s to %s" % (branch, repo) + + +class GitTag(GitCommand): + """Wrap git-tag""" + def __init__(self, sign_tag=False, keyid=None): + GitCommand.__init__(self,'tag') + self.sign_tag = sign_tag + self.keyid = keyid + + def __call__(self, version, msg="Tagging %(version)s"): + self.run_error = "Couldn't tag %s" % (version,) + if self.sign_tag: + if self.keyid: + sign_opts = [ '-u', self.keyid ] + else: + sign_opts = [ '-s' ] + else: + sign_opts = [] + GitCommand.__call__(self, sign_opts+[ '-m', msg % locals(), version]) + + +class GitAdd(GitCommand): + """Wrap git-add to add new files""" + def __init__(self): + GitCommand.__init__(self,'add') + self.run_error = "Couldn't add files" + + +class GitCommitAll(GitCommand): + """Wrap git-commit to commit all changes""" + def __init__(self): + GitCommand.__init__(self, 'commit', ['-a']) + + def __call__(self, msg=''): + args = [ [], ['-m', msg] ][len(msg) > 0] + self.run_error = "Couldn't commit -a %s" % " ".join(args) + GitCommand.__call__(self, args) + + +# vim:et:ts=4:sw=4: diff --git a/gbp/config.py b/gbp/config.py index eeffd440..09297c6b 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -1,5 +1,6 @@ -# -*- coding: utf-8 -*- -# (C) 2006 Guido Guenther +# vim: set fileencoding=utf-8 : +# +# (C) 2006,2007 Guido Guenther """handles command line and config file option parsing for the gbp commands""" from optparse import OptionParser diff --git a/gbp/deb_utils.py b/gbp/deb_utils.py index 8121ca70..8c4fd917 100644 --- a/gbp/deb_utils.py +++ b/gbp/deb_utils.py @@ -1,5 +1,6 @@ -# -*- coding: utf-8 -*- -# (C) 2006 Guido Guenther +# vim: set fileencoding=utf-8 : +# +# (C) 2006,2007 Guido Guenther """provides some debian source package related helpers""" import email diff --git a/gbp/errors.py b/gbp/errors.py new file mode 100644 index 00000000..be92b99f --- /dev/null +++ b/gbp/errors.py @@ -0,0 +1,10 @@ +# vim: set fileencoding=utf-8 : +# +# (C) 2006,2007 Guido Guenther +"""Thinks common to all gbp commands""" + +class GbpError(Exception): + """Generic exception raised in git-buildpackage commands""" + pass + +# vim:et:ts=4:sw=4: diff --git a/gbp/git_utils.py b/gbp/git_utils.py index 4859a71d..19e280a1 100644 --- a/gbp/git_utils.py +++ b/gbp/git_utils.py @@ -1,6 +1,6 @@ -# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 : # -# (C) 2006 Guido Guenther +# (C) 2006,2007 Guido Guenther """provides some git repository related helpers""" import subprocess diff --git a/git-buildpackage b/git-buildpackage index 621c406a..aeb5d84c 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -1,7 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 : # -# (C) 2006 Guido Guenther +# (C) 2006,2007 Guido Guenther # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -18,21 +18,14 @@ # """run commands to build a debian package out of a git repository""" -import sys,os,os.path,pipes -from git_buildpackage import GitTag, Command, CommandExecFailed -from git_buildpackage.git_utils import (GitRepositoryError, - GitRepository, - build_tag) -from git_buildpackage.deb_utils import (parse_changelog, - is_native, - orig_file, - has_orig) -from git_buildpackage.config import GBPOptionParser - - -class GbpError(Exception): - """Generic exception raised in git-buildpackage commands""" - pass +import sys +import os, os.path +import pipes +from gbp.git_utils import (GitRepositoryError, GitRepository, build_tag) +from gbp.deb_utils import (parse_changelog, is_native, orig_file, has_orig) +from gbp.command_wrappers import (GitTag, Command, CommandExecFailed) +from gbp.config import GbpOptionParser +from gbp.errors import GbpError def create_orig(cp, dir, branch): @@ -64,7 +57,7 @@ def main(argv): if "--help" in dpkg_args: args.append('--help') - parser = GBPOptionParser(command=os.path.basename(argv[0]), prefix='git-') + parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='git-') parser.add_option("--git-ignore-new", action="store_true", dest="ignore_new", default=False, help="build with uncommited changes in the source tree") diff --git a/git-import-dsc b/git-import-dsc index 3bd2d50d..1e8e2ff8 100755 --- a/git-import-dsc +++ b/git-import-dsc @@ -1,8 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 : # -# -# (C) 2006 Guido Guenther +# (C) 2006,2007 Guido Guenther # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -23,10 +22,11 @@ import re import os import tempfile import glob -import git_buildpackage -from git_buildpackage.deb_utils import debian_version_chars -from git_buildpackage.git_utils import build_tag -from git_buildpackage.config import GBPOptionParser +import gbp.command_wrappers as gbpc +from gbp.deb_utils import debian_version_chars +from gbp.git_utils import build_tag +from gbp.config import GbpOptionParser +from gbp.errors import GbpError class DscFile(object): @@ -88,28 +88,28 @@ def import_upstream(src, dirs, options, tagger): debian native package and tag appropriately """ try: - unpackTGZ = git_buildpackage.UnpackTGZ(src.tgz, dirs['tmp']) + unpackTGZ = gbpc.UnpackTGZ(src.tgz, dirs['tmp']) unpackTGZ() - except git_buildpackage.CommandExecFailed: + except gbpc.CommandExecFailed: print >>sys.stderr,"Unpacking of %s failed" % src.tgz - git_buildpackage.RemoveTree(dirs['tmp'])() + gbpc.RemoveTree(dirs['tmp'])() return False try: dirs['git'] = glob.glob('%s/*' % unpackTGZ.dir)[0] os.chdir(dirs['git']) - git_buildpackage.GitInitDB()() - git_buildpackage.GitAdd()(['.']) - git_buildpackage.GitCommitAll()( + gbpc.GitInitDB()() + gbpc.GitAdd()(['.']) + gbpc.GitCommitAll()( msg="Imported %s version %s" % (['upstream', 'Debian'][src.native], src.upstream_version)) format = [options.upstream_tag, options.debian_tag][src.native] tagger(build_tag(format, src.upstream_version)) if not src.native: - git_buildpackage.GitBranch()(options.upstream_branch) - except git_buildpackage.CommandExecFailed: + gbpc.GitBranch()(options.upstream_branch) + except gbpc.CommandExecFailed: print >>sys.stderr,"Creation of git repository failed" - git_buildpackage.RemoveTree(unpackTGZ.dir)() + gbpc.RemoveTree(unpackTGZ.dir)() return False return True @@ -117,11 +117,11 @@ def import_upstream(src, dirs, options, tagger): def apply_debian_patch(src, dirs, options, tagger): """apply the debian patch and tag appropriately""" try: - git_buildpackage.DpkgSourceExtract()(src.dscfile, dirs['dpkg-src']) + gbpc.DpkgSourceExtract()(src.dscfile, dirs['dpkg-src']) os.chdir(dirs['git']) - git_buildpackage.GitLoadDirs()(dirs['dpkg-src'], 'Imported Debian patch') + gbpc.GitLoadDirs()(dirs['dpkg-src'], 'Imported Debian patch') tagger(build_tag(options.debian_tag, '%s-%s' % (src.upstream_version, src.debian_version))) - except git_buildpackage.CommandExecFailed: + except gbpc.CommandExecFailed: print >>sys.stderr,"Failed to import Debian package" return False return True @@ -136,14 +136,15 @@ def move_tree(src, dirs): os.path.abspath(src.pkg), err) return False else: - git_buildpackage.RemoveTree(dirs['tmp'])() + gbpc.RemoveTree(dirs['tmp'])() return True def main(argv): dirs = {'top': os.path.abspath(os.curdir)} + ret = 0 - parser = GBPOptionParser(command=os.path.basename(argv[0]), prefix='', + parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='', usage='%prog [options] /path/to/package.dsc') parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, @@ -161,33 +162,40 @@ def main(argv): (options, args) = parser.parse_args(argv[1:]) if options.verbose: - git_buildpackage.Command.verbose = True - - gitTag = git_buildpackage.GitTag(options.sign_tags, options.keyid) - - if len(args) != 1: - parser.print_help() - return 1 - else: - src = parse_dsc(args[0]) - if not src: - return 1 - - dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='.')) - if not import_upstream(src, dirs, options, gitTag): - return 1 - os.chdir(dirs['top']) - if not src.native: - dirs['unpack'] = os.path.join(dirs['tmp'], 'unpack') - os.mkdir(dirs['unpack']) - dirs['dpkg-src'] = os.path.join(dirs['unpack'], - "%s-%s-%s" % (src.pkg, src.upstream_version, src.debian_version)) - if not apply_debian_patch(src, dirs, options, gitTag): - return 1 - os.chdir(dirs['top']) - if not move_tree(src, dirs): - return 1 - print 'Everything imported under %s' % src.pkg + gbpc.Command.verbose = True + + gitTag = gbpc.GitTag(options.sign_tags, options.keyid) + + try: + if len(args) != 1: + parser.print_help() + raise GbpError + else: + src = parse_dsc(args[0]) + if not src: + raise GbpError + + dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='.')) + if not import_upstream(src, dirs, options, gitTag): + raise GbpError + os.chdir(dirs['top']) + if not src.native: + dirs['unpack'] = os.path.join(dirs['tmp'], 'unpack') + os.mkdir(dirs['unpack']) + dirs['dpkg-src'] = os.path.join(dirs['unpack'], + "%s-%s-%s" % (src.pkg, src.upstream_version, src.debian_version)) + if not apply_debian_patch(src, dirs, options, gitTag): + raise GbpError + os.chdir(dirs['top']) + if not move_tree(src, dirs): + raise GbpError + except GbpError, err: + if len(err.__str__()): + print >>sys.stderr, err + ret = 1 + + if not ret: + print 'Everything imported under %s' % src.pkg if __name__ == '__main__': sys.exit(main(sys.argv)) diff --git a/git-import-orig b/git-import-orig index 62935ef2..8dc0fba7 100755 --- a/git-import-orig +++ b/git-import-orig @@ -1,7 +1,7 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 : # -# (C) 2006 Guido Guenther +# (C) 2006,2007 Guido Guenther # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -23,26 +23,27 @@ import os import tempfile import re import glob -import git_buildpackage -from git_buildpackage.git_utils import (GitRepositoryError, - GitRepository, - build_tag) -from git_buildpackage.config import GBPOptionParser +import gbp.command_wrappers as gbpc +from gbp.git_utils import (GitRepositoryError, GitRepository, build_tag) +from gbp.config import GbpOptionParser +from gbp.errors import GbpError - -def cleanupTmpTree(tree): +def cleanup_tmp_tree(tree): """remove a tree of temporary files""" - git_buildpackage.RemoveTree(tree)() + try: + gbpc.RemoveTree(tree)() + except gbpc.CommandExecFailed: + print >>sys.stderr, "Removal of tmptree %s failed." % tree -def unpackOrig(tgz): +def unpack_orig(tgz): """unpack a .orig.tar.gz""" try: - unpackTGZ = git_buildpackage.UnpackTGZ(tgz, tempfile.mkdtemp(dir='../')) + unpackTGZ = gbpc.UnpackTGZ(tgz, tempfile.mkdtemp(dir='../')) unpackTGZ() - except git_buildpackage.CommandExecFailed: + except gbpc.CommandExecFailed: print "Unpacking of %s failed" % (tgz,) - cleanupTmpTree(unpackTGZ.dir) + cleanup_tmp_tree(unpackTGZ.dir) return return unpackTGZ.dir @@ -55,7 +56,10 @@ def get_version(tgz): return m.group('version') def main(argv): - parser = GBPOptionParser(command=os.path.basename(argv[0]), prefix='', + ret = 0 + tmpdir = '' + + parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='', usage='%prog [-u version] /path/to/upstream-version.tar.gz') parser.add_option("-u", "--upstreamversion", dest="version", @@ -76,80 +80,85 @@ def main(argv): help="Format string for upstream tags, default is '%(upstream-tag)s'") (options, args) = parser.parse_args(argv[1:]) - gitCheckoutUpstream = git_buildpackage.GitCheckoutBranch(options.upstream) - gitCheckoutMaster = git_buildpackage.GitCheckoutBranch(options.debian) - gitShowBranch = git_buildpackage.GitShowBranch() - gitPullUpstream = git_buildpackage.GitPull('.', options.upstream) + gitCheckoutUpstream = gbpc.GitCheckoutBranch(options.upstream) + gitCheckoutMaster = gbpc.GitCheckoutBranch(options.debian) + gitShowBranch = gbpc.GitShowBranch() + gitPullUpstream = gbpc.GitPull('.', options.upstream) - if options.verbose: - git_buildpackage.Command.verbose = True + try: + if options.verbose: + gbpc.Command.verbose = True - if len(args) != 1: - parser.print_help() - return 1 - else: - tgz = args[0] + if len(args) != 1: + parser.print_help() + raise GbpError + else: + tgz = args[0] - try: - repo = GitRepository('.') - except GitRepositoryError: - print >>sys.stderr,"%s is not a git repository" % (os.path.abspath('.')) - return 1 + try: + repo = GitRepository('.') + except GitRepositoryError: + raise GbpError, "%s is not a git repository" % (os.path.abspath('.')) - if not repo.has_branch(options.upstream): - print >>sys.stderr, """ + if not repo.has_branch(options.upstream): + print >>sys.stderr, """ Repository does not have branch '%s' for upstream sources. If there is none see -/usr/share/doc/git-buildpackage/manual-html/gbp.import.convert.html on howto +/usr/share/doc/git-buildpackage/manual-html/gbpc.import.convert.html on howto create it otherwise use --upstream-branch to specify it. """ % options.upstream - return 1 - - if options.version: - version = options.version - else: - version = get_version(tgz) - if version: - print "Upstream version is %s" % (version,) - else: - print >>sys.stderr,"Cannot determine upstream version from %s - use -u" % (tgz,) - parser.print_help() - return 1 - - (ret, out) = repo.is_clean() - if not ret: - print >>sys.stderr, "Repository has uncommitted changes, commit them first: " - print >>sys.stderr, out - return 1 - - tmpdir = unpackOrig(tgz) - if not tmpdir: - return 1 - else: - if options.verbose: - print "Unpacked orig to %s" % tmpdir - origdir = glob.glob(tmpdir+'/*')[0] - - try: - print "Importing %s to upstream branch..." % tgz - gitCheckoutUpstream() - gitShowBranch() - git_buildpackage.GitLoadDirs()(origdir) - git_buildpackage.GitTag(options.sign_tags, options.keyid)(build_tag(options.upstream_tag, version)) - - if options.merge: - print "Merging to %s" % (options.debian,) - gitCheckoutMaster() + raise GbpError + + if options.version: + version = options.version + else: + version = get_version(tgz) + + if version: + print "Upstream version is %s" % (version,) + else: + print >>sys.stderr,"Cannot determine upstream version from %s - use -u" % (tgz,) + parser.print_help() + raise GbpError + + (ret, out) = repo.is_clean() + if not ret: + print >>sys.stderr, "Repository has uncommitted changes, commit them first: " + raise GbpError, out + + tmpdir = unpack_orig(tgz) + if not tmpdir: + raise GbpError + else: + if options.verbose: + print "Unpacked orig to %s" % tmpdir + origdir = glob.glob(tmpdir+'/*')[0] + + try: + print "Importing %s to upstream branch..." % tgz + gitCheckoutUpstream() gitShowBranch() - gitPullUpstream() - git_buildpackage.Dch("%s-1" % (version,), 'New Upstream Version')() - except git_buildpackage.CommandExecFailed: - print >>sys.stderr, "Import of %s failed" % (tgz,) - cleanupTmpTree(tmpdir) - return 1 - cleanupTmpTree(tmpdir) - - print "Merged version %s of %s into ." % (version, tgz) - return 0 + gbpc.GitLoadDirs(verbose=options.verbose)(origdir) + gbpc.GitTag(options.sign_tags, options.keyid)(build_tag(options.upstream_tag, version)) + + if options.merge: + print "Merging to %s" % (options.debian,) + gitCheckoutMaster() + gitShowBranch() + gitPullUpstream() + gbpc.Dch("%s-1" % (version,), 'New Upstream Version')() + except gbpc.CommandExecFailed: + raise GbpError, "Import of %s failed" % tgz + except GbpError, err: + if len(err.__str__()): + print >>sys.stderr, err + ret = 1 + + if tmpdir: + cleanup_tmp_tree(tmpdir) + + if not ret: + print "Succesfully merged version %s of %s into ." % (version, tgz) + return ret if __name__ == "__main__": sys.exit(main(sys.argv)) diff --git a/setup.py b/setup.py index fa60981c..b8e373cf 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python2.3 -# Copyright (C) 2006 Guido Guenther +#!/usr/bin/python +# Copyright (C) 2006,2007 Guido Guenther # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ setup(name = "git_build_package", author = 'Guido Guenther', author_email = 'agx@sigxcpu.org', scripts = [ 'git-buildpackage', 'git-import-dsc', 'git-import-orig'], - packages = [ 'git_buildpackage' ], + packages = [ 'gbp' ], data_files = [("/etc/git-buildpackage/", ["gbp.conf" ]),], ) -- cgit v1.2.3