aboutsummaryrefslogtreecommitdiffhomepage
path: root/git-import-dsc
blob: 52b7b28baf6347dce73b0bcac542741e2d8cc10e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/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 <agx@sigxcpu.org>
#    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<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)')

    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: