]> git.donarmstrong.com Git - dak.git/blob - ziyi
add missing debug option
[dak.git] / ziyi
1 #!/usr/bin/env python
2
3 # Create all the Release files
4
5 # Copyright (C) 2001  Anthony Towns <ajt@debian.org>
6 # $Id: ziyi,v 1.17 2002-02-12 22:14:38 troup Exp $
7
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.
12
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.
17
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
21
22 #   ``Bored now''
23
24 ################################################################################
25
26 import sys, os, popen2, tempfile, stat, string, time
27 import utils
28 import apt_pkg
29
30 ################################################################################
31
32 Cnf = None
33 projectB = None
34
35 ################################################################################
36
37 def usage (exit_code=0):
38     print """Usage: ziyi [OPTION]
39 Generate Release files.
40
41   -h, --help                 show this help and exit"""
42
43     sys.exit(exit_code)
44
45 ################################################################################
46
47 def compressnames (tree,type,file):
48     compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
49     result = []
50     cl = string.split(compress)
51     uncompress = ("." not in cl)
52     for mode in string.split(compress):
53         if mode == ".":
54             result.append(file)
55         elif mode == "gzip":
56             if uncompress:
57                 result.append("<zcat/.gz>" + file)
58                 uncompress = 0
59             result.append(file + ".gz")
60         elif mode == "bzip2":
61             if uncompress:
62                 result.append("<bzcat/.bz2>" + file)
63                 uncompress = 0
64             result.append(file + ".bz2")
65     return result
66
67 def create_temp_file (cmd):
68     f = tempfile.TemporaryFile()
69     r = popen2.popen2(cmd)
70     r[1].close()
71     r = r[0]
72     size = 0
73     while 1:
74         x = r.readline()
75         if not x:
76             r.close()
77             del x,r
78             break
79         f.write(x)
80         size = size + len(x)
81     f.flush()
82     f.seek(0)
83     return (size, f)
84
85 def print_md5sha_files (tree, files, hashop):
86     path = Cnf["Dir::RootDir"] + tree + "/"
87     for name in files:
88         try:
89             if name[0] == "<":
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))
95             else:
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
100         else:
101             hash = hashop(file_handle)
102             file_handle.close()
103             out.write(" %s         %8d %s\n" % (hash, size, name))
104
105 def print_md5_files (tree, files):
106     print_md5sha_files (tree, files, apt_pkg.md5sum)
107
108 def print_sha1_files (tree, files):
109     print_md5sha_files (tree, files, apt_pkg.sha1sum)
110
111 ################################################################################
112
113 def main ():
114     global Cnf, AptCnf, projectB, out
115     out = sys.stdout;
116
117     Cnf = utils.get_conf()
118
119     AptCnf = apt_pkg.newConfiguration()
120     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
121
122     Arguments = [('h',"help","Ziyi::Options::Help")];
123     for i in [ "help" ]:
124         if not Cnf.has_key("Ziyi::Options::%s" % (i)):
125             Cnf["Ziyi::Options::%s" % (i)] = "";
126
127     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
128     Options = Cnf.SubTree("Ziyi::Options")
129
130     if Options["Help"]:
131         usage();
132
133     if not suites:
134         suites = Cnf.SubTree("Suite").List()
135
136     def real_arch(x):
137         return x != "source" and x != "all"
138
139     for suite in suites:
140         print "Processing: " + suite
141         SuiteBlock = Cnf.SubTree("Suite::" + suite)
142
143         if SuiteBlock.has_key("Untouchable"):
144             print "Skipping: " + suite + " (untouchable)"
145             continue
146
147         suite = string.lower(suite)
148
149         origin = SuiteBlock["Origin"]
150         label = SuiteBlock.get("Label", origin)
151         version = SuiteBlock.get("Version", "")
152         codename = SuiteBlock.get("CodeName", "")
153
154         if SuiteBlock.has_key("NotAutomatic"):
155             notautomatic = "yes"
156         else:
157             notautomatic = ""
158
159         if SuiteBlock.has_key("Components"):
160             components = SuiteBlock.SubTree("Components").List()
161         else:
162             components = []
163
164         nonus = 1
165         if components != []:
166             for c in components:
167                 if string.find(c, "non-US/") != 0:
168                     nonus = 0
169         else:
170             nonus = 0
171         if nonus:
172             longsuite = suite + "/non-US"
173         else:
174             longsuite = suite
175
176         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
177
178         if AptCnf.has_key("tree::%s" % (tree)):
179             pass
180         elif AptCnf.has_key("bindirectory::%s" % (tree)):
181             pass
182         else:
183             print "ALERT: suite %s not in apt.conf, nor untouchable!" % (suite)
184             continue
185
186         print Cnf["Dir::RootDir"] + tree + "/Release"
187         out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
188
189         out.write("Origin: %s\n" % (origin))
190         out.write("Label: %s\n" % (label))
191         out.write("Suite: %s\n" % (suite))
192         if version != "":
193             out.write("Version: %s\n" % (version))
194         if codename != "":
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()))))
200         if components != []:
201             out.write("Components: %s\n" % (string.join(components)))
202
203         out.write("Description: %s\n" % (SuiteBlock["Description"]))
204
205         files = []
206
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)]):
210                     if arch == "source":
211                         for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
212                             files.append(file)
213                     else:
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))
220
221                         for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
222                             files.append(file)
223
224                     if arch == "source":
225                         rel = "%s/%s/Release" % (sec, arch)
226                     else:
227                         rel = "%s/binary-%s/Release" % (sec, arch)
228                     relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
229
230                     if os.path.exists(relpath):
231                         try:
232                             os.unlink(relpath)
233                             release = open(relpath, "w")
234                             #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
235                         except IOError:
236                             print "Couldn't write to " + relpath
237                         else:
238                             release.write("Archive: %s\n" % (suite))
239                             if version != "":
240                                 release.write("Version: %s\n" % (version))
241                             if nonus:
242                                 release.write("Component: non-US/%s\n" % (sec))
243                             else:
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))
250                             release.close()
251                             files.append(rel)
252
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)
257
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)):
261                             files.append(file)
262
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))
268         else:
269             print "ALERT: no tree/bindirectory for %s" % (tree)
270
271         out.write("MD5Sum:\n")
272         print_md5_files(tree, files)
273         out.write("SHA1:\n")
274         print_sha1_files(tree, files)
275
276         out.close()
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"]
281
282             arguments = "--no-options --batch --no-tty --armour"
283             if Cnf.has_key("Dinstall::SigningKeyIds"):
284                 signkeyids = string.split(Cnf["Dinstall::SigningKeyIds"])
285             else:
286                 signkeyids = [""]
287
288             dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
289             if os.path.exists(dest):
290                 os.unlink(dest)
291
292             for keyid in signkeyids:
293                 if keyid != "": defkeyid = "--default-key %s" % keyid
294                 else: defkeyid = ""
295                 os.system("gpg %s %s %s --detach-sign <%s >>%s" %
296                         (keyring, defkeyid, arguments,
297                         Cnf["Dir::RootDir"] + tree + "/Release", dest))
298
299 #######################################################################################
300
301 if __name__ == '__main__':
302     main()
303