3 # Create all the Release files
5 # Copyright (C) 2001, 2002 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.27 2005-11-15 09:50:32 ajt Exp $
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ################################################################################
26 import sys, os, popen2, tempfile, stat, time
30 ################################################################################
37 ################################################################################
39 def usage (exit_code=0):
40 print """Usage: ziyi [OPTION]... [SUITE]...
41 Generate Release files (for SUITE).
43 -h, --help show this help and exit
45 If no SUITE is given Release files are generated for all suites."""
49 ################################################################################
51 def add_tiffani (files, path, indexstem):
52 index = "%s.diff/Index" % (indexstem)
53 filepath = "%s/%s" % (path, index)
54 if os.path.exists(filepath):
55 #print "ALERT: there was a tiffani file %s" % (filepath)
58 def compressnames (tree,type,file):
59 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
62 uncompress = ("." not in cl)
63 for mode in compress.split():
68 result.append("<zcat/.gz>" + file)
70 result.append(file + ".gz")
73 result.append("<bzcat/.bz2>" + file)
75 result.append(file + ".bz2")
78 def create_temp_file (cmd):
79 f = tempfile.TemporaryFile()
80 r = popen2.popen2(cmd)
96 def print_md5sha_files (tree, files, hashop):
97 path = Cnf["Dir::Root"] + tree + "/"
103 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
104 (size, file_handle) = create_temp_file("%s %s%s%s" %
105 (cat, path, name, ext))
107 size = os.stat(path + name)[stat.ST_SIZE]
108 file_handle = utils.open_file(path + name)
109 except utils.cant_open_exc:
110 print "ALERT: Couldn't open " + path + name
112 hash = hashop(file_handle)
114 out.write(" %s %8d %s\n" % (hash, size, name))
116 def print_md5_files (tree, files):
117 print_md5sha_files (tree, files, apt_pkg.md5sum)
119 def print_sha1_files (tree, files):
120 print_md5sha_files (tree, files, apt_pkg.sha1sum)
122 ################################################################################
125 global Cnf, AptCnf, projectB, out
128 Cnf = utils.get_conf()
130 Arguments = [('h',"help","Ziyi::Options::Help")]
132 if not Cnf.has_key("Ziyi::Options::%s" % (i)):
133 Cnf["Ziyi::Options::%s" % (i)] = ""
135 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
136 Options = Cnf.SubTree("Ziyi::Options")
141 AptCnf = apt_pkg.newConfiguration()
142 apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
145 suites = Cnf.SubTree("Suite").List()
148 print "Processing: " + suite
149 SuiteBlock = Cnf.SubTree("Suite::" + suite)
151 if SuiteBlock.has_key("Untouchable"):
152 print "Skipping: " + suite + " (untouchable)"
155 suite = suite.lower()
157 origin = SuiteBlock["Origin"]
158 label = SuiteBlock.get("Label", origin)
159 version = SuiteBlock.get("Version", "")
160 codename = SuiteBlock.get("CodeName", "")
162 if SuiteBlock.has_key("NotAutomatic"):
167 if SuiteBlock.has_key("Components"):
168 components = SuiteBlock.ValueList("Components")
172 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
173 if components and suite_suffix:
174 longsuite = suite + "/" + suite_suffix
178 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
180 if AptCnf.has_key("tree::%s" % (tree)):
182 elif AptCnf.has_key("bindirectory::%s" % (tree)):
185 aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
186 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
189 print Cnf["Dir::Root"] + tree + "/Release"
190 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
192 out.write("Origin: %s\n" % (origin))
193 out.write("Label: %s\n" % (label))
194 out.write("Suite: %s\n" % (suite))
196 out.write("Version: %s\n" % (version))
198 out.write("Codename: %s\n" % (codename))
199 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
200 if notautomatic != "":
201 out.write("NotAutomatic: %s\n" % (notautomatic))
202 out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
204 out.write("Components: %s\n" % (" ".join(components)))
206 out.write("Description: %s\n" % (SuiteBlock["Description"]))
210 if AptCnf.has_key("tree::%s" % (tree)):
211 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
212 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
214 filepath = "%s/%s/Sources" % (sec, arch)
215 for file in compressnames("tree::%s" % (tree), "Sources", filepath):
217 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
219 disks = "%s/disks-%s" % (sec, arch)
220 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
221 if os.path.exists(diskspath):
222 for dir in os.listdir(diskspath):
223 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
224 files.append("%s/%s/md5sum.txt" % (disks, dir))
226 filepath = "%s/binary-%s/Packages" % (sec, arch)
227 for file in compressnames("tree::%s" % (tree), "Packages", filepath):
229 add_tiffani(files, Cnf["Dir::Root"] + tree, filepath)
232 rel = "%s/%s/Release" % (sec, arch)
234 rel = "%s/binary-%s/Release" % (sec, arch)
235 relpath = Cnf["Dir::Root"]+tree+"/"+rel
238 release = open(relpath, "w")
239 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
241 utils.fubar("Couldn't write to " + relpath)
243 release.write("Archive: %s\n" % (suite))
245 release.write("Version: %s\n" % (version))
247 release.write("Component: %s/%s\n" % (suite_suffix,sec))
249 release.write("Component: %s\n" % (sec))
250 release.write("Origin: %s\n" % (origin))
251 release.write("Label: %s\n" % (label))
252 if notautomatic != "":
253 release.write("NotAutomatic: %s\n" % (notautomatic))
254 release.write("Architecture: %s\n" % (arch))
258 if AptCnf.has_key("tree::%s/main" % (tree)):
259 sec = AptCnf["tree::%s/main::Sections" % (tree)].split()[0]
260 if sec != "debian-installer":
261 print "ALERT: weird non debian-installer section in %s" % (tree)
263 for arch in AptCnf["tree::%s/main::Architectures" % (tree)].split():
264 if arch != "source": # always true
265 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
267 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
268 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
269 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
270 if sec != "debian-installer":
271 print "ALERT: weird non debian-installer section in %s" % (usetree)
273 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
274 if arch != "source": # always true
275 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
278 elif AptCnf.has_key("bindirectory::%s" % (tree)):
279 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
280 files.append(file.replace(tree+"/","",1))
281 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
282 files.append(file.replace(tree+"/","",1))
284 print "ALERT: no tree/bindirectory for %s" % (tree)
286 out.write("MD5Sum:\n")
287 print_md5_files(tree, files)
289 print_sha1_files(tree, files)
292 if Cnf.has_key("Dinstall::SigningKeyring"):
293 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
294 if Cnf.has_key("Dinstall::SigningPubKeyring"):
295 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
297 arguments = "--no-options --batch --no-tty --armour"
298 if Cnf.has_key("Dinstall::SigningKeyIds"):
299 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
303 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
304 if os.path.exists(dest):
307 for keyid in signkeyids:
308 if keyid != "": defkeyid = "--default-key %s" % keyid
310 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
311 (keyring, defkeyid, arguments,
312 Cnf["Dir::Root"] + tree + "/Release", dest))
314 #######################################################################################
316 if __name__ == '__main__':