3 # Create all the Release files
5 # Copyright (C) 2001, 2002 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.21 2002-05-18 23:54:59 troup 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, string, time
30 ################################################################################
37 ################################################################################
39 def usage (exit_code=0):
40 print """Usage: ziyi [OPTION]
41 Generate Release files.
43 -h, --help show this help and exit"""
47 ################################################################################
49 def compressnames (tree,type,file):
50 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
52 cl = string.split(compress)
53 uncompress = ("." not in cl)
54 for mode in string.split(compress):
59 result.append("<zcat/.gz>" + file)
61 result.append(file + ".gz")
64 result.append("<bzcat/.bz2>" + file)
66 result.append(file + ".bz2")
69 def create_temp_file (cmd):
70 f = tempfile.TemporaryFile()
71 r = popen2.popen2(cmd)
87 def print_md5sha_files (tree, files, hashop):
88 path = Cnf["Dir::Root"] + tree + "/"
92 j = string.index(name, "/")
93 k = string.index(name, ">")
94 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
95 (size, file_handle) = create_temp_file("%s %s%s%s" %
96 (cat, path, name, ext))
98 size = os.stat(path + name)[stat.ST_SIZE]
99 file_handle = utils.open_file(path + name)
100 except utils.cant_open_exc:
101 print "ALERT: Couldn't open " + path + name
103 hash = hashop(file_handle)
105 out.write(" %s %8d %s\n" % (hash, size, name))
107 def print_md5_files (tree, files):
108 print_md5sha_files (tree, files, apt_pkg.md5sum)
110 def print_sha1_files (tree, files):
111 print_md5sha_files (tree, files, apt_pkg.sha1sum)
113 ################################################################################
116 global Cnf, AptCnf, projectB, out
119 Cnf = utils.get_conf()
121 AptCnf = apt_pkg.newConfiguration()
122 apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
124 Arguments = [('h',"help","Ziyi::Options::Help")];
126 if not Cnf.has_key("Ziyi::Options::%s" % (i)):
127 Cnf["Ziyi::Options::%s" % (i)] = "";
129 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
130 Options = Cnf.SubTree("Ziyi::Options")
136 suites = Cnf.SubTree("Suite").List()
139 return x != "source" and x != "all"
142 print "Processing: " + suite
143 SuiteBlock = Cnf.SubTree("Suite::" + suite)
145 if SuiteBlock.has_key("Untouchable"):
146 print "Skipping: " + suite + " (untouchable)"
149 suite = string.lower(suite)
151 origin = SuiteBlock["Origin"]
152 label = SuiteBlock.get("Label", origin)
153 version = SuiteBlock.get("Version", "")
154 codename = SuiteBlock.get("CodeName", "")
156 if SuiteBlock.has_key("NotAutomatic"):
161 if SuiteBlock.has_key("Components"):
162 components = SuiteBlock.ValueList("Components")
169 if string.find(c, "non-US/") != 0:
174 if not nonus and string.find(codename, "/updates") > 0:
180 longsuite = suite + "/non-US"
182 suite = suite + "/updates"
187 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
189 if AptCnf.has_key("tree::%s" % (tree)):
191 elif AptCnf.has_key("bindirectory::%s" % (tree)):
194 print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
197 print Cnf["Dir::Root"] + tree + "/Release"
198 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
200 out.write("Origin: %s\n" % (origin))
201 out.write("Label: %s\n" % (label))
202 out.write("Suite: %s\n" % (suite))
204 out.write("Version: %s\n" % (version))
206 out.write("Codename: %s\n" % (codename))
207 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
208 if notautomatic != "":
209 out.write("NotAutomatic: %s\n" % (notautomatic))
210 out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.ValueList("Architectures")))))
212 out.write("Components: %s\n" % (string.join(components)))
214 out.write("Description: %s\n" % (SuiteBlock["Description"]))
218 if AptCnf.has_key("tree::%s" % (tree)):
219 for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
220 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
222 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
225 disks = "%s/disks-%s" % (sec, arch)
226 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
227 if os.path.exists(diskspath):
228 for dir in os.listdir(diskspath):
229 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
230 files.append("%s/%s/md5sum.txt" % (disks, dir))
232 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
236 rel = "%s/%s/Release" % (sec, arch)
238 rel = "%s/binary-%s/Release" % (sec, arch)
239 relpath = Cnf["Dir::Root"]+tree+"/"+rel
241 if os.path.exists(relpath):
244 release = open(relpath, "w")
245 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
247 print "Couldn't write to " + relpath
249 release.write("Archive: %s\n" % (suite))
251 release.write("Version: %s\n" % (version))
253 release.write("Component: non-US/%s\n" % (sec))
255 release.write("Component: %s\n" % (sec))
256 release.write("Origin: %s\n" % (origin))
257 release.write("Label: %s\n" % (label))
258 if notautomatic != "":
259 release.write("NotAutomatic: %s\n" % (notautomatic))
260 release.write("Architecture: %s\n" % (arch))
264 if AptCnf.has_key("tree::%s/main" % (tree)):
265 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
266 if sec != "debian-installer":
267 print "ALERT: weird non debian-installer section in %s" % (tree)
269 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
270 if arch != "source": # always true
271 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
274 elif AptCnf.has_key("bindirectory::%s" % (tree)):
275 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
276 files.append(string.replace(file,tree+"/","",1))
277 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
278 files.append(string.replace(file,tree+"/","",1))
280 print "ALERT: no tree/bindirectory for %s" % (tree)
282 out.write("MD5Sum:\n")
283 print_md5_files(tree, files)
285 print_sha1_files(tree, files)
288 if Cnf.has_key("Dinstall::SigningKeyring"):
289 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
290 if Cnf.has_key("Dinstall::SigningPubKeyring"):
291 keyring = keyring + " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
293 arguments = "--no-options --batch --no-tty --armour"
294 if Cnf.has_key("Dinstall::SigningKeyIds"):
295 signkeyids = string.split(Cnf["Dinstall::SigningKeyIds"])
299 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
300 if os.path.exists(dest):
303 for keyid in signkeyids:
304 if keyid != "": defkeyid = "--default-key %s" % keyid
306 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
307 (keyring, defkeyid, arguments,
308 Cnf["Dir::Root"] + tree + "/Release", dest))
310 #######################################################################################
312 if __name__ == '__main__':