3 # Create all the Release files
5 # Copyright (C) 2001 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.8 2001-09-27 01:22:51 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 pg, sys, os, stat, string, time
27 import utils, db_access
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 for mode in string.split(compress):
54 result.append(file + ".gz")
56 result.append(file + ".bz2")
59 def print_md5_files (tree, files):
60 path = Cnf["Dir::RootDir"] + tree + "/"
63 file_handle = utils.open_file(path + name, "r")
64 except utils.cant_open_exc:
65 print "ALERT: Couldn't open " + path + name
67 md5 = apt_pkg.md5sum(file_handle)
70 size = os.stat(path + name)[stat.ST_SIZE]
71 out.write(" %s %8d %s\n" % (md5, size, name))
73 def print_sha1_files (tree, files):
74 path = Cnf["Dir::RootDir"] + tree + "/"
77 file_handle = utils.open_file(path + name, "r")
78 except utils.cant_open_exc:
79 print "ALERT: Couldn't open " + path + name
81 sha1 = apt_pkg.sha1sum(file_handle)
84 size = os.stat(path + name)[stat.ST_SIZE]
85 out.write(" %s %8d %s\n" % (sha1, size, name))
87 ################################################################################
90 global Cnf, AptCnf, projectB, out
96 Cnf = apt_pkg.newConfiguration()
97 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file())
99 AptCnf = apt_pkg.newConfiguration()
100 apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
102 Arguments = [('h',"help","Ziyi::Options::Help")];
104 Cnf["Ziyi::Options::%s" % (i)] = "";
106 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
107 Options = Cnf.SubTree("Ziyi::Options")
113 suites = Cnf.SubTree("Suite").List()
116 return x != "source" and x != "all"
119 print "Processing: " + suite
120 SuiteBlock = Cnf.SubTree("Suite::" + suite)
122 if SuiteBlock.has_key("Untouchable"):
123 print "Skipping: " + suite + " (untouchable)"
126 suite = string.lower(suite)
128 origin = SuiteBlock["Origin"]
129 label = SuiteBlock.get("Label", origin)
130 version = SuiteBlock.get("Version", "")
131 codename = SuiteBlock.get("CodeName", "")
133 if SuiteBlock.has_key("NotAutomatic"):
138 if SuiteBlock.has_key("Components"):
139 components = SuiteBlock.SubTree("Components").List()
146 if c[:7] != "non-US/":
151 longsuite = suite + "/non-US"
155 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
157 print Cnf["Dir::RootDir"] + tree + "/Release"
158 out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
160 out.write("Origin: %s\n" % (origin))
161 out.write("Label: %s\n" % (label))
162 out.write("Suite: %s\n" % (suite))
164 out.write("Version: %s\n" % (version))
166 out.write("Codename: %s\n" % (codename))
167 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
168 if notautomatic != "":
169 out.write("NotAutomatic: %s\n" % (notautomatic))
170 out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
172 out.write("Components: %s\n" % (string.join(components)))
174 out.write("Description: %s\n" % (SuiteBlock["Description"]))
178 if AptCnf.has_key("tree::%s" % (tree)):
179 for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
180 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
182 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
185 rel = "%s/binary-%s/Release" % (sec, arch)
186 relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
187 if os.path.exists(relpath):
189 release = open(relpath, "w")
190 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
192 print "Couldn't write to " + relpath
194 release.write("Archive: %s\n" % (suite))
196 release.write("Version: %s\n" % (version))
198 release.write("Component: non-US/%s\n" % (sec))
200 release.write("Component: %s\n" % (sec))
201 release.write("Origin: %s\n" % (origin))
202 release.write("Label: %s\n" % (label))
203 if notautomatic != "":
204 release.write("NotAutomatic: %s\n" % (notautomatic))
205 release.write("Architecture: %s\n" % (arch))
207 files.append("%s/binary-%s/Release" % (sec,arch))
209 disks = "%s/disks-%s" % (sec, arch)
210 diskspath = Cnf["Dir::RootDir"]+tree+"/"+disks
211 if os.path.exists(diskspath):
212 for dir in os.listdir(diskspath):
213 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
214 files.append("%s/%s/md5sum.txt" % (disks, dir))
216 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
219 if AptCnf.has_key("tree::%s/main" % (tree)):
220 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
221 if sec != "debian-installer":
222 print "ALERT: weird non debian-installer section in %s" % (tree)
224 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
225 if arch != "source": # always true
226 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
229 elif AptCnf.has_key("bindirectory::%s" % (tree)):
230 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
231 files.append(string.replace(file,tree+"/","",1))
232 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
233 files.append(string.replace(file,tree+"/","",1))
235 print "ALERT: no tree/bindirectory for %s" % (tree)
237 out.write("MD5Sum:\n")
238 print_md5_files(tree, files)
240 print_sha1_files(tree, files)
243 if Cnf.has_key("Dinstall::SigningKeyring"):
244 dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
245 if os.path.exists(dest):
247 os.system("gpg --secret-keyring \"%s\" --no-options --batch --no-tty --armour --detach-sign <%s --output=%s" % (Cnf["Dinstall::SigningKeyring"],
248 Cnf["Dir::RootDir"] + tree + "/Release", dest))
250 #######################################################################################
252 if __name__ == '__main__':