3 # Create all the Release files
5 # Copyright (C) 2001 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.17 2002-02-12 22:14:38 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::RootDir"] + 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 longsuite = suite + "/non-US"
176 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
178 if AptCnf.has_key("tree::%s" % (tree)):
180 elif AptCnf.has_key("bindirectory::%s" % (tree)):
183 print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
186 print Cnf["Dir::RootDir"] + tree + "/Release"
187 out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
189 out.write("Origin: %s\n" % (origin))
190 out.write("Label: %s\n" % (label))
191 out.write("Suite: %s\n" % (suite))
193 out.write("Version: %s\n" % (version))
195 out.write("Codename: %s\n" % (codename))
196 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
197 if notautomatic != "":
198 out.write("NotAutomatic: %s\n" % (notautomatic))
199 out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
201 out.write("Components: %s\n" % (string.join(components)))
203 out.write("Description: %s\n" % (SuiteBlock["Description"]))
207 if AptCnf.has_key("tree::%s" % (tree)):
208 for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
209 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
211 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
214 disks = "%s/disks-%s" % (sec, arch)
215 diskspath = Cnf["Dir::RootDir"]+tree+"/"+disks
216 if os.path.exists(diskspath):
217 for dir in os.listdir(diskspath):
218 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
219 files.append("%s/%s/md5sum.txt" % (disks, dir))
221 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
225 rel = "%s/%s/Release" % (sec, arch)
227 rel = "%s/binary-%s/Release" % (sec, arch)
228 relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
230 if os.path.exists(relpath):
233 release = open(relpath, "w")
234 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
236 print "Couldn't write to " + relpath
238 release.write("Archive: %s\n" % (suite))
240 release.write("Version: %s\n" % (version))
242 release.write("Component: non-US/%s\n" % (sec))
244 release.write("Component: %s\n" % (sec))
245 release.write("Origin: %s\n" % (origin))
246 release.write("Label: %s\n" % (label))
247 if notautomatic != "":
248 release.write("NotAutomatic: %s\n" % (notautomatic))
249 release.write("Architecture: %s\n" % (arch))
253 if AptCnf.has_key("tree::%s/main" % (tree)):
254 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
255 if sec != "debian-installer":
256 print "ALERT: weird non debian-installer section in %s" % (tree)
258 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
259 if arch != "source": # always true
260 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
263 elif AptCnf.has_key("bindirectory::%s" % (tree)):
264 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
265 files.append(string.replace(file,tree+"/","",1))
266 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
267 files.append(string.replace(file,tree+"/","",1))
269 print "ALERT: no tree/bindirectory for %s" % (tree)
271 out.write("MD5Sum:\n")
272 print_md5_files(tree, files)
274 print_sha1_files(tree, files)
277 if Cnf.has_key("Dinstall::SigningKeyring"):
278 keyring = "--secret-keyring \"%s\"" % Cnf["Dinstall::SigningKeyring"]
279 if Cnf.has_key("Dinstall::SigningPubKeyring"):
280 keyring = keyring + " --keyring \"%s\"" % Cnf["Dinstall::SigningPubKeyring"]
282 arguments = "--no-options --batch --no-tty --armour"
283 if Cnf.has_key("Dinstall::SigningKeyIds"):
284 signkeyids = string.split(Cnf["Dinstall::SigningKeyIds"])
288 dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
289 if os.path.exists(dest):
292 for keyid in signkeyids:
293 if keyid != "": defkeyid = "--default-key %s" % keyid
295 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
296 (keyring, defkeyid, arguments,
297 Cnf["Dir::RootDir"] + tree + "/Release", dest))
299 #######################################################################################
301 if __name__ == '__main__':