3 """ Create all the Release files
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @Copyright: 2001, 2002, 2006 Anthony Towns <ajt@debian.org>
7 @copyright: 2009, 2011 Joerg Jaspert <joerg@debian.org>
8 @license: GNU General Public License version 2 or later
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ################################################################################
36 from daklib import utils
37 from daklib.dak_exceptions import *
38 from daklib.dbconn import *
39 from daklib.config import Config
41 ################################################################################
47 ################################################################################
49 def usage (exit_code=0):
50 print """Usage: dak generate-releases [OPTION]... [SUITE]...
51 Generate Release files (for SUITE).
53 -h, --help show this help and exit
54 -a, --apt-conf FILE use FILE instead of default apt.conf
55 -f, --force-touch ignore Untouchable directives in dak.conf
57 If no SUITE is given Release files are generated for all suites."""
61 ################################################################################
63 def add_tiffani (files, path, indexstem):
64 index = "%s.diff/Index" % (indexstem)
65 filepath = "%s/%s" % (path, index)
66 if os.path.exists(filepath):
67 #print "ALERT: there was a tiffani file %s" % (filepath)
70 def gen_i18n_index (files, tree, sec):
71 path = Cnf["Dir::Root"] + tree + "/"
72 i18n_path = "%s/i18n" % (sec)
73 if os.path.exists("%s/%s" % (path, i18n_path)):
74 index = "%s/Index" % (i18n_path)
75 out = open("%s/%s" % (path, index), "w")
77 for x in os.listdir("%s/%s" % (path, i18n_path)):
78 if x.startswith('Translation-'):
79 f = open("%s/%s/%s" % (path, i18n_path, x), "r")
80 size = os.fstat(f.fileno())[6]
82 sha1sum = apt_pkg.sha1sum(f)
84 out.write(" %s %7d %s\n" % (sha1sum, size, x))
88 def compressnames (tree,type,file):
89 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
92 uncompress = ("." not in cl)
93 for mode in compress.split():
98 result.append("<zcat/.gz>" + file)
100 result.append(file + ".gz")
101 elif mode == "bzip2":
103 result.append("<bzcat/.bz2>" + file)
105 result.append(file + ".bz2")
108 decompressors = { 'zcat' : gzip.GzipFile,
109 'bzip2' : bz2.BZ2File }
111 def print_hash_files (tree, files, hashop):
112 path = Cnf["Dir::Root"] + tree + "/"
120 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
121 file_handle = decompressors[ cat ]( "%s%s%s" % (path, name, ext) )
122 contents = file_handle.read()
123 hashvalue = hashop(contents)
124 hashlen = len(contents)
127 file_handle = utils.open_file(path + name)
128 hashvalue = hashop(file_handle)
129 hashlen = os.stat(path + name).st_size
136 except CantOpenError:
137 print "ALERT: Couldn't open " + path + name
139 print "ALERT: IOError when reading %s" % (path + name)
142 out.write(" %s %8d %s\n" % (hashvalue, hashlen, name))
144 def print_sha1_files (tree, files):
145 print_hash_files (tree, files, apt_pkg.sha1sum)
147 def print_sha256_files (tree, files):
148 print_hash_files (tree, files, apt_pkg.sha256sum)
150 def write_release_file (relpath, suite, component, origin, label, arch, version="", suite_suffix="", notautomatic="", butautomaticupgrades=""):
152 if os.access(relpath, os.F_OK):
153 if os.stat(relpath).st_nlink > 1:
155 release = open(relpath, "w")
157 utils.fubar("Couldn't write to " + relpath)
159 release.write("Archive: %s\n" % (suite))
161 release.write("Version: %s\n" % (version))
164 release.write("Component: %s/%s\n" % (suite_suffix,component))
166 release.write("Component: %s\n" % (component))
168 release.write("Origin: %s\n" % (origin))
169 release.write("Label: %s\n" % (label))
170 if notautomatic != "":
171 release.write("NotAutomatic: %s\n" % (notautomatic))
172 if butautomaticupgrades != "":
173 release.write("ButAutomaticUpgrades: %s\n" % (butautomaticupgrades))
174 release.write("Architecture: %s\n" % (arch))
177 ################################################################################
180 global Cnf, AptCnf, out
183 Cnf = utils.get_conf()
186 Arguments = [('h',"help","Generate-Releases::Options::Help"),
187 ('a',"apt-conf","Generate-Releases::Options::Apt-Conf", "HasArg"),
188 ('f',"force-touch","Generate-Releases::Options::Force-Touch"),
190 for i in [ "help", "apt-conf", "force-touch" ]:
191 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
192 Cnf["Generate-Releases::Options::%s" % (i)] = ""
194 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
195 Options = Cnf.SubTree("Generate-Releases::Options")
200 if not Options["Apt-Conf"]:
201 Options["Apt-Conf"] = utils.which_apt_conf_file()
203 AptCnf = apt_pkg.newConfiguration()
204 apt_pkg.ReadConfigFileISC(AptCnf, Options["Apt-Conf"])
207 suites = Cnf.SubTree("Suite").List()
209 for suitename in suites:
210 print "Processing: " + suitename
211 SuiteBlock = Cnf.SubTree("Suite::" + suitename)
212 suiteobj = get_suite(suitename.lower())
214 print "ALERT: Cannot find suite %s!" % (suitename.lower())
217 # Use the canonical name
218 suite = suiteobj.suite_name.lower()
220 if suiteobj.untouchable and not Options["Force-Touch"]:
221 print "Skipping: " + suite + " (untouchable)"
224 origin = suiteobj.origin
225 label = suiteobj.label or suiteobj.origin
226 codename = suiteobj.codename or ""
228 if suiteobj.version and suiteobj.version != '-':
229 version = suiteobj.version
230 description = suiteobj.description or ""
232 architectures = get_suite_architectures(suite, skipall=True, skipsrc=True)
234 if suiteobj.notautomatic:
239 if suiteobj.butautomaticupgrades:
240 butautomaticupgrades = "yes"
242 butautomaticupgrades = ""
244 if SuiteBlock.has_key("Components"):
245 components = SuiteBlock.ValueList("Components")
249 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
250 if components and suite_suffix:
251 longsuite = suite + "/" + suite_suffix
255 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
257 if AptCnf.has_key("tree::%s" % (tree)):
259 elif AptCnf.has_key("bindirectory::%s" % (tree)):
262 aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
263 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
266 print Cnf["Dir::Root"] + tree + "/Release"
267 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
269 out.write("Origin: %s\n" % (suiteobj.origin))
270 out.write("Label: %s\n" % (label))
271 out.write("Suite: %s\n" % (suite))
273 out.write("Version: %s\n" % (version))
275 out.write("Codename: %s\n" % (codename))
276 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
278 if suiteobj.validtime:
279 validtime=float(suiteobj.validtime)
280 out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))
282 if notautomatic != "":
283 out.write("NotAutomatic: %s\n" % (notautomatic))
284 if butautomaticupgrades != "":
285 out.write("ButAutomaticUpgrades: %s\n" % (butautomaticupgrades))
286 out.write("Architectures: %s\n" % (" ".join([a.arch_string for a in architectures])))
288 out.write("Components: %s\n" % (" ".join(components)))
291 out.write("Description: %s\n" % (description))
295 if AptCnf.has_key("tree::%s" % (tree)):
296 if AptCnf.has_key("tree::%s::Contents" % (tree)):
299 for x in os.listdir("%s/%s" % (Cnf["Dir::Root"], tree)):
300 if x.startswith('Contents-'):
301 if x.endswith('.diff'):
302 files.append("%s/Index" % (x))
306 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
307 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
309 filepath = "%s/%s/Sources" % (sec, arch)
310 for cfile in compressnames("tree::%s" % (tree), "Sources", filepath):
312 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
314 installer = "%s/installer-%s" % (sec, arch)
315 installerpath = Cnf["Dir::Root"]+tree+"/"+installer
316 if os.path.exists(installerpath):
317 for directory in os.listdir(installerpath):
318 if os.path.exists("%s/%s/images/MD5SUMS" % (installerpath, directory)):
319 files.append("%s/%s/images/MD5SUMS" % (installer, directory))
321 filepath = "%s/binary-%s/Packages" % (sec, arch)
322 for cfile in compressnames("tree::%s" % (tree), "Packages", filepath):
324 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
327 rel = "%s/%s/Release" % (sec, arch)
329 rel = "%s/binary-%s/Release" % (sec, arch)
330 relpath = Cnf["Dir::Root"]+tree+"/"+rel
331 write_release_file(relpath, suite, sec, origin, label, arch, version, suite_suffix, notautomatic, butautomaticupgrades)
333 gen_i18n_index(files, tree, sec)
335 if AptCnf.has_key("tree::%s/main" % (tree)):
336 for dis in ["main", "contrib", "non-free"]:
337 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
338 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
339 if sec != "debian-installer":
340 print "ALERT: weird non debian-installer section in %s" % (tree)
342 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
343 if arch != "source": # always true
344 rel = "%s/%s/binary-%s/Release" % (dis, sec, arch)
345 relpath = Cnf["Dir::Root"]+tree+"/"+rel
346 write_release_file(relpath, suite, dis, origin, label, arch, version, suite_suffix, notautomatic, butautomaticupgrades)
348 for cfile in compressnames("tree::%s/%s" % (tree,dis),
350 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
352 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
353 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
354 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
355 if sec != "debian-installer":
356 print "ALERT: weird non debian-installer section in %s" % (usetree)
358 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
359 if arch != "source": # always true
360 for cfile in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
363 elif AptCnf.has_key("bindirectory::%s" % (tree)):
364 for cfile in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
365 files.append(cfile.replace(tree+"/","",1))
366 for cfile in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
367 files.append(cfile.replace(tree+"/","",1))
369 print "ALERT: no tree/bindirectory for %s" % (tree)
372 print_sha1_files(tree, files)
373 out.write("SHA256:\n")
374 print_sha256_files(tree, files)
377 if Cnf.has_key("Dinstall::SigningKeyring"):
378 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
379 if Cnf.has_key("Dinstall::SigningPubKeyring"):
380 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
382 arguments = "--no-options --batch --no-tty --armour"
383 signkeyids=cnf.signingkeyids.split()
385 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
386 if os.path.exists(dest):
388 inlinedest = Cnf["Dir::Root"] + tree + "/InRelease"
389 if os.path.exists(inlinedest):
390 os.unlink(inlinedest)
392 for keyid in signkeyids:
394 defkeyid = "--default-key %s" % keyid
397 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
398 (keyring, defkeyid, arguments,
399 Cnf["Dir::Root"] + tree + "/Release", dest))
400 os.system("gpg %s %s %s --clearsign <%s >>%s" %
401 (keyring, defkeyid, arguments,
402 Cnf["Dir::Root"] + tree + "/Release", inlinedest))
404 #######################################################################################
406 if __name__ == '__main__':