4 Functions related debian binary packages
6 @contact: Debian FTPMaster <ftpmaster@debian.org>
7 @copyright: 2009 Mike O'Connor <stew@debian.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 ################################################################################
27 # <Ganneff> are we going the xorg way?
28 # <Ganneff> a dak without a dak.conf?
29 # <stew> automatically detect the wrong settings at runtime?
31 # <mhy> well, we'll probably always need dak.conf (how do you get the database setting
32 # <mhy> but removing most of the config into the database seems sane
33 # <Ganneff> mhy: dont spoil the fun
34 # <Ganneff> mhy: and i know how. we nmap localhost and check all open ports
35 # <Ganneff> maybe one answers to sql
36 # <stew> we will discover projectb via avahi
37 # <mhy> you're both sick
38 # <mhy> really fucking sick
40 ################################################################################
50 from debian_bundle import deb822
51 from dbconn import DBConn
52 from config import Config
57 def __init__(self, filename, reject=None):
59 @ptype filename: string
60 @param filename: path of a .deb
62 @ptype reject: function
63 @param reject: a function to log reject messages to
65 self.filename = filename
68 self.wrapped_reject = reject
70 def reject(self, message):
72 if we were given a reject function, send the reject message,
73 otherwise send it to stderr.
75 if self.wrapped_reject:
76 self.wrapped_reject(message)
78 print >> sys.stderr, message
82 make sure we cleanup when we are garbage collected.
88 we need to remove the temporary directory, if we created one
90 if self.tmpdir and os.path.exists(self.tmpdir):
91 shutil.rmtree(self.tmpdir)
95 # get a list of the ar contents
98 cmd = "ar t %s" % (self.filename)
99 (result, output) = commands.getstatusoutput(cmd)
102 print("%s: 'ar t' invocation failed." % (self.filename))
103 self.reject("%s: 'ar t' invocation failed." % (self.filename))
104 self.reject(utils.prefix_multi_line_string(output, " [ar output:] "))
105 self.chunks = output.split('\n')
110 # Internal function which extracts the contents of the .ar to
111 # a temporary directory
114 tmpdir = utils.temp_dirname()
118 cmd = "ar x %s %s %s" % (os.path.join(cwd,self.filename), self.chunks[1], self.chunks[2])
119 (result, output) = commands.getstatusoutput(cmd)
121 print("%s: '%s' invocation failed." % (self.filename, cmd))
122 self.reject("%s: '%s' invocation failed." % (self.filename, cmd))
123 self.reject(utils.prefix_multi_line_string(output, " [ar output:] "))
126 atexit.register( self._cleanup )
133 Check deb contents making sure the .deb contains:
136 3. data.tar.gz or data.tar.bz2
137 in that order, and nothing else.
140 rejected = not self.chunks
141 if len(self.chunks) != 3:
143 self.reject("%s: found %d chunks, expected 3." % (self.filename, len(self.chunks)))
144 if self.chunks[0] != "debian-binary":
146 self.reject("%s: first chunk is '%s', expected 'debian-binary'." % (self.filename, self.chunks[0]))
147 if not rejected and self.chunks[1] != "control.tar.gz":
149 self.reject("%s: second chunk is '%s', expected 'control.tar.gz'." % (self.filename, self.chunks[1]))
150 if not rejected and self.chunks[2] not in [ "data.tar.bz2", "data.tar.gz" ]:
152 self.reject("%s: third chunk is '%s', expected 'data.tar.gz' or 'data.tar.bz2'." % (self.filename, self.chunks[2]))
156 def scan_package(self, bootstrap_id=0):
158 Unpack the .deb, do sanity checking, and gather info from it.
160 Currently information gathering consists of getting the contents list. In
161 the hopefully near future, it should also include gathering info from the
164 @ptype bootstrap_id: int
165 @param bootstrap_id: the id of the binary these packages
166 should be associated or zero meaning we are not bootstrapping
167 so insert into a temporary table
169 @return True if the deb is valid and contents were imported
172 rejected = not self.valid_deb()
178 if not rejected and self.tmpdir:
180 os.chdir(self.tmpdir)
181 if self.chunks[1] == "control.tar.gz":
182 control = tarfile.open(os.path.join(self.tmpdir, "control.tar.gz" ), "r:gz")
183 control.extract('./control', self.tmpdir )
184 if self.chunks[2] == "data.tar.gz":
185 data = tarfile.open(os.path.join(self.tmpdir, "data.tar.gz"), "r:gz")
186 elif self.chunks[2] == "data.tar.bz2":
187 data = tarfile.open(os.path.join(self.tmpdir, "data.tar.bz2" ), "r:bz2")
190 result = DBConn().insert_content_paths(bootstrap_id, [tarinfo.name for tarinfo in data if not tarinfo.isdir()])
192 pkgs = deb822.Packages.iter_paragraphs(file(os.path.join(self.tmpdir,'control')))
194 result = DBConn().insert_pending_content_paths(pkg, [tarinfo.name for tarinfo in data if not tarinfo.isdir()])
197 traceback.print_exc()
202 def check_utf8_package(self, package):
204 Unpack the .deb, do sanity checking, and gather info from it.
206 Currently information gathering consists of getting the contents list. In
207 the hopefully near future, it should also include gathering info from the
210 @ptype bootstrap_id: int
211 @param bootstrap_id: the id of the binary these packages
212 should be associated or zero meaning we are not bootstrapping
213 so insert into a temporary table
215 @return True if the deb is valid and contents were imported
217 rejected = not self.valid_deb()
220 if not rejected and self.tmpdir:
223 os.chdir(self.tmpdir)
224 if self.chunks[1] == "control.tar.gz":
225 control = tarfile.open(os.path.join(self.tmpdir, "control.tar.gz" ), "r:gz")
226 control.extract('control', self.tmpdir )
227 if self.chunks[2] == "data.tar.gz":
228 data = tarfile.open(os.path.join(self.tmpdir, "data.tar.gz"), "r:gz")
229 elif self.chunks[2] == "data.tar.bz2":
230 data = tarfile.open(os.path.join(self.tmpdir, "data.tar.bz2" ), "r:bz2")
234 unicode( tarinfo.name )
236 print >> sys.stderr, "E: %s has non-unicode filename: %s" % (package,tarinfo.name)
239 traceback.print_exc()
244 if __name__ == "__main__":
245 Binary( "/srv/ftp.debian.org/queue/accepted/halevt_0.1.3-2_amd64.deb" ).scan_package()