/[ascend]/trunk/tools/dtar/dtar
ViewVC logotype

Contents of /trunk/tools/dtar/dtar

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1819 - (show annotations) (download)
Sat Aug 16 07:51:31 2008 UTC (11 years, 2 months ago) by jpye
File size: 4252 byte(s)
Fix for tarball missing debian files.
1 #!/usr/bin/env python
2 # dtar - Tool to produce .deb package from source tarball
3 # Copyright (C) 2008 John Pye <john@curioussymbols.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19
20 import sys, re, tarfile, os.path, subprocess
21 import apt
22 from debian_bundle import deb822, changelog
23
24 # the tarball is the argument to this script
25 f = sys.argv[1]
26
27 # get the first filename in the tarball
28 t = tarfile.open(f)
29 M = t.getmembers()
30 print M[0].name
31
32 # split the top-level directory name from that path
33
34 h,path = os.path.split(M[0].name)
35 if not h:
36 raise RuntimeError("Tarball appears not contain a top-level directory")
37
38 while h:
39 head = h
40 h,path = os.path.split(path)
41
42 print "Head directory = ",head
43
44 r = re.compile(r"^%s/debian/(.*)$" % re.escape(head))
45
46 # search for 'debian/changelog' inside the tarfile
47
48 debfiles = {}
49 for m in M:
50 if r.match(m.name):
51 h,p = os.path.split(m.name)
52 debfiles[p] = m
53
54 mandatorydebfiles = ['control','changelog','rules']
55
56 missingdebfiles = []
57 for _f in mandatorydebfiles:
58 if _f not in debfiles:
59 missingdebfiles.append(_f)
60 if missingdebfiles:
61 s = "Tarball is missing required debian/* files: %s" %missingdebfiles
62 raise RuntimeError(s)
63
64 fc = t.extractfile(debfiles['control'])
65
66 # display mandatory fields from 'debian/control'
67
68 controlmandatory = ['Source','Maintainer']
69
70 control = deb822.Deb822(fc.read())
71 for _c in controlmandatory:
72 print "%s: %s" % (_c, control[_c])
73
74 # check that debian/changelog is current
75
76 fchange = t.extractfile(debfiles['changelog'])
77
78 changes = changelog.Changelog(file=fchange.read())
79
80 debianname = "%s-%s" % (control['Source'],changes.upstream_version)
81
82 if debianname != head:
83 raise RuntimeError("Debian files not up to date: debian/changelog refers to version '%s' but tarball head directory is '%s'"
84 % (debianname,head));
85
86 # check for build-time dependencies
87
88 dependencies = ['build-essential']
89
90 if 'Build-Depends' in control:
91 #print "Build-Depends:",control['Build-Depends']
92 c = apt.Cache()
93 dependencies += control['Build-Depends'].split(', ')
94
95 print "Checking build dependencies..."
96 depsmissing = []
97 for d in dependencies:
98 p = c[d]
99 if not p.isInstalled:
100 depsmissing.append(d)
101
102 if depsmissing:
103 raise RuntimeError("Unable to proceed. Missing buildtime dependencies: %s" % (depsmissing))
104
105 # original tarball (recompressing to .gz if required)
106
107 if f[-3:] == ".gz":
108 print "Original tarball is in gzip format"
109 elif f[-4:] == ".bz2":
110 print "Original tarball is in bzip2 format"
111 else:
112 raise RuntimeError("Unrecognized tarball compression style")
113
114 # extract tarball to tmp dir
115
116 maindir = "/tmp/dtar-%s" % os.getpid()
117
118 print "Extracting tarball to '%s'..." % maindir
119
120 if os.path.exists(maindir):
121 raise RuntimeError("Temp path '%s' already exists!"%maindir)
122
123 os.mkdir(maindir)
124
125 try:
126 os.chdir(maindir)
127 t.extractall()
128 assert(os.path.exists(head))
129 print "Files extracted to '%s'" % os.getcwd()
130
131 # build the source package
132 print "Building source package..."
133 res = subprocess.call(["dpkg-source","-b",head,f],executable="/usr/bin/dpkg-source")
134
135 if res:
136 raise RuntimeError("dpkg-source returned error code %d",res)
137
138 # build the binary package
139 print "Building binary package..."
140 os.chdir(head)
141 res = subprocess.call(["dpkg-buildpackage","-b","-rfakeroot"])
142
143 except Exception, e:
144 print "ERROR: %s", str(e)
145
146 #clean up files
147
148 print "EXITING now"
149 sys.exit(1)
150
151 print "Cleaning up files..."
152 assert maindir[:10]=="/tmp/dtar-"
153 for _root,_dirs,_files in os.walk(maindir,topdown=False):
154 for _f in _files:
155 os.remove(os.path.join(_root,_f))
156 for _d in _dirs:
157 os.rmdir(os.path.join(_root,_d))
158 print "All done, exiting"
159
160 os.rmdir(maindir)

Properties

Name Value
svn:executable *

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22