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, stat, time, pg
29 from daklib import utils
30 from daklib.dak_exceptions import *
31 from daklib.dbconn import *
33 ################################################################################
39 ################################################################################
41 def usage (exit_code=0):
42 print """Usage: dak generate-releases [OPTION]... [SUITE]...
43 Generate Release files (for SUITE).
45 -h, --help show this help and exit
46 -a, --apt-conf FILE use FILE instead of default apt.conf
47 -f, --force-touch ignore Untouchable directives in dak.conf
49 If no SUITE is given Release files are generated for all suites."""
53 ################################################################################
55 def add_tiffani (files, path, indexstem):
56 index = "%s.diff/Index" % (indexstem)
57 filepath = "%s/%s" % (path, index)
58 if os.path.exists(filepath):
59 #print "ALERT: there was a tiffani file %s" % (filepath)
62 def compressnames (tree,type,file):
63 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
66 uncompress = ("." not in cl)
67 for mode in compress.split():
72 result.append("<zcat/.gz>" + file)
74 result.append(file + ".gz")
77 result.append("<bzcat/.bz2>" + file)
79 result.append(file + ".bz2")
82 decompressors = { 'zcat' : gzip.GzipFile,
83 'bzip2' : bz2.BZ2File }
85 def print_md5sha_files (tree, files, hashop):
86 path = Cnf["Dir::Root"] + tree + "/"
94 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
95 file_handle = decompressors[ cat ]( "%s%s%s" % (path, name, ext) )
96 contents = file_handle.read()
97 hashvalue = hashop(contents)
98 hashlen = len(contents)
101 file_handle = utils.open_file(path + name)
102 hashvalue = hashop(file_handle)
103 hashlen = os.stat(path + name).st_size
110 except CantOpenError:
111 print "ALERT: Couldn't open " + path + name
113 out.write(" %s %8d %s\n" % (hashvalue, hashlen, name))
115 def print_md5_files (tree, files):
116 print_md5sha_files (tree, files, apt_pkg.md5sum)
118 def print_sha1_files (tree, files):
119 print_md5sha_files (tree, files, apt_pkg.sha1sum)
121 def print_sha256_files (tree, files):
122 print_md5sha_files (tree, files, apt_pkg.sha256sum)
124 def write_release_file (relpath, suite, component, origin, label, arch, version="", suite_suffix="", notautomatic=""):
126 if os.access(relpath, os.F_OK):
127 if os.stat(relpath).st_nlink > 1:
129 release = open(relpath, "w")
131 utils.fubar("Couldn't write to " + relpath)
133 release.write("Archive: %s\n" % (suite))
135 release.write("Version: %s\n" % (version))
138 release.write("Component: %s/%s\n" % (suite_suffix,component))
140 release.write("Component: %s\n" % (component))
142 release.write("Origin: %s\n" % (origin))
143 release.write("Label: %s\n" % (label))
144 if notautomatic != "":
145 release.write("NotAutomatic: %s\n" % (notautomatic))
146 release.write("Architecture: %s\n" % (arch))
149 ################################################################################
152 global Cnf, AptCnf, out
155 Cnf = utils.get_conf()
157 Arguments = [('h',"help","Generate-Releases::Options::Help"),
158 ('a',"apt-conf","Generate-Releases::Options::Apt-Conf", "HasArg"),
159 ('f',"force-touch","Generate-Releases::Options::Force-Touch"),
161 for i in [ "help", "apt-conf", "force-touch" ]:
162 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
163 Cnf["Generate-Releases::Options::%s" % (i)] = ""
165 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
166 Options = Cnf.SubTree("Generate-Releases::Options")
171 if not Options["Apt-Conf"]:
172 Options["Apt-Conf"] = utils.which_apt_conf_file()
174 AptCnf = apt_pkg.newConfiguration()
175 apt_pkg.ReadConfigFileISC(AptCnf, Options["Apt-Conf"])
178 suites = Cnf.SubTree("Suite").List()
180 for suitename in suites:
181 print "Processing: " + suitename
182 SuiteBlock = Cnf.SubTree("Suite::" + suite)
183 suiteobj = get_suite(suitename)
185 suite = suite.suite_name.lower()
187 if suite.untouchable and not Options["Force-Touch"]:
188 print "Skipping: " + suite + " (untouchable)"
191 origin = suite.origin
192 label = suite.label or suite.origin
193 codename = suite.codename or ""
195 if suite.version and suite.version != '-':
196 version = suite.version
197 description = suite.description or ""
199 architectures = get_suite_architectures(suite, skipall=True, skipsrc=True)
201 if SuiteBlock.has_key("NotAutomatic"):
206 if SuiteBlock.has_key("Components"):
207 components = SuiteBlock.ValueList("Components")
211 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
212 if components and suite_suffix:
213 longsuite = suite + "/" + suite_suffix
217 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
219 if AptCnf.has_key("tree::%s" % (tree)):
221 elif AptCnf.has_key("bindirectory::%s" % (tree)):
224 aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
225 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
228 print Cnf["Dir::Root"] + tree + "/Release"
229 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
231 out.write("Origin: %s\n" % (suiteobj.origin))
232 out.write("Label: %s\n" % (label))
233 out.write("Suite: %s\n" % (suite))
235 out.write("Version: %s\n" % (version))
237 out.write("Codename: %s\n" % (codename))
238 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
240 if SuiteBlock.has_key("ValidTime"):
241 validtime=float(SuiteBlock["ValidTime"])
242 out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))
244 if notautomatic != "":
245 out.write("NotAutomatic: %s\n" % (notautomatic))
246 out.write("Architectures: %s\n" % (" ".join([a.arch_string for a in architectures])))
248 out.write("Components: %s\n" % (" ".join(components)))
251 out.write("Description: %s\n" % (description))
255 if AptCnf.has_key("tree::%s" % (tree)):
256 if AptCnf.has_key("tree::%s::Contents" % (tree)):
259 for x in os.listdir("%s/%s" % (Cnf["Dir::Root"], tree)):
260 if x.startswith('Contents-'):
263 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
264 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
266 filepath = "%s/%s/Sources" % (sec, arch)
267 for cfile in compressnames("tree::%s" % (tree), "Sources", filepath):
269 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
271 disks = "%s/disks-%s" % (sec, arch)
272 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
273 if os.path.exists(diskspath):
274 for dir in os.listdir(diskspath):
275 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
276 files.append("%s/%s/md5sum.txt" % (disks, dir))
278 filepath = "%s/binary-%s/Packages" % (sec, arch)
279 for cfile in compressnames("tree::%s" % (tree), "Packages", filepath):
281 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
284 rel = "%s/%s/Release" % (sec, arch)
286 rel = "%s/binary-%s/Release" % (sec, arch)
287 relpath = Cnf["Dir::Root"]+tree+"/"+rel
288 write_release_file(relpath, suite, sec, origin, label, arch, version, suite_suffix, notautomatic)
291 if AptCnf.has_key("tree::%s/main" % (tree)):
292 for dis in ["main", "contrib", "non-free"]:
293 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
294 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
295 if sec != "debian-installer":
296 print "ALERT: weird non debian-installer section in %s" % (tree)
298 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
299 if arch != "source": # always true
300 rel = "%s/%s/binary-%s/Release" % (dis, sec, arch)
301 relpath = Cnf["Dir::Root"]+tree+"/"+rel
302 write_release_file(relpath, suite, dis, origin, label, arch, version, suite_suffix, notautomatic)
304 for cfile in compressnames("tree::%s/%s" % (tree,dis),
306 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
308 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
309 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
310 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
311 if sec != "debian-installer":
312 print "ALERT: weird non debian-installer section in %s" % (usetree)
314 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
315 if arch != "source": # always true
316 for cfile in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
319 elif AptCnf.has_key("bindirectory::%s" % (tree)):
320 for cfile in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
321 files.append(cfile.replace(tree+"/","",1))
322 for cfile in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
323 files.append(cfile.replace(tree+"/","",1))
325 print "ALERT: no tree/bindirectory for %s" % (tree)
327 out.write("MD5Sum:\n")
328 print_md5_files(tree, files)
330 print_sha1_files(tree, files)
331 out.write("SHA256:\n")
332 print_sha256_files(tree, files)
335 if Cnf.has_key("Dinstall::SigningKeyring"):
336 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
337 if Cnf.has_key("Dinstall::SigningPubKeyring"):
338 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
340 arguments = "--no-options --batch --no-tty --armour"
341 if Cnf.has_key("Dinstall::SigningKeyIds"):
342 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
346 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
347 if os.path.exists(dest):
350 for keyid in signkeyids:
351 if keyid != "": defkeyid = "--default-key %s" % keyid
353 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
354 (keyring, defkeyid, arguments,
355 Cnf["Dir::Root"] + tree + "/Release", dest))
357 #######################################################################################
359 if __name__ == '__main__':