]> git.decadent.org.uk Git - dak.git/blob - ziyi
usage() + options cleanup
[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.8 2001-09-27 01:22:51 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 pg, sys, os, stat, string, time
27 import utils, db_access
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     for mode in string.split(compress):
51         if mode == ".":
52             result.append(file)
53         elif mode == "gzip":
54             result.append(file + ".gz")
55         elif mode == "bzip2":
56             result.append(file + ".bz2")
57     return result
58
59 def print_md5_files (tree, files):
60     path = Cnf["Dir::RootDir"] + tree + "/"
61     for name in files:
62         try:
63             file_handle = utils.open_file(path + name, "r")
64         except utils.cant_open_exc:
65             print "ALERT: Couldn't open " + path + name
66         else:
67             md5 = apt_pkg.md5sum(file_handle)
68             file_handle.close()
69
70         size = os.stat(path + name)[stat.ST_SIZE]
71         out.write(" %s         %8d %s\n" % (md5, size, name))
72
73 def print_sha1_files (tree, files):
74     path = Cnf["Dir::RootDir"] + tree + "/"
75     for name in files:
76         try:
77             file_handle = utils.open_file(path + name, "r")
78         except utils.cant_open_exc:
79             print "ALERT: Couldn't open " + path + name
80         else:
81             sha1 = apt_pkg.sha1sum(file_handle)
82             file_handle.close()
83
84         size = os.stat(path + name)[stat.ST_SIZE]
85         out.write(" %s %8d %s\n" % (sha1, size, name))
86
87 ################################################################################
88
89 def main ():
90     global Cnf, AptCnf, projectB, out
91     out = sys.stdout;
92
93
94     apt_pkg.init()
95
96     Cnf = apt_pkg.newConfiguration()
97     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file())
98
99     AptCnf = apt_pkg.newConfiguration()
100     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
101
102     Arguments = [('h',"help","Ziyi::Options::Help")];
103     for i in [ "help" ]:
104         Cnf["Ziyi::Options::%s" % (i)] = "";
105
106     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
107     Options = Cnf.SubTree("Ziyi::Options")
108
109     if Options["Help"]:
110         usage();
111
112     if suites == []:
113         suites = Cnf.SubTree("Suite").List()
114
115     def real_arch(x):
116         return x != "source" and x != "all"
117
118     for suite in suites:
119         print "Processing: " + suite
120         SuiteBlock = Cnf.SubTree("Suite::" + suite)
121
122         if SuiteBlock.has_key("Untouchable"):
123             print "Skipping: " + suite + " (untouchable)"
124             continue
125
126         suite = string.lower(suite)
127
128         origin = SuiteBlock["Origin"]
129         label = SuiteBlock.get("Label", origin)
130         version = SuiteBlock.get("Version", "")
131         codename = SuiteBlock.get("CodeName", "")
132
133         if SuiteBlock.has_key("NotAutomatic"):
134             notautomatic = "yes"
135         else:
136             notautomatic = ""
137
138         if SuiteBlock.has_key("Components"):
139             components = SuiteBlock.SubTree("Components").List()
140         else:
141             components = []
142
143         nonus = 1
144         if components != []:
145             for c in components:
146                 if c[:7] != "non-US/":
147                     nonus = 0
148         else:
149             nonus = 0
150         if nonus:
151             longsuite = suite + "/non-US"
152         else:
153             longsuite = suite
154
155         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
156
157         print Cnf["Dir::RootDir"] + tree + "/Release"
158         out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
159
160         out.write("Origin: %s\n" % (origin))
161         out.write("Label: %s\n" % (label))
162         out.write("Suite: %s\n" % (suite))
163         if version != "":
164             out.write("Version: %s\n" % (version))
165         if codename != "":
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()))))
171         if components != []:
172             out.write("Components: %s\n" % (string.join(components)))
173
174         out.write("Description: %s\n" % (SuiteBlock["Description"]))
175
176         files = []
177
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)]):
181                     if arch == "source":
182                         for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
183                             files.append(file)
184                     else:
185                         rel = "%s/binary-%s/Release" % (sec, arch)
186                         relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
187                         if os.path.exists(relpath):
188                             try:
189                                 release = open(relpath, "w")
190                                 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
191                             except IOError:
192                                 print "Couldn't write to " + relpath
193                             else:
194                                 release.write("Archive: %s\n" % (suite))
195                                 if version != "":
196                                     release.write("Version: %s\n" % (version))
197                                 if nonus:
198                                     release.write("Component: non-US/%s\n" % (sec))
199                                 else:
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))
206                                 release.close()
207                             files.append("%s/binary-%s/Release" % (sec,arch))
208
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))
215
216                         for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
217                             files.append(file)
218
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)
223
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)):
227                             files.append(file)
228
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))
234         else:
235             print "ALERT: no tree/bindirectory for %s" % (tree)
236
237         out.write("MD5Sum:\n")
238         print_md5_files(tree, files)
239         out.write("SHA1:\n")
240         print_sha1_files(tree, files)
241
242         out.close()
243         if Cnf.has_key("Dinstall::SigningKeyring"):
244             dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
245             if os.path.exists(dest):
246                  os.unlink(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))
249
250 #######################################################################################
251
252 if __name__ == '__main__':
253     main()
254