3 # Create all the Release files
5 # Copyright (C) 2001, 2002, 2006 Anthony Towns <ajt@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ################################################################################
25 import sys, os, popen2, tempfile, stat, time, pg
29 ################################################################################
36 ################################################################################
38 def usage (exit_code=0):
39 print """Usage: dak generate-releases [OPTION]... [SUITE]...
40 Generate Release files (for SUITE).
42 -h, --help show this help and exit
43 -a, --apt-conf FILE use FILE instead of default apt.conf
44 -f, --force-touch ignore Untouchable directives in dak.conf
46 If no SUITE is given Release files are generated for all suites."""
50 ################################################################################
52 def add_tiffani (files, path, indexstem):
53 index = "%s.diff/Index" % (indexstem)
54 filepath = "%s/%s" % (path, index)
55 if os.path.exists(filepath):
56 #print "ALERT: there was a tiffani file %s" % (filepath)
59 def compressnames (tree,type,file):
60 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
63 uncompress = ("." not in cl)
64 for mode in compress.split():
69 result.append("<zcat/.gz>" + file)
71 result.append(file + ".gz")
74 result.append("<bzcat/.bz2>" + file)
76 result.append(file + ".bz2")
79 def create_temp_file (cmd):
80 f = tempfile.TemporaryFile()
81 r = popen2.popen2(cmd)
97 def print_md5sha_files (tree, files, hashop):
98 path = Cnf["Dir::Root"] + tree + "/"
104 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
105 (size, file_handle) = create_temp_file("%s %s%s%s" %
106 (cat, path, name, ext))
108 size = os.stat(path + name)[stat.ST_SIZE]
109 file_handle = daklib.utils.open_file(path + name)
110 except daklib.utils.cant_open_exc:
111 print "ALERT: Couldn't open " + path + name
113 hash = hashop(file_handle)
115 out.write(" %s %8d %s\n" % (hash, size, name))
117 def print_md5_files (tree, files):
118 print_md5sha_files (tree, files, apt_pkg.md5sum)
120 def print_sha1_files (tree, files):
121 print_md5sha_files (tree, files, apt_pkg.sha1sum)
123 def print_sha256_files (tree, files):
124 print_md5sha_files (tree, files, apt_pkg.sha256sum)
126 ################################################################################
129 global Cnf, AptCnf, projectB, out
132 Cnf = daklib.utils.get_conf()
134 Arguments = [('h',"help","Generate-Releases::Options::Help"),
135 ('a',"apt-conf","Generate-Releases::Options::Apt-Conf", "HasArg"),
136 ('f',"force-touch","Generate-Releases::Options::Force-Touch"),
138 for i in [ "help", "apt-conf", "force-touch" ]:
139 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
140 Cnf["Generate-Releases::Options::%s" % (i)] = ""
142 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
143 Options = Cnf.SubTree("Generate-Releases::Options")
148 if not Options["Apt-Conf"]:
149 Options["Apt-Conf"] = daklib.utils.which_apt_conf_file()
151 AptCnf = apt_pkg.newConfiguration()
152 apt_pkg.ReadConfigFileISC(AptCnf, Options["Apt-Conf"])
154 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
157 suites = Cnf.SubTree("Suite").List()
160 print "Processing: " + suite
161 SuiteBlock = Cnf.SubTree("Suite::" + suite)
163 if SuiteBlock.has_key("Untouchable") and not Options["Force-Touch"]:
164 print "Skipping: " + suite + " (untouchable)"
167 suite = suite.lower()
169 origin = SuiteBlock["Origin"]
170 label = SuiteBlock.get("Label", origin)
171 codename = SuiteBlock.get("CodeName", "")
176 q = projectB.query("SELECT version, description FROM suite WHERE suite_name = '%s'" % (suite))
179 if qs[0][0] != "-": version = qs[0][0]
180 if qs[0][1]: description = qs[0][1]
182 if SuiteBlock.has_key("NotAutomatic"):
187 if SuiteBlock.has_key("Components"):
188 components = SuiteBlock.ValueList("Components")
192 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
193 if components and suite_suffix:
194 longsuite = suite + "/" + suite_suffix
198 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
200 if AptCnf.has_key("tree::%s" % (tree)):
202 elif AptCnf.has_key("bindirectory::%s" % (tree)):
205 aptcnf_filename = os.path.basename(daklib.utils.which_apt_conf_file())
206 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
209 print Cnf["Dir::Root"] + tree + "/Release"
210 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
212 out.write("Origin: %s\n" % (origin))
213 out.write("Label: %s\n" % (label))
214 out.write("Suite: %s\n" % (suite))
216 out.write("Version: %s\n" % (version))
218 out.write("Codename: %s\n" % (codename))
219 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
220 if notautomatic != "":
221 out.write("NotAutomatic: %s\n" % (notautomatic))
222 out.write("Architectures: %s\n" % (" ".join(filter(daklib.utils.real_arch, SuiteBlock.ValueList("Architectures")))))
224 out.write("Components: %s\n" % (" ".join(components)))
227 out.write("Description: %s\n" % (description))
231 if AptCnf.has_key("tree::%s" % (tree)):
232 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
233 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
235 filepath = "%s/%s/Sources" % (sec, arch)
236 for file in compressnames("tree::%s" % (tree), "Sources", filepath):
238 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
240 disks = "%s/disks-%s" % (sec, arch)
241 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
242 if os.path.exists(diskspath):
243 for dir in os.listdir(diskspath):
244 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
245 files.append("%s/%s/md5sum.txt" % (disks, dir))
247 filepath = "%s/binary-%s/Packages" % (sec, arch)
248 for file in compressnames("tree::%s" % (tree), "Packages", filepath):
250 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
253 rel = "%s/%s/Release" % (sec, arch)
255 rel = "%s/binary-%s/Release" % (sec, arch)
256 relpath = Cnf["Dir::Root"]+tree+"/"+rel
259 if os.access(relpath, os.F_OK):
260 if os.stat(relpath).st_nlink > 1:
262 release = open(relpath, "w")
263 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
265 daklib.utils.fubar("Couldn't write to " + relpath)
267 release.write("Archive: %s\n" % (suite))
269 release.write("Version: %s\n" % (version))
271 release.write("Component: %s/%s\n" % (suite_suffix,sec))
273 release.write("Component: %s\n" % (sec))
274 release.write("Origin: %s\n" % (origin))
275 release.write("Label: %s\n" % (label))
276 if notautomatic != "":
277 release.write("NotAutomatic: %s\n" % (notautomatic))
278 release.write("Architecture: %s\n" % (arch))
282 if AptCnf.has_key("tree::%s/main" % (tree)):
283 for dis in ["main", "contrib", "non-free"]:
284 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
285 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
286 if sec != "debian-installer":
287 print "ALERT: weird non debian-installer section in %s" % (tree)
289 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
290 if arch != "source": # always true
291 for file in compressnames("tree::%s/%s" % (tree,dis),
293 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
295 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
296 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
297 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
298 if sec != "debian-installer":
299 print "ALERT: weird non debian-installer section in %s" % (usetree)
301 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
302 if arch != "source": # always true
303 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
306 elif AptCnf.has_key("bindirectory::%s" % (tree)):
307 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
308 files.append(file.replace(tree+"/","",1))
309 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
310 files.append(file.replace(tree+"/","",1))
312 print "ALERT: no tree/bindirectory for %s" % (tree)
314 out.write("MD5Sum:\n")
315 print_md5_files(tree, files)
317 print_sha1_files(tree, files)
318 out.write("SHA256:\n")
319 print_sha256_files(tree, files)
322 if Cnf.has_key("Dinstall::SigningKeyring"):
323 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
324 if Cnf.has_key("Dinstall::SigningPubKeyring"):
325 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
327 arguments = "--no-options --batch --no-tty --armour"
328 if Cnf.has_key("Dinstall::SigningKeyIds"):
329 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
333 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
334 if os.path.exists(dest):
337 for keyid in signkeyids:
338 if keyid != "": defkeyid = "--default-key %s" % keyid
340 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
341 (keyring, defkeyid, arguments,
342 Cnf["Dir::Root"] + tree + "/Release", dest))
344 #######################################################################################
346 if __name__ == '__main__':