#!/usr/bin/python # # make a git archive out of a Debian source package # # FIXME: - error handling # - better use 'dpkg-source -x' # - import debian native packages # # (C) 2006 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 # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # 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 class CorruptDsc: pass class DscPackage(object): pkgre=re.compile('Source: (?P[\w\-]+)') versionre=re.compile('Version: (?P[a-z\d\-\.]+)-(?P[a-z\d\.~]+)') origre=re.compile('^ [\da-z]+ \d+ (?P[a-z\d-]+_[a-z\d\.\~\-]+\.orig\.tar\.gz)') diffre=re.compile('^ [\da-z]+ \d+ (?P[a-z\d-]+_[a-z\d\.\~\-]+\.diff\.gz)') def __init__(self, dscfile): self.dscfile=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') 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') continue m=self.diffre.match(line) if m: self.diff = m.group('diff') 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' sys.exit(0) def main(argv): if len(argv) != 2: usage() 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) print 'Everything imported under %s' % (src.pkg, ) if __name__ == '__main__': sys.exit(main(sys.argv)) # vim:et:ts=4:sw=4: