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 import database
30 from daklib.dak_exceptions import *
32 ################################################################################
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 ################################################################################
127 global Cnf, AptCnf, projectB, out
130 Cnf = utils.get_conf()
132 Arguments = [('h',"help","Generate-Releases::Options::Help"),
133 ('a',"apt-conf","Generate-Releases::Options::Apt-Conf", "HasArg"),
134 ('f',"force-touch","Generate-Releases::Options::Force-Touch"),
136 for i in [ "help", "apt-conf", "force-touch" ]:
137 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
138 Cnf["Generate-Releases::Options::%s" % (i)] = ""
140 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
141 Options = Cnf.SubTree("Generate-Releases::Options")
146 if not Options["Apt-Conf"]:
147 Options["Apt-Conf"] = utils.which_apt_conf_file()
149 AptCnf = apt_pkg.newConfiguration()
150 apt_pkg.ReadConfigFileISC(AptCnf, Options["Apt-Conf"])
152 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
155 suites = Cnf.SubTree("Suite").List()
158 print "Processing: " + suite
159 SuiteBlock = Cnf.SubTree("Suite::" + suite)
161 if SuiteBlock.has_key("Untouchable") and not Options["Force-Touch"]:
162 print "Skipping: " + suite + " (untouchable)"
165 suite = suite.lower()
167 origin = SuiteBlock["Origin"]
168 label = SuiteBlock.get("Label", origin)
169 codename = SuiteBlock.get("CodeName", "")
174 q = projectB.query("SELECT version, description FROM suite WHERE suite_name = '%s'" % (suite))
177 if qs[0][0] != "-": version = qs[0][0]
178 if qs[0][1]: description = qs[0][1]
180 architectures = database.get_suite_architectures(suite)
181 if architectures == None:
184 if SuiteBlock.has_key("NotAutomatic"):
189 if SuiteBlock.has_key("Components"):
190 components = SuiteBlock.ValueList("Components")
194 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
195 if components and suite_suffix:
196 longsuite = suite + "/" + suite_suffix
200 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
202 if AptCnf.has_key("tree::%s" % (tree)):
204 elif AptCnf.has_key("bindirectory::%s" % (tree)):
207 aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
208 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
211 print Cnf["Dir::Root"] + tree + "/Release"
212 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
214 out.write("Origin: %s\n" % (origin))
215 out.write("Label: %s\n" % (label))
216 out.write("Suite: %s\n" % (suite))
218 out.write("Version: %s\n" % (version))
220 out.write("Codename: %s\n" % (codename))
221 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
223 if SuiteBlock.has_key("ValidTime"):
224 validtime=float(SuiteBlock["ValidTime"])
225 out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))
227 if notautomatic != "":
228 out.write("NotAutomatic: %s\n" % (notautomatic))
229 out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, architectures))))
231 out.write("Components: %s\n" % (" ".join(components)))
234 out.write("Description: %s\n" % (description))
238 if AptCnf.has_key("tree::%s" % (tree)):
239 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
240 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
242 filepath = "%s/%s/Sources" % (sec, arch)
243 for cfile in compressnames("tree::%s" % (tree), "Sources", filepath):
245 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
247 disks = "%s/disks-%s" % (sec, arch)
248 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
249 if os.path.exists(diskspath):
250 for dir in os.listdir(diskspath):
251 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
252 files.append("%s/%s/md5sum.txt" % (disks, dir))
254 filepath = "%s/binary-%s/Packages" % (sec, arch)
255 for cfile in compressnames("tree::%s" % (tree), "Packages", filepath):
257 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
260 rel = "%s/%s/Release" % (sec, arch)
262 rel = "%s/binary-%s/Release" % (sec, arch)
263 relpath = Cnf["Dir::Root"]+tree+"/"+rel
266 if os.access(relpath, os.F_OK):
267 if os.stat(relpath).st_nlink > 1:
269 release = open(relpath, "w")
270 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
272 utils.fubar("Couldn't write to " + relpath)
274 release.write("Archive: %s\n" % (suite))
276 release.write("Version: %s\n" % (version))
278 release.write("Component: %s/%s\n" % (suite_suffix,sec))
280 release.write("Component: %s\n" % (sec))
281 release.write("Origin: %s\n" % (origin))
282 release.write("Label: %s\n" % (label))
283 if notautomatic != "":
284 release.write("NotAutomatic: %s\n" % (notautomatic))
285 release.write("Architecture: %s\n" % (arch))
289 if AptCnf.has_key("tree::%s/main" % (tree)):
290 for dis in ["main", "contrib", "non-free"]:
291 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
292 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
293 if sec != "debian-installer":
294 print "ALERT: weird non debian-installer section in %s" % (tree)
296 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
297 if arch != "source": # always true
298 for cfile in compressnames("tree::%s/%s" % (tree,dis),
300 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
302 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
303 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
304 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
305 if sec != "debian-installer":
306 print "ALERT: weird non debian-installer section in %s" % (usetree)
308 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
309 if arch != "source": # always true
310 for cfile in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
313 elif AptCnf.has_key("bindirectory::%s" % (tree)):
314 for cfile in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
315 files.append(cfile.replace(tree+"/","",1))
316 for cfile in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
317 files.append(cfile.replace(tree+"/","",1))
319 print "ALERT: no tree/bindirectory for %s" % (tree)
321 out.write("MD5Sum:\n")
322 print_md5_files(tree, files)
324 print_sha1_files(tree, files)
325 out.write("SHA256:\n")
326 print_sha256_files(tree, files)
329 if Cnf.has_key("Dinstall::SigningKeyring"):
330 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
331 if Cnf.has_key("Dinstall::SigningPubKeyring"):
332 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
334 arguments = "--no-options --batch --no-tty --armour"
335 if Cnf.has_key("Dinstall::SigningKeyIds"):
336 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
340 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
341 if os.path.exists(dest):
344 for keyid in signkeyids:
345 if keyid != "": defkeyid = "--default-key %s" % keyid
347 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
348 (keyring, defkeyid, arguments,
349 Cnf["Dir::Root"] + tree + "/Release", dest))
351 #######################################################################################
353 if __name__ == '__main__':