3 # Create all the Release files
5 # Copyright (C) 2001, 2002 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.26 2003-07-15 09:43:18 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 compressnames (tree,type,file):
52 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
55 uncompress = ("." not in cl)
56 for mode in compress.split():
61 result.append("<zcat/.gz>" + file)
63 result.append(file + ".gz")
66 result.append("<bzcat/.bz2>" + file)
68 result.append(file + ".bz2")
71 def create_temp_file (cmd):
72 f = tempfile.TemporaryFile()
73 r = popen2.popen2(cmd)
89 def print_md5sha_files (tree, files, hashop):
90 path = Cnf["Dir::Root"] + tree + "/"
96 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
97 (size, file_handle) = create_temp_file("%s %s%s%s" %
98 (cat, path, name, ext))
100 size = os.stat(path + name)[stat.ST_SIZE]
101 file_handle = utils.open_file(path + name)
102 except utils.cant_open_exc:
103 print "ALERT: Couldn't open " + path + name
105 hash = hashop(file_handle)
107 out.write(" %s %8d %s\n" % (hash, size, name))
109 def print_md5_files (tree, files):
110 print_md5sha_files (tree, files, apt_pkg.md5sum)
112 def print_sha1_files (tree, files):
113 print_md5sha_files (tree, files, apt_pkg.sha1sum)
115 ################################################################################
118 global Cnf, AptCnf, projectB, out
121 Cnf = utils.get_conf()
123 Arguments = [('h',"help","Ziyi::Options::Help")];
125 if not Cnf.has_key("Ziyi::Options::%s" % (i)):
126 Cnf["Ziyi::Options::%s" % (i)] = "";
128 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
129 Options = Cnf.SubTree("Ziyi::Options")
134 AptCnf = apt_pkg.newConfiguration()
135 apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
138 suites = Cnf.SubTree("Suite").List()
141 print "Processing: " + suite
142 SuiteBlock = Cnf.SubTree("Suite::" + suite)
144 if SuiteBlock.has_key("Untouchable"):
145 print "Skipping: " + suite + " (untouchable)"
148 suite = suite.lower()
150 origin = SuiteBlock["Origin"]
151 label = SuiteBlock.get("Label", origin)
152 version = SuiteBlock.get("Version", "")
153 codename = SuiteBlock.get("CodeName", "")
155 if SuiteBlock.has_key("NotAutomatic"):
160 if SuiteBlock.has_key("Components"):
161 components = SuiteBlock.ValueList("Components")
165 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix");
166 if components and suite_suffix:
167 longsuite = suite + "/" + suite_suffix;
171 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
173 if AptCnf.has_key("tree::%s" % (tree)):
175 elif AptCnf.has_key("bindirectory::%s" % (tree)):
178 aptcnf_filename = os.path.basename(utils.which_apt_conf_file());
179 print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename);
182 print Cnf["Dir::Root"] + tree + "/Release"
183 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
185 out.write("Origin: %s\n" % (origin))
186 out.write("Label: %s\n" % (label))
187 out.write("Suite: %s\n" % (suite))
189 out.write("Version: %s\n" % (version))
191 out.write("Codename: %s\n" % (codename))
192 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
193 if notautomatic != "":
194 out.write("NotAutomatic: %s\n" % (notautomatic))
195 out.write("Architectures: %s\n" % (" ".join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
197 out.write("Components: %s\n" % (" ".join(components)))
199 out.write("Description: %s\n" % (SuiteBlock["Description"]))
203 if AptCnf.has_key("tree::%s" % (tree)):
204 for sec in AptCnf["tree::%s::Sections" % (tree)].split():
205 for arch in AptCnf["tree::%s::Architectures" % (tree)].split():
207 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
210 disks = "%s/disks-%s" % (sec, arch)
211 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
212 if os.path.exists(diskspath):
213 for dir in os.listdir(diskspath):
214 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
215 files.append("%s/%s/md5sum.txt" % (disks, dir))
217 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
221 rel = "%s/%s/Release" % (sec, arch)
223 rel = "%s/binary-%s/Release" % (sec, arch)
224 relpath = Cnf["Dir::Root"]+tree+"/"+rel
227 release = open(relpath, "w")
228 #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
230 utils.fubar("Couldn't write to " + relpath);
232 release.write("Archive: %s\n" % (suite))
234 release.write("Version: %s\n" % (version))
236 release.write("Component: %s/%s\n" % (suite_suffix,sec));
238 release.write("Component: %s\n" % (sec));
239 release.write("Origin: %s\n" % (origin))
240 release.write("Label: %s\n" % (label))
241 if notautomatic != "":
242 release.write("NotAutomatic: %s\n" % (notautomatic))
243 release.write("Architecture: %s\n" % (arch))
247 if AptCnf.has_key("tree::%s/main" % (tree)):
248 sec = AptCnf["tree::%s/main::Sections" % (tree)].split()[0]
249 if sec != "debian-installer":
250 print "ALERT: weird non debian-installer section in %s" % (tree)
252 for arch in AptCnf["tree::%s/main::Architectures" % (tree)].split():
253 if arch != "source": # always true
254 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
256 elif AptCnf.has_key("tree::%s::FakeDI" % (tree)):
257 usetree = AptCnf["tree::%s::FakeDI" % (tree)]
258 sec = AptCnf["tree::%s/main::Sections" % (usetree)].split()[0]
259 if sec != "debian-installer":
260 print "ALERT: weird non debian-installer section in %s" % (usetree)
262 for arch in AptCnf["tree::%s/main::Architectures" % (usetree)].split():
263 if arch != "source": # always true
264 for file in compressnames("tree::%s/main" % (usetree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
267 elif AptCnf.has_key("bindirectory::%s" % (tree)):
268 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
269 files.append(file.replace(tree+"/","",1))
270 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
271 files.append(file.replace(tree+"/","",1))
273 print "ALERT: no tree/bindirectory for %s" % (tree)
275 out.write("MD5Sum:\n")
276 print_md5_files(tree, files)
278 print_sha1_files(tree, files)
281 if Cnf.has_key("Dinstall::SigningKeyring"):
282 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
283 if Cnf.has_key("Dinstall::SigningPubKeyring"):
284 keyring += " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
286 arguments = "--no-options --batch --no-tty --armour"
287 if Cnf.has_key("Dinstall::SigningKeyIds"):
288 signkeyids = Cnf["Dinstall::SigningKeyIds"].split()
292 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
293 if os.path.exists(dest):
296 for keyid in signkeyids:
297 if keyid != "": defkeyid = "--default-key %s" % keyid
299 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
300 (keyring, defkeyid, arguments,
301 Cnf["Dir::Root"] + tree + "/Release", dest))
303 #######################################################################################
305 if __name__ == '__main__':