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()))))
222 if SuiteBlock.has_key("ValidTime"):
223 validtime=float(SuiteBlock["ValidTime"])
224 out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))
226 if notautomatic != "":
227 out.write("NotAutomatic: %s\n" % (notautomatic))
228 out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
230 out.write("Components: %s\n" % (" ".join(components)))
233 out.write("Description: %s\n" % (description))
237 if AptCnf.has_key("tree::%s" % (tree)):
238 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
239 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
241 filepath = "%s/%s/Sources" % (sec, arch)
242 for file in compressnames("tree::%s" % (tree), "Sources", filepath):
244 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
246 disks = "%s/disks-%s" % (sec, arch)
247 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
248 if os.path.exists(diskspath):
249 for dir in os.listdir(diskspath):
250 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
251 files.append("%s/%s/md5sum.txt" % (disks, dir))
253 filepath = "%s/binary-%s/Packages" % (sec, arch)
254 for file in compressnames("tree::%s" % (tree), "Packages", filepath):
256 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
259 rel = "%s/%s/Release" % (sec, arch)
261 rel = "%s/binary-%s/Release" % (sec, arch)
262 relpath = Cnf["Dir::Root"]+tree+"/"+rel
265 if os.access(relpath, os.F_OK):
266 if os.stat(relpath).st_nlink > 1:
268 release = open(relpath, "w")
269 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
271 utils.fubar("Couldn't write to " + relpath)
273 release.write("Archive: %s\n" % (suite))
275 release.write("Version: %s\n" % (version))
277 release.write("Component: %s/%s\n" % (suite_suffix,sec))
279 release.write("Component: %s\n" % (sec))
280 release.write("Origin: %s\n" % (origin))
281 release.write("Label: %s\n" % (label))
282 if notautomatic != "":
283 release.write("NotAutomatic: %s\n" % (notautomatic))
284 release.write("Architecture: %s\n" % (arch))
288 if AptCnf.has_key("tree::%s/main" % (tree)):
289 for dis in ["main", "contrib", "non-free"]:
290 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
291 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
292 if sec != "debian-installer":
293 print "ALERT: weird non debian-installer section in %s" % (tree)
295 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
296 if arch != "source": # always true
297 for file in compressnames("tree::%s/%s" % (tree,dis),
299 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
301 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
302 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
303 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
304 if sec != "debian-installer":
305 print "ALERT: weird non debian-installer section in %s" % (usetree)
307 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
308 if arch != "source": # always true
309 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
312 elif AptCnf.has_key("bindirectory::%s" % (tree)):
313 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
314 files.append(file.replace(tree+"/","",1))
315 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
316 files.append(file.replace(tree+"/","",1))
318 print "ALERT: no tree/bindirectory for %s" % (tree)
320 out.write("MD5Sum:\n")
321 print_md5_files(tree, files)
323 print_sha1_files(tree, files)
324 out.write("SHA256:\n")
325 print_sha256_files(tree, files)
328 if Cnf.has_key("Dinstall::SigningKeyring"):
329 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
330 if Cnf.has_key("Dinstall::SigningPubKeyring"):
331 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
333 arguments = "--no-options --batch --no-tty --armour"
334 if Cnf.has_key("Dinstall::SigningKeyIds"):
335 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
339 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
340 if os.path.exists(dest):
343 for keyid in signkeyids:
344 if keyid != "": defkeyid = "--default-key %s" % keyid
346 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
347 (keyring, defkeyid, arguments,
348 Cnf["Dir::Root"] + tree + "/Release", dest))
350 #######################################################################################
352 if __name__ == '__main__':