diff options
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debian/pyversions | 2 | ||||
-rwxr-xr-x | git-buildpackage | 8 | ||||
-rwxr-xr-x | git-import-dsc | 147 | ||||
-rwxr-xr-x | git-import-orig | 89 | ||||
-rw-r--r-- | git_buildpackage.py | 150 | ||||
-rw-r--r-- | setup.py | 3 |
10 files changed, 271 insertions, 144 deletions
@@ -13,5 +13,6 @@ This is a bunch of scripts to ease the development of Debian packages with git: --git-ignore-new: ignore uncommited changes --git-tag: tag after building (version number is fetched from the changelog) -To import new upstream sources you can use tla-load-dirs from Debian with this patch: +To import new upstream sources tla-load-dirs from Debian with this patch (to +add a git-load-dirs command) is used: http://honk.sigxcpu.org/unsorted-patches/tla-load-dir_git-support.diff @@ -1,9 +1,6 @@ - git-import-dsc: - - error handling - - better use 'dpkg-source -x' - - import debian native packages - - use classes from git-import-orig - allow to set use individual branch names - git-import-orig: - allow to set use individual branch names - git-buildpackage: + - allow to export the hole source tree to tmpdir before building diff --git a/debian/changelog b/debian/changelog index ce31a69a..5149bcb4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +git-buildpackage (0.2) git-buildpackage; urgency=low + + * git-import-dsc: import of debian native packages + + -- Guido Guenther <agx@sigxcpu.org> Wed, 27 Sep 2006 00:40:46 +0200 + git-buildpackage (0.01) unstable; urgency=low * Initial release diff --git a/debian/control b/debian/control index 0ae2934d..3f292e01 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Package: git-buildpackage Architecture: all Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, devscripts, git-load-dirs Description: bunch of scripts to ease the development of Debian packages with git - This package contains the following tools: + This package contains the following tools: * git-import-dsc: import an existing Debian source package into a git repository * git-import-orig: import a new upstream version into the git repository diff --git a/debian/pyversions b/debian/pyversions index 6b4950e3..8b253bc3 100644 --- a/debian/pyversions +++ b/debian/pyversions @@ -1 +1 @@ -2.4 +2.4- diff --git a/git-buildpackage b/git-buildpackage index ecf58d25..ba1daaea 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -54,21 +54,21 @@ def main(argv): clean_cmd='%s clean' % options.build_cmd if not options.ignore_new: - if not exec_command(clean_cmd)[0]: sys.exit(1) + if not exec_command(clean_cmd)[0]: return 1 (status, out) = commands.getstatusoutput('git status') msgs=out.split('\n') if msgs[0] != 'nothing to commit': print "You have uncommitted changes in your source tree:" print out print "Use --git-ignore_new to override" - sys.exit(1) + return 1 cmd=options.build_cmd+' -i.git '+" ".join(dpkg_args) - if not exec_command(cmd)[0]: sys.exit(1) + if not exec_command(cmd)[0]: return 1 if options.tag: version=get_version() if version: print "Tagging", version - if not exec_command('git-tag %s' % version)[0]: sys.exit(1) + if not exec_command('git-tag %s' % version)[0]: return 1 else: print >>sys.stderr,"Can't parse version from changes file" diff --git a/git-import-dsc b/git-import-dsc index 7b48238e..abc10cc8 100755 --- a/git-import-dsc +++ b/git-import-dsc @@ -17,80 +17,125 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -import sys,re,os,tempfile,glob +import sys +import re +import os +import tempfile +import glob +from optparse import OptionParser +from git_buildpackage import * -class CorruptDsc: - pass +gitAdd=GitAdd() +gitCommitAll=GitCommitAll() +gitTag=GitTag() class DscPackage(object): + """Parse the dsc file for verions, package names, etc""" pkgre=re.compile('Source: (?P<pkg>[\w\-]+)') - versionre=re.compile('Version: (?P<upstream>[a-z\d\-\.]+)-(?P<debian>[a-z\d\.~]+)') - origre=re.compile('^ [\da-z]+ \d+ (?P<orig>[a-z\d-]+_[a-z\d\.\~\-]+\.orig\.tar\.gz)') - diffre=re.compile('^ [\da-z]+ \d+ (?P<diff>[a-z\d-]+_[a-z\d\.\~\-]+\.diff\.gz)') + versionre=re.compile('Version: (?P<upstream>[a-z\d\.]+)(-(?P<debian>[a-z\d\.~]+))?') + tarre=re.compile ('^ [\da-z]+ \d+ (?P<tar>[a-z\d-]+_[a-z\d\.\~\-]+(\.orig)?\.tar\.gz)') def __init__(self, dscfile): - self.dscfile=dscfile + self.dscfile=os.path.abspath(dscfile) f=file(self.dscfile) for line in f: m=self.versionre.match(line) if m: self.upstream_version = m.group('upstream') - self.debian_version = m.group('debian') + if m.group('debian'): + self.debian_version = m.group('debian') + self.native = False + else: + print "Debian Native Package" + self.native = True # Debian native package continue m=self.pkgre.match(line) - if m: - self.pkg= m.group('pkg') - continue - m=self.origre.match(line) if m: - self.orig = m.group('orig') + self.pkg= m.group('pkg') continue - m=self.diffre.match(line) + m=self.tarre.match(line) if m: - self.diff = m.group('diff') + self.tgz= os.path.dirname(dscfile)+'/'+m.group('tar') continue f.close() - self.workdir='' -def import_upstream(src): - src.tempdir=tempfile.mkdtemp(dir='.') - os.system('tar -C %s -zxf %s' % (src.tempdir, src.orig)) - src.workdir=glob.glob('%s/*' % (src.tempdir, ))[0] - os.chdir(src.workdir) - os.system('git-init-db') - os.system('git-add .') - os.system('git-commit -m"Imported upstream version %s"' % (src.upstream_version, )) - os.system('git-tag %s' % (src.upstream_version, )) - os.system('git-branch upstream') # create upstream branch - -def apply_debian_patch(src): - os.system('gunzip -c ../../%s | patch -p1' % (src.diff, )) - os.chmod('debian/rules', 0755) - os.system('git-add .') - os.system('git-commit -a -m"import debian debian patch"') - os.system('git-tag %s-%s' % (src.upstream_version, src.debian_version)) - -def move_tree(src): - os.chdir('../..') - os.rename(src.workdir, src.pkg) - os.rmdir(src.tempdir) - -def usage(): - print >>sys.stderr,'Usage: gbp-import-dsc dscfile' + +def import_upstream(src, dirs): + try: + unpackTGZ=UnpackTGZ(src.tgz, dirs['tmp']) + unpackTGZ() + except CommandExecFailed: + print >>sys.stderr,"Unpacking of %s failed" % (src.tgz,) + RemoveTree(dirs['tmp'])() + return 1 + + try: + dirs['git']=glob.glob('%s/*' % (unpackTGZ.dir, ))[0] + os.chdir(dirs['git']) + GitInitDB()() + gitAdd(['.']) + gitCommitAll(msg="Imported upstream version %s" % (src.upstream_version,)) + gitTag(src.upstream_version) + if not src.native: + GitBranch()('upstream') + except CommandExecFailed: + print >>sys.stderr,"Creation of git repository failed" + RemoveTree(unpackTGZ.dir)() + return 1 + return 0 + + +def apply_debian_patch(src, dirs): + try: + DpkgSourceExtract()(src.dscfile, dirs['dpkg-src']) + os.chdir(dirs['git']) + GitLoadDirs()(dirs['dpkg-src'], 'Imported debian patch') + gitTag('%s-%s' % (src.upstream_version, src.debian_version)) + except CommandExecFailed: + print >>sys.stderr,"Failed to import debian package" + return 1 + return 0 + + +def move_tree(src, dirs): + os.rename(dirs['git'], src.pkg) + RemoveTree(dirs['tmp'])() + + +def usage(parser): + parser.print_help() sys.exit(0) + def main(argv): - if len(argv) != 2: - usage() + dirs={'top': os.path.abspath(os.curdir)} + + parser = OptionParser('%prog [options] /path/to/package.dsc') + + parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") + (options, args) = parser.parse_args() + + if options.verbose: + Command.verbose = True + + if len(args) != 1: + usage(parser) else: - try: - src=DscPackage(argv[1]) - except CorruptDsc: - print >>sys.stderr,"Dsc corrupt" - sys.exit(1) - import_upstream(src) - apply_debian_patch(src) - move_tree(src) + src=DscPackage(args[0]) + + dirs['tmp']=os.path.abspath(tempfile.mkdtemp(dir='.')) + if import_upstream(src, dirs): + return 1 + os.chdir(dirs['top']) + if not src.native: + dirs['unpack']=dirs['tmp']+'/unpack' + os.mkdir(dirs['unpack']) + dirs['dpkg-src']="%s/%s-%s-%s" % (dirs['unpack'], src.pkg, src.upstream_version, src.debian_version) + if apply_debian_patch(src, dirs): + return 1 + os.chdir(dirs['top']) + move_tree(src, dirs) print 'Everything imported under %s' % (src.pkg, ) if __name__ == '__main__': diff --git a/git-import-orig b/git-import-orig index 273a2de3..44319c5e 100755 --- a/git-import-orig +++ b/git-import-orig @@ -19,90 +19,12 @@ import sys import os -import subprocess import tempfile import re import glob from optparse import OptionParser +from git_buildpackage import * -class CommandExecFailed: - pass - -class Command(object): - def __init__(self, cmd, args=[]): - self.cmd=cmd - self.args=args - - def run(self): - try: - retcode = subprocess.call([self.cmd]+self.args) - 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 - return retcode - - def __call__(self): - if self.run(): - raise CommandExecFailed - - -class UnpackTGZ(Command): - 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", self.tgz - -class RemoveTree(Command): - "Remove a whole directory tree" - def __init__(self, tree): - self.tree=tree - Command.__init__(self, 'rm', [ '-rf', tree ]) - self.run_error="Couldn't remove ", self.tree - -class Dch(Command): - def __init__(self, version, msg): - args=['-v', version] - if msg: - args.append(msg) - Command.__init__(self, 'dch', args) - self.run_error="Dch failed." - -class GitLoadDirs(Command): - def __init__(self, upstream_dir): - self.upstream_dir=upstream_dir - Command.__init__(self, 'git_load_dirs', [ self.upstream_dir ]) - self.run_error="Couldn't import %s", self.upstream_dir - -class GitCommand(Command): - "Mother/Father of all git commands" - def __init__(self, cmd, args=[]): - Command.__init__(self, 'git-'+cmd, args) - -class GitShowBranch(GitCommand): - def __init__(self): - GitCommand.__init__(self,'branch') - self.run_error="Couldn't list branches" - -class GitCheckoutBranch(GitCommand): - 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): - 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): - def __init__(self, version): - GitCommand.__init__(self,'tag', [version]) - self.run_error="Couldn't tag %s" % (version,) # Used GIT Commands gitCheckoutUpstream=GitCheckoutBranch('upstream') @@ -136,8 +58,13 @@ def main(): parser.add_option("-u", "--upstreamversion", dest="version", help="Upstream Version") + parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, + help="verbose command execution") (options, args) = parser.parse_args() + if options.verbose: + Command.verbose = True + if len(args) != 1: parser.print_help() return 1 @@ -172,8 +99,8 @@ def main(): print "Importing %s to upstream branch..." % (tgz,) gitCheckoutUpstream() gitShowBranch() - GitLoadDirs(origdir)() - GitTag(version)() + GitLoadDirs()(origdir) + GitTag()(version) print "Merging to master..." gitCheckoutMaster() diff --git a/git_buildpackage.py b/git_buildpackage.py new file mode 100644 index 00000000..d046c7f6 --- /dev/null +++ b/git_buildpackage.py @@ -0,0 +1,150 @@ +# helper classes for git-buildpackge and friends +# (C) 2006 Guido Guenther <agx@sigxcpu.org> + +import subprocess +import sys + +class CommandExecFailed(Exception): + pass + +class Command(object): + verbose=False + + def __init__(self, cmd, args=[]): + self.cmd=cmd + self.args=args + + def __run(self, args): + try: + if self.verbose: + print self.cmd, self.args, args + retcode = subprocess.call([self.cmd]+self.args+args) + 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): + 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): + "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): + 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): + 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): + 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): + def __init__(self): + GitCommand.__init__(self,'init-db') + self.run_error="Couldn't init git repository" + + +class GitShowBranch(GitCommand): + def __init__(self): + GitCommand.__init__(self,'branch') + self.run_error="Couldn't list branches" + + +class GitBranch(GitCommand): + 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): + 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): + 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): + def __init__(self): + GitCommand.__init__(self,'tag') + + def __call__(self, tag): + self.run_error="Couldn't tag %s" % (tag,) + GitCommand.__call__(self, [tag]) + + +class GitAdd(GitCommand): + """add a lists of files""" + def __init__(self): + GitCommand.__init__(self,'add') + self.run_error="Couldn't add files" + + +class GitCommitAll(GitCommand): + """Commit files to the repository""" + 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: @@ -21,6 +21,7 @@ from distutils.core import setup setup(name = "git_build_package", author = 'Guido Guenther', author_email = 'agx@sigxcpu.org', - scripts = [ 'git-buildpackage', 'git-import-dsc', 'git-import-orig'] + scripts = [ 'git-buildpackage', 'git-import-dsc', 'git-import-orig'], + py_modules = [ 'git_buildpackage' ] ) |