3 # Create all the Release files
5 # Copyright (C) 2001, 2002 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.22 2002-06-08 00:18:47 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 print "Processing: " + suite
140 SuiteBlock = Cnf.SubTree("Suite::" + suite)
142 if SuiteBlock.has_key("Untouchable"):
143 print "Skipping: " + suite + " (untouchable)"
146 suite = string.lower(suite)
148 origin = SuiteBlock["Origin"]
149 label = SuiteBlock.get("Label", origin)
150 version = SuiteBlock.get("Version", "")
151 codename = SuiteBlock.get("CodeName", "")
153 if SuiteBlock.has_key("NotAutomatic"):
158 if SuiteBlock.has_key("Components"):
159 components = SuiteBlock.ValueList("Components")
163 suite_suffix = Cnf.Find("Dinstall::SuiteSuffix");
164 if components and suite_suffix:
165 longsuite = suite + "/" + suite_suffix;
169 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
171 if AptCnf.has_key("tree::%s" % (tree)):
173 elif AptCnf.has_key("bindirectory::%s" % (tree)):
176 print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
179 print Cnf["Dir::Root"] + tree + "/Release"
180 out = open(Cnf["Dir::Root"] + tree + "/Release", "w")
182 out.write("Origin: %s\n" % (origin))
183 out.write("Label: %s\n" % (label))
184 out.write("Suite: %s\n" % (suite))
186 out.write("Version: %s\n" % (version))
188 out.write("Codename: %s\n" % (codename))
189 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
190 if notautomatic != "":
191 out.write("NotAutomatic: %s\n" % (notautomatic))
192 out.write("Architectures: %s\n" % (string.join(filter(utils.real_arch, SuiteBlock.ValueList("Architectures")))))
194 out.write("Components: %s\n" % (string.join(components)))
196 out.write("Description: %s\n" % (SuiteBlock["Description"]))
200 if AptCnf.has_key("tree::%s" % (tree)):
201 for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
202 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
204 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
207 disks = "%s/disks-%s" % (sec, arch)
208 diskspath = Cnf["Dir::Root"]+tree+"/"+disks
209 if os.path.exists(diskspath):
210 for dir in os.listdir(diskspath):
211 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
212 files.append("%s/%s/md5sum.txt" % (disks, dir))
214 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
218 rel = "%s/%s/Release" % (sec, arch)
220 rel = "%s/binary-%s/Release" % (sec, arch)
221 relpath = Cnf["Dir::Root"]+tree+"/"+rel
224 release = open(relpath, "w")
225 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
227 utils.fubar("Couldn't write to " + relpath);
229 release.write("Archive: %s\n" % (suite))
231 release.write("Version: %s\n" % (version))
233 release.write("Component: %s/%s\n" % (suite_suffix,sec));
235 release.write("Component: %s\n" % (sec));
236 release.write("Origin: %s\n" % (origin))
237 release.write("Label: %s\n" % (label))
238 if notautomatic != "":
239 release.write("NotAutomatic: %s\n" % (notautomatic))
240 release.write("Architecture: %s\n" % (arch))
244 if AptCnf.has_key("tree::%s/main" % (tree)):
245 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
246 if sec != "debian-installer":
247 print "ALERT: weird non debian-installer section in %s" % (tree)
249 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
250 if arch != "source": # always true
251 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
254 elif AptCnf.has_key("bindirectory::%s" % (tree)):
255 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
256 files.append(string.replace(file,tree+"/","",1))
257 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
258 files.append(string.replace(file,tree+"/","",1))
260 print "ALERT: no tree/bindirectory for %s" % (tree)
262 out.write("MD5Sum:\n")
263 print_md5_files(tree, files)
265 print_sha1_files(tree, files)
268 if Cnf.has_key("Dinstall::SigningKeyring"):
269 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
270 if Cnf.has_key("Dinstall::SigningPubKeyring"):
271 keyring = keyring + " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
273 arguments = "--no-options --batch --no-tty --armour"
274 if Cnf.has_key("Dinstall::SigningKeyIds"):
275 signkeyids = string.split(Cnf["Dinstall::SigningKeyIds"])
279 dest = Cnf["Dir::Root"] + tree + "/Release.gpg"
280 if os.path.exists(dest):
283 for keyid in signkeyids:
284 if keyid != "": defkeyid = "--default-key %s" % keyid
286 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
287 (keyring, defkeyid, arguments,
288 Cnf["Dir::Root"] + tree + "/Release", dest))
290 #######################################################################################
292 if __name__ == '__main__':