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
29 ################################################################################
36 ################################################################################
38 def usage (exit_code=0):
39 print """Usage: dak generate-releases [OPTION]... [SUITE]...
40 Generate Release files (for SUITE).
42 -h, --help show this help and exit
44 If no SUITE is given Release files are generated for all suites."""
48 ################################################################################
50 def add_tiffani (files, path, indexstem):
51 index = "%s.diff/Index" % (indexstem)
52 filepath = "%s/%s" % (path, index)
53 if os.path.exists(filepath):
54 #print "ALERT: there was a tiffani file %s" % (filepath)
57 def compressnames (tree,type,file):
58 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
61 uncompress = ("." not in cl)
62 for mode in compress.split():
67 result.append("<zcat/.gz>" + file)
69 result.append(file + ".gz")
72 result.append("<bzcat/.bz2>" + file)
74 result.append(file + ".bz2")
77 def create_temp_file (cmd):
78 f = tempfile.TemporaryFile()
79 r = popen2.popen2(cmd)
95 def print_md5sha_files (tree, files, hashop):
96 path = Cnf["Dir::Root"] + tree + "/"
102 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
103 (size, file_handle) = create_temp_file("%s %s%s%s" %
104 (cat, path, name, ext))
106 size = os.stat(path + name)[stat.ST_SIZE]
107 file_handle = daklib.utils.open_file(path + name)
108 except daklib.utils.cant_open_exc:
109 print "ALERT: Couldn't open " + path + name
111 hash = hashop(file_handle)
113 out.write(" %s %8d %s\n" % (hash, size, 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 = daklib.utils.get_conf()
132 Arguments = [('h',"help","Generate-Releases::Options::Help")]
134 if not Cnf.has_key("Generate-Releases::Options::%s" % (i)):
135 Cnf["Generate-Releases::Options::%s" % (i)] = ""
137 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
138 Options = Cnf.SubTree("Generate-Releases::Options")
143 AptCnf = apt_pkg.newConfiguration()
144 apt_pkg.ReadConfigFileISC(AptCnf,daklib.utils.which_apt_conf_file())
147 suites = Cnf.SubTree("Suite").List()
150 print "Processing: " + suite
151 SuiteBlock = Cnf.SubTree("Suite::" + suite)
153 if SuiteBlock.has_key("Untouchable"):
154 print "Skipping: " + suite + " (untouchable)"
157 suite = suite.lower()
159 origin = SuiteBlock["Origin"]
160 label = SuiteBlock.get("Label", origin)
161 version = SuiteBlock.get("Version", "")
162 codename = SuiteBlock.get("CodeName", "")
164 if SuiteBlock.has_key("NotAutomatic"):
169 if SuiteBlock.has_key("Components"):
170 components = SuiteBlock.ValueList("Components")
174 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
175 if components and suite_suffix:
176 longsuite = suite + "/" + suite_suffix
180 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
182 if AptCnf.has_key("tree::%s" % (tree)):
184 elif AptCnf.has_key("bindirectory::%s" % (tree)):
187 aptcnf_filename = os.path.basename(daklib.utils.which_apt_conf_file())
188 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
191 print Cnf["Dir::Root"] + tree + "/Release"
192 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
194 out.write("Origin: %s\n" % (origin))
195 out.write("Label: %s\n" % (label))
196 out.write("Suite: %s\n" % (suite))
198 out.write("Version: %s\n" % (version))
200 out.write("Codename: %s\n" % (codename))
201 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
202 if notautomatic != "":
203 out.write("NotAutomatic: %s\n" % (notautomatic))
204 out.write("Architectures: %s\n" % (" ".join(filter(daklib.utils.real_arch, SuiteBlock.ValueList("Architectures")))))
206 out.write("Components: %s\n" % (" ".join(components)))
208 out.write("Description: %s\n" % (SuiteBlock["Description"]))
212 if AptCnf.has_key("tree::%s" % (tree)):
213 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
214 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
216 filepath = "%s/%s/Sources" % (sec, arch)
217 for file in compressnames("tree::%s" % (tree), "Sources", filepath):
219 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
221 disks = "%s/disks-%s" % (sec, arch)
222 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
223 if os.path.exists(diskspath):
224 for dir in os.listdir(diskspath):
225 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
226 files.append("%s/%s/md5sum.txt" % (disks, dir))
228 filepath = "%s/binary-%s/Packages" % (sec, arch)
229 for file in compressnames("tree::%s" % (tree), "Packages", filepath):
231 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
234 rel = "%s/%s/Release" % (sec, arch)
236 rel = "%s/binary-%s/Release" % (sec, arch)
237 relpath = Cnf["Dir::Root"]+tree+"/"+rel
240 release = open(relpath, "w")
241 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
243 daklib.utils.fubar("Couldn't write to " + relpath)
245 release.write("Archive: %s\n" % (suite))
247 release.write("Version: %s\n" % (version))
249 release.write("Component: %s/%s\n" % (suite_suffix,sec))
251 release.write("Component: %s\n" % (sec))
252 release.write("Origin: %s\n" % (origin))
253 release.write("Label: %s\n" % (label))
254 if notautomatic != "":
255 release.write("NotAutomatic: %s\n" % (notautomatic))
256 release.write("Architecture: %s\n" % (arch))
260 if AptCnf.has_key("tree::%s/main" % (tree)):
261 for dis in ["main", "contrib", "non-free"]:
262 if not AptCnf.has_key("tree::%s/%s" % (tree, dis)): continue
263 sec = AptCnf["tree::%s/%s::Sections" % (tree,dis)].split()[0]
264 if sec != "debian-installer":
265 print "ALERT: weird non debian-installer section in %s" % (tree)
267 for arch in AptCnf["tree::%s/%s::Architectures" % (tree,dis)].split():
268 if arch != "source": # always true
269 for file in compressnames("tree::%s/%s" % (tree,dis),
271 "%s/%s/binary-%s/Packages" % (dis, sec, arch)):
273 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
274 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
275 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
276 if sec != "debian-installer":
277 print "ALERT: weird non debian-installer section in %s" % (usetree)
279 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
280 if arch != "source": # always true
281 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
284 elif AptCnf.has_key("bindirectory::%s" % (tree)):
285 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
286 files.append(file.replace(tree+"/","",1))
287 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
288 files.append(file.replace(tree+"/","",1))
290 print "ALERT: no tree/bindirectory for %s" % (tree)
292 out.write("MD5Sum:\n")
293 print_md5_files(tree, files)
295 print_sha1_files(tree, files)
296 out.write("SHA256:\n")
297 print_sha256_files(tree, files)
300 if Cnf.has_key("Dinstall::SigningKeyring"):
301 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
302 if Cnf.has_key("Dinstall::SigningPubKeyring"):
303 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
305 arguments = "--no-options --batch --no-tty --armour"
306 if Cnf.has_key("Dinstall::SigningKeyIds"):
307 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
311 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
312 if os.path.exists(dest):
315 for keyid in signkeyids:
316 if keyid != "": defkeyid = "--default-key %s" % keyid
318 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
319 (keyring, defkeyid, arguments,
320 Cnf["Dir::Root"] + tree + "/Release", dest))
322 #######################################################################################
324 if __name__ == '__main__':