3 # Create all the Release files
5 # Copyright (C) 2001, 2002 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.18 2002-05-08 11:17:53 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 ################################################################################
35 ################################################################################
37 def usage (exit_code=0):
38 print """Usage: ziyi [OPTION]
39 Generate Release files.
41 -h, --help show this help and exit"""
45 ################################################################################
47 def compressnames (tree,type,file):
48 compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
50 cl = string.split(compress)
51 uncompress = ("." not in cl)
52 for mode in string.split(compress):
57 result.append("<zcat/.gz>" + file)
59 result.append(file + ".gz")
62 result.append("<bzcat/.bz2>" + file)
64 result.append(file + ".bz2")
67 def create_temp_file (cmd):
68 f = tempfile.TemporaryFile()
69 r = popen2.popen2(cmd)
85 def print_md5sha_files (tree, files, hashop):
86 path = Cnf["Dir::Root"] + tree + "/"
90 j = string.index(name, "/")
91 k = string.index(name, ">")
92 (cat, ext, name) = (name[1:j], name[j+1:k], name[k+1:])
93 (size, file_handle) = create_temp_file("%s %s%s%s" %
94 (cat, path, name, ext))
96 size = os.stat(path + name)[stat.ST_SIZE]
97 file_handle = utils.open_file(path + name)
98 except utils.cant_open_exc:
99 print "ALERT: Couldn't open " + path + name
101 hash = hashop(file_handle)
103 out.write(" %s %8d %s\n" % (hash, size, name))
105 def print_md5_files (tree, files):
106 print_md5sha_files (tree, files, apt_pkg.md5sum)
108 def print_sha1_files (tree, files):
109 print_md5sha_files (tree, files, apt_pkg.sha1sum)
111 ################################################################################
114 global Cnf, AptCnf, projectB, out
117 Cnf = utils.get_conf()
119 AptCnf = apt_pkg.newConfiguration()
120 apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
122 Arguments = [('h',"help","Ziyi::Options::Help")];
124 if not Cnf.has_key("Ziyi::Options::%s" % (i)):
125 Cnf["Ziyi::Options::%s" % (i)] = "";
127 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
128 Options = Cnf.SubTree("Ziyi::Options")
134 suites = Cnf.SubTree("Suite").List()
137 return x != "source" and x != "all"
140 print "Processing: " + suite
141 SuiteBlock = Cnf.SubTree("Suite::" + suite)
143 if SuiteBlock.has_key("Untouchable"):
144 print "Skipping: " + suite + " (untouchable)"
147 suite = string.lower(suite)
149 origin = SuiteBlock["Origin"]
150 label = SuiteBlock.get("Label", origin)
151 version = SuiteBlock.get("Version", "")
152 codename = SuiteBlock.get("CodeName", "")
154 if SuiteBlock.has_key("NotAutomatic"):
159 if SuiteBlock.has_key("Components"):
160 components = SuiteBlock.SubTree("Components").List()
167 if string.find(c, "non-US/") != 0:
172 if not nonus and string.find(codename, "/updates") > 0:
178 longsuite = suite + "/non-US"
180 suite = suite + "/updates"
185 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
187 if AptCnf.has_key("tree::%s" % (tree)):
189 elif AptCnf.has_key("bindirectory::%s" % (tree)):
192 print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
195 print Cnf["Dir::Root"] + tree + "/Release"
196 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
198 out.write("Origin: %s\n" % (origin))
199 out.write("Label: %s\n" % (label))
200 out.write("Suite: %s\n" % (suite))
202 out.write("Version: %s\n" % (version))
204 out.write("Codename: %s\n" % (codename))
205 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
206 if notautomatic != "":
207 out.write("NotAutomatic: %s\n" % (notautomatic))
208 out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
210 out.write("Components: %s\n" % (string.join(components)))
212 out.write("Description: %s\n" % (SuiteBlock["Description"]))
216 if AptCnf.has_key("tree::%s" % (tree)):
217 for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
218 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
220 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
223 disks = "%s/disks-%s" % (sec, arch)
224 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
225 if os.path.exists(diskspath):
226 for dir in os.listdir(diskspath):
227 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
228 files.append("%s/%s/md5sum.txt" % (disks, dir))
230 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
234 rel = "%s/%s/Release" % (sec, arch)
236 rel = "%s/binary-%s/Release" % (sec, arch)
237 relpath = Cnf["Dir::Root"]+tree+"/"+rel
239 if os.path.exists(relpath):
242 release = open(relpath, "w")
243 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
245 print "Couldn't write to " + relpath
247 release.write("Archive: %s\n" % (suite))
249 release.write("Version: %s\n" % (version))
251 release.write("Component: non-US/%s\n" % (sec))
253 release.write("Component: %s\n" % (sec))
254 release.write("Origin: %s\n" % (origin))
255 release.write("Label: %s\n" % (label))
256 if notautomatic != "":
257 release.write("NotAutomatic: %s\n" % (notautomatic))
258 release.write("Architecture: %s\n" % (arch))
262 if AptCnf.has_key("tree::%s/main" % (tree)):
263 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
264 if sec != "debian-installer":
265 print "ALERT: weird non debian-installer section in %s" % (tree)
267 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
268 if arch != "source": # always true
269 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
272 elif AptCnf.has_key("bindirectory::%s" % (tree)):
273 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
274 files.append(string.replace(file,tree+"/","",1))
275 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
276 files.append(string.replace(file,tree+"/","",1))
278 print "ALERT: no tree/bindirectory for %s" % (tree)
280 out.write("MD5Sum:\n")
281 print_md5_files(tree, files)
283 print_sha1_files(tree, files)
286 if Cnf.has_key("Dinstall::SigningKeyring"):
287 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
288 if Cnf.has_key("Dinstall::SigningPubKeyring"):
289 keyring = keyring + " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
291 arguments = "--no-options --batch --no-tty --armour"
292 if Cnf.has_key("Dinstall::SigningKeyIds"):
293 signkeyids = string.split(Cnf["Dinstall::SigningKeyIds"])
297 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
298 if os.path.exists(dest):
301 for keyid in signkeyids:
302 if keyid != "": defkeyid = "--default-key %s" % keyid
304 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
305 (keyring, defkeyid, arguments,
306 Cnf["Dir::Root"] + tree + "/Release", dest))
308 #######################################################################################
310 if __name__ == '__main__':