3 # Create all the Release files
5 # Copyright (C) 2001 Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.11 2001-11-24 18:44:14 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)
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)
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
93 Cnf = utils.get_conf()
95 AptCnf = apt_pkg.newConfiguration()
96 apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
98 Arguments = [('h',"help","Ziyi::Options::Help")];
100 if not Cnf.has_key("Ziyi::Options::%s" % (i)):
101 Cnf["Ziyi::Options::%s" % (i)] = "";
103 suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
104 Options = Cnf.SubTree("Ziyi::Options")
110 suites = Cnf.SubTree("Suite").List()
113 return x != "source" and x != "all"
116 print "Processing: " + suite
117 SuiteBlock = Cnf.SubTree("Suite::" + suite)
119 if SuiteBlock.has_key("Untouchable"):
120 print "Skipping: " + suite + " (untouchable)"
123 suite = string.lower(suite)
125 origin = SuiteBlock["Origin"]
126 label = SuiteBlock.get("Label", origin)
127 version = SuiteBlock.get("Version", "")
128 codename = SuiteBlock.get("CodeName", "")
130 if SuiteBlock.has_key("NotAutomatic"):
135 if SuiteBlock.has_key("Components"):
136 components = SuiteBlock.SubTree("Components").List()
143 if string.find(c, "non-US/") != 0:
148 longsuite = suite + "/non-US"
152 tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
154 if AptCnf.has_key("tree::%s" % (tree)):
156 elif AptCnf.has_key("bindirectory::%s" % (tree)):
159 print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
162 print Cnf["Dir::RootDir"] + tree + "/Release"
163 out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
165 out.write("Origin: %s\n" % (origin))
166 out.write("Label: %s\n" % (label))
167 out.write("Suite: %s\n" % (suite))
169 out.write("Version: %s\n" % (version))
171 out.write("Codename: %s\n" % (codename))
172 out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
173 if notautomatic != "":
174 out.write("NotAutomatic: %s\n" % (notautomatic))
175 out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
177 out.write("Components: %s\n" % (string.join(components)))
179 out.write("Description: %s\n" % (SuiteBlock["Description"]))
183 if AptCnf.has_key("tree::%s" % (tree)):
184 for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
185 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
187 for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
190 disks = "%s/disks-%s" % (sec, arch)
191 diskspath = Cnf["Dir::RootDir"]+tree+"/"+disks
192 if os.path.exists(diskspath):
193 for dir in os.listdir(diskspath):
194 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
195 files.append("%s/%s/md5sum.txt" % (disks, dir))
197 for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
201 rel = "%s/%s/Release" % (sec, arch)
203 rel = "%s/binary-%s/Release" % (sec, arch)
204 relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
206 if os.path.exists(relpath):
208 release = open(relpath, "w")
209 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
211 print "Couldn't write to " + relpath
213 release.write("Archive: %s\n" % (suite))
215 release.write("Version: %s\n" % (version))
217 release.write("Component: non-US/%s\n" % (sec))
219 release.write("Component: %s\n" % (sec))
220 release.write("Origin: %s\n" % (origin))
221 release.write("Label: %s\n" % (label))
222 if notautomatic != "":
223 release.write("NotAutomatic: %s\n" % (notautomatic))
224 release.write("Architecture: %s\n" % (arch))
228 if AptCnf.has_key("tree::%s/main" % (tree)):
229 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
230 if sec != "debian-installer":
231 print "ALERT: weird non debian-installer section in %s" % (tree)
233 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
234 if arch != "source": # always true
235 for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
238 elif AptCnf.has_key("bindirectory::%s" % (tree)):
239 for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
240 files.append(string.replace(file,tree+"/","",1))
241 for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
242 files.append(string.replace(file,tree+"/","",1))
244 print "ALERT: no tree/bindirectory for %s" % (tree)
246 out.write("MD5Sum:\n")
247 print_md5_files(tree, files)
249 print_sha1_files(tree, files)
252 if Cnf.has_key("Dinstall::SigningKeyring"):
253 dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
254 if os.path.exists(dest):
256 os.system("gpg --secret-keyring \"%s\" --no-options --batch --no-tty --armour --detach-sign <%s --output=%s" % (Cnf["Dinstall::SigningKeyring"],
257 Cnf["Dir::RootDir"] + tree + "/Release", dest))
259 #######################################################################################
261 if __name__ == '__main__':