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
27 from daklib import utils
28 from daklib.dak_exceptions import *
30 ################################################################################
37 ################################################################################
39 def usage (exit_code=0):
40 print """Usage: dak generate-releases [OPTION]... [SUITE]...
41 Generate Release files (for SUITE).
43 -h, --help show this help and exit
44 -a, --apt-conf FILE use FILE instead of default apt.conf
45 -f, --force-touch ignore Untouchable directives in dak.conf
47 If no SUITE is given Release files are generated for all suites."""
51 ################################################################################
53 def add_tiffani (files, path, indexstem):
54 index = "%s.diff/Index" % (indexstem)
55 filepath = "%s/%s" % (path, index)
56 if os.path.exists(filepath):
57 #print "ALERT: there was a tiffani file %s" % (filepath)
60 def compressnames (tree,type,file):
61 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
64 uncompress = ("." not in cl)
65 for mode in compress.split():
70 result.append("<zcat/.gz>" + file)
72 result.append(file + ".gz")
75 result.append("<bzcat/.bz2>" + file)
77 result.append(file + ".bz2")
80 def create_temp_file (cmd):
81 f = tempfile.TemporaryFile()
82 r = popen2.popen2(cmd)
98 def print_md5sha_files (tree, files, hashop):
99 path = Cnf["Dir::Root"] + tree + "/"
105 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
106 (size, file_handle) = create_temp_file("%s %s%s%s" %
107 (cat, path, name, ext))
109 size = os.stat(path + name)[stat.ST_SIZE]
110 file_handle = utils.open_file(path + name)
111 except CantOpenError:
112 print "ALERT: Couldn't open " + path + name
114 hash = hashop(file_handle)
116 out.write(" %s %8d %s\n" % (hash, size, name))
118 def print_md5_files (tree, files):
119 print_md5sha_files (tree, files, apt_pkg.md5sum)
121 def print_sha1_files (tree, files):
122 print_md5sha_files (tree, files, apt_pkg.sha1sum)
124 def print_sha256_files (tree, files):
125 print_md5sha_files (tree, files, apt_pkg.sha256sum)
127 ################################################################################
130 global Cnf, AptCnf, projectB, out
133 Cnf = utils.get_conf()
135 Arguments = [('h',"help","Generate-Releases::Options::Help"),
136 ('a',"apt-conf","Generate-Releases::Options::Apt-Conf", "HasArg"),
137 ('f',"force-touch","Generate-Releases::Options::Force-Touch"),
139 for i in [ "help", "apt-conf", "force-touch" ]:
140 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
141 Cnf["Generate-Releases::Options::%s" % (i)] = ""
143 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
144 Options = Cnf.SubTree("Generate-Releases::Options")
149 if not Options["Apt-Conf"]:
150 Options["Apt-Conf"] = utils.which_apt_conf_file()
152 AptCnf = apt_pkg.newConfiguration()
153 apt_pkg.ReadConfigFileISC(AptCnf, Options["Apt-Conf"])
155 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
158 suites = Cnf.SubTree("Suite").List()
161 print "Processing: " + suite
162 SuiteBlock = Cnf.SubTree("Suite::" + suite)
164 if SuiteBlock.has_key("Untouchable") and not Options["Force-Touch"]:
165 print "Skipping: " + suite + " (untouchable)"
168 suite = suite.lower()
170 origin = SuiteBlock["Origin"]
171 label = SuiteBlock.get("Label", origin)
172 codename = SuiteBlock.get("CodeName", "")
177 q = projectB.query("SELECT version, description FROM suite WHERE suite_name = '%s'" % (suite))
180 if qs[0][0] != "-": version = qs[0][0]
181 if qs[0][1]: description = qs[0][1]
183 if SuiteBlock.has_key("NotAutomatic"):
188 if SuiteBlock.has_key("Components"):
189 components = SuiteBlock.ValueList("Components")
193 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
194 if components and suite_suffix:
195 longsuite = suite + "/" + suite_suffix
199 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
201 if AptCnf.has_key("tree::%s" % (tree)):
203 elif AptCnf.has_key("bindirectory::%s" % (tree)):
206 aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
207 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
210 print Cnf["Dir::Root"] + tree + "/Release"
211 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
213 out.write("Origin: %s\n" % (origin))
214 out.write("Label: %s\n" % (label))
215 out.write("Suite: %s\n" % (suite))
217 out.write("Version: %s\n" % (version))
219 out.write("Codename: %s\n" % (codename))
220 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
221 if notautomatic != "":
222 out.write("NotAutomatic: %s\n" % (notautomatic))
223 out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
225 out.write("Components: %s\n" % (" ".join(components)))
228 out.write("Description: %s\n" % (description))
232 if AptCnf.has_key("tree::%s" % (tree)):
233 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
234 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
236 filepath = "%s/%s/Sources" % (sec, arch)
237 for file in compressnames("tree::%s" % (tree), "Sources", filepath):
239 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
241 disks = "%s/disks-%s" % (sec, arch)
242 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
243 if os.path.exists(diskspath):
244 for dir in os.listdir(diskspath):
245 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
246 files.append("%s/%s/md5sum.txt" % (disks, dir))
248 filepath = "%s/binary-%s/Packages" % (sec, arch)
249 for file in compressnames("tree::%s" % (tree), "Packages", filepath):
251 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
254 rel = "%s/%s/Release" % (sec, arch)
256 rel = "%s/binary-%s/Release" % (sec, arch)
257 relpath = Cnf["Dir::Root"]+tree+"/"+rel
260 if os.access(relpath, os.F_OK):
261 if os.stat(relpath).st_nlink > 1:
263 release = open(relpath, "w")
264 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
266 utils.fubar("Couldn't write to " + relpath)
268 release.write("Archive: %s\n" % (suite))
270 release.write("Version: %s\n" % (version))
272 release.write("Component: %s/%s\n" % (suite_suffix,sec))
274 release.write("Component: %s\n" % (sec))
275 release.write("Origin: %s\n" % (origin))
276 release.write("Label: %s\n" % (label))
277 if notautomatic != "":
278 release.write("NotAutomatic: %s\n" % (notautomatic))
279 release.write("Architecture: %s\n" % (arch))
283 if AptCnf.has_key("tree::%s/main" % (tree)):
284 for dis in ["main", "contrib", "non-free"]:
285 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
286 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
287 if sec != "debian-installer":
288 print "ALERT: weird non debian-installer section in %s" % (tree)
290 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
291 if arch != "source": # always true
292 for file in compressnames("tree::%s/%s" % (tree,dis),
294 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
296 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
297 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
298 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
299 if sec != "debian-installer":
300 print "ALERT: weird non debian-installer section in %s" % (usetree)
302 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
303 if arch != "source": # always true
304 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
307 elif AptCnf.has_key("bindirectory::%s" % (tree)):
308 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
309 files.append(file.replace(tree+"/","",1))
310 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
311 files.append(file.replace(tree+"/","",1))
313 print "ALERT: no tree/bindirectory for %s" % (tree)
315 out.write("MD5Sum:\n")
316 print_md5_files(tree, files)
318 print_sha1_files(tree, files)
319 out.write("SHA256:\n")
320 print_sha256_files(tree, files)
323 if Cnf.has_key("Dinstall::SigningKeyring"):
324 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
325 if Cnf.has_key("Dinstall::SigningPubKeyring"):
326 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
328 arguments = "--no-options --batch --no-tty --armour"
329 if Cnf.has_key("Dinstall::SigningKeyIds"):
330 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
334 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
335 if os.path.exists(dest):
338 for keyid in signkeyids:
339 if keyid != "": defkeyid = "--default-key %s" % keyid
341 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
342 (keyring, defkeyid, arguments,
343 Cnf["Dir::Root"] + tree + "/Release", dest))
345 #######################################################################################
347 if __name__ == '__main__':