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
28 from daklib import utils
29 from daklib.dak_exceptions import *
31 ################################################################################
38 ################################################################################
40 def usage (exit_code=0):
41 print """Usage: dak generate-releases [OPTION]... [SUITE]...
42 Generate Release files (for SUITE).
44 -h, --help show this help and exit
45 -a, --apt-conf FILE use FILE instead of default apt.conf
46 -f, --force-touch ignore Untouchable directives in dak.conf
48 If no SUITE is given Release files are generated for all suites."""
52 ################################################################################
54 def add_tiffani (files, path, indexstem):
55 index = "%s.diff/Index" % (indexstem)
56 filepath = "%s/%s" % (path, index)
57 if os.path.exists(filepath):
58 #print "ALERT: there was a tiffani file %s" % (filepath)
61 def compressnames (tree,type,file):
62 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
65 uncompress = ("." not in cl)
66 for mode in compress.split():
71 result.append("<zcat/.gz>" + file)
73 result.append(file + ".gz")
76 result.append("<bzcat/.bz2>" + file)
78 result.append(file + ".bz2")
81 decompressors = { 'zcat' : gzip.GzipFile,
82 'bzip2' : bz2.BZ2File }
84 def print_md5sha_files (tree, files, hashop):
85 path = Cnf["Dir::Root"] + tree + "/"
91 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
92 file_handle = decompressors[ cat ]( "%s%s%s" % (path, name, ext) )
93 contents = file_handle.read()
96 file_handle = utils.open_file(path + name)
97 contents = file_handle.read()
104 except CantOpenError:
105 print "ALERT: Couldn't open " + path + name
107 hash = hashop(contents)
108 out.write(" %s %8d %s\n" % (hash, len(contents), name))
110 def print_md5_files (tree, files):
111 print_md5sha_files (tree, files, apt_pkg.md5sum)
113 def print_sha1_files (tree, files):
114 print_md5sha_files (tree, files, apt_pkg.sha1sum)
116 def print_sha256_files (tree, files):
117 print_md5sha_files (tree, files, apt_pkg.sha256sum)
119 ################################################################################
122 global Cnf, AptCnf, projectB, out
125 Cnf = utils.get_conf()
127 Arguments = [('h',"help","Generate-Releases::Options::Help"),
128 ('a',"apt-conf","Generate-Releases::Options::Apt-Conf", "HasArg"),
129 ('f',"force-touch","Generate-Releases::Options::Force-Touch"),
131 for i in [ "help", "apt-conf", "force-touch" ]:
132 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
133 Cnf["Generate-Releases::Options::%s" % (i)] = ""
135 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
136 Options = Cnf.SubTree("Generate-Releases::Options")
141 if not Options["Apt-Conf"]:
142 Options["Apt-Conf"] = utils.which_apt_conf_file()
144 AptCnf = apt_pkg.newConfiguration()
145 apt_pkg.ReadConfigFileISC(AptCnf, Options["Apt-Conf"])
147 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
150 suites = Cnf.SubTree("Suite").List()
153 print "Processing: " + suite
154 SuiteBlock = Cnf.SubTree("Suite::" + suite)
156 if SuiteBlock.has_key("Untouchable") and not Options["Force-Touch"]:
157 print "Skipping: " + suite + " (untouchable)"
160 suite = suite.lower()
162 origin = SuiteBlock["Origin"]
163 label = SuiteBlock.get("Label", origin)
164 codename = SuiteBlock.get("CodeName", "")
169 q = projectB.query("SELECT version, description FROM suite WHERE suite_name = '%s'" % (suite))
172 if qs[0][0] != "-": version = qs[0][0]
173 if qs[0][1]: description = qs[0][1]
175 if SuiteBlock.has_key("NotAutomatic"):
180 if SuiteBlock.has_key("Components"):
181 components = SuiteBlock.ValueList("Components")
185 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
186 if components and suite_suffix:
187 longsuite = suite + "/" + suite_suffix
191 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
193 if AptCnf.has_key("tree::%s" % (tree)):
195 elif AptCnf.has_key("bindirectory::%s" % (tree)):
198 aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
199 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
202 print Cnf["Dir::Root"] + tree + "/Release"
203 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
205 out.write("Origin: %s\n" % (origin))
206 out.write("Label: %s\n" % (label))
207 out.write("Suite: %s\n" % (suite))
209 out.write("Version: %s\n" % (version))
211 out.write("Codename: %s\n" % (codename))
212 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
214 if SuiteBlock.has_key("ValidTime"):
215 validtime=float(SuiteBlock["ValidTime"])
216 out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))
218 if notautomatic != "":
219 out.write("NotAutomatic: %s\n" % (notautomatic))
220 out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
222 out.write("Components: %s\n" % (" ".join(components)))
225 out.write("Description: %s\n" % (description))
229 if AptCnf.has_key("tree::%s" % (tree)):
230 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
231 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
233 filepath = "%s/%s/Sources" % (sec, arch)
234 for file in compressnames("tree::%s" % (tree), "Sources", filepath):
236 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
238 disks = "%s/disks-%s" % (sec, arch)
239 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
240 if os.path.exists(diskspath):
241 for dir in os.listdir(diskspath):
242 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
243 files.append("%s/%s/md5sum.txt" % (disks, dir))
245 filepath = "%s/binary-%s/Packages" % (sec, arch)
246 for file in compressnames("tree::%s" % (tree), "Packages", filepath):
248 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
251 rel = "%s/%s/Release" % (sec, arch)
253 rel = "%s/binary-%s/Release" % (sec, arch)
254 relpath = Cnf["Dir::Root"]+tree+"/"+rel
257 if os.access(relpath, os.F_OK):
258 if os.stat(relpath).st_nlink > 1:
260 release = open(relpath, "w")
261 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
263 utils.fubar("Couldn't write to " + relpath)
265 release.write("Archive: %s\n" % (suite))
267 release.write("Version: %s\n" % (version))
269 release.write("Component: %s/%s\n" % (suite_suffix,sec))
271 release.write("Component: %s\n" % (sec))
272 release.write("Origin: %s\n" % (origin))
273 release.write("Label: %s\n" % (label))
274 if notautomatic != "":
275 release.write("NotAutomatic: %s\n" % (notautomatic))
276 release.write("Architecture: %s\n" % (arch))
280 if AptCnf.has_key("tree::%s/main" % (tree)):
281 for dis in ["main", "contrib", "non-free"]:
282 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
283 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
284 if sec != "debian-installer":
285 print "ALERT: weird non debian-installer section in %s" % (tree)
287 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
288 if arch != "source": # always true
289 for file in compressnames("tree::%s/%s" % (tree,dis),
291 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
293 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
294 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
295 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
296 if sec != "debian-installer":
297 print "ALERT: weird non debian-installer section in %s" % (usetree)
299 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
300 if arch != "source": # always true
301 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
304 elif AptCnf.has_key("bindirectory::%s" % (tree)):
305 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
306 files.append(file.replace(tree+"/","",1))
307 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
308 files.append(file.replace(tree+"/","",1))
310 print "ALERT: no tree/bindirectory for %s" % (tree)
312 out.write("MD5Sum:\n")
313 print_md5_files(tree, files)
315 print_sha1_files(tree, files)
316 out.write("SHA256:\n")
317 print_sha256_files(tree, files)
320 if Cnf.has_key("Dinstall::SigningKeyring"):
321 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
322 if Cnf.has_key("Dinstall::SigningPubKeyring"):
323 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
325 arguments = "--no-options --batch --no-tty --armour"
326 if Cnf.has_key("Dinstall::SigningKeyIds"):
327 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
331 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
332 if os.path.exists(dest):
335 for keyid in signkeyids:
336 if keyid != "": defkeyid = "--default-key %s" % keyid
338 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
339 (keyring, defkeyid, arguments,
340 Cnf["Dir::Root"] + tree + "/Release", dest))
342 #######################################################################################
344 if __name__ == '__main__':