]> git.decadent.org.uk Git - dak.git/blob - ziyi
add functional help to melanie
[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.6 2001-05-05 07:20:57 ajt 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 compressnames (tree,type,file):
38     compress = AptCnf.get("%s::%s::Compress" % (tree,type), AptCnf.get("Default::%s::Compress" % (type), ". gzip"))
39     result = []
40     for mode in string.split(compress):
41         if mode == ".":
42             result.append(file)
43         elif mode == "gzip":
44             result.append(file + ".gz")
45         elif mode == "bzip2":
46             result.append(file + ".bz2")
47     return result
48
49 def print_md5_files (tree, files):
50     path = Cnf["Dir::RootDir"] + tree + "/"
51     for name in files:
52         try:
53             file_handle = utils.open_file(path + name, "r")
54         except utils.cant_open_exc:
55             print "ALERT: Couldn't open " + path + name
56         else:
57             md5 = apt_pkg.md5sum(file_handle)
58             file_handle.close()
59
60         size = os.stat(path + name)[stat.ST_SIZE]
61         out.write(" %s         %8d %s\n" % (md5, size, name))
62
63 def print_sha1_files (tree, files):
64     path = Cnf["Dir::RootDir"] + tree + "/"
65     for name in files:
66         try:
67             file_handle = utils.open_file(path + name, "r")
68         except utils.cant_open_exc:
69             print "ALERT: Couldn't open " + path + name
70         else:
71             sha1 = apt_pkg.sha1sum(file_handle)
72             file_handle.close()
73
74         size = os.stat(path + name)[stat.ST_SIZE]
75         out.write(" %s %8d %s\n" % (sha1, size, name))
76
77 ################################################################################
78
79 def main ():
80     global Cnf, AptCnf, projectB, out
81     out = sys.stdout;
82
83
84     apt_pkg.init()
85     
86     Cnf = apt_pkg.newConfiguration()
87     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file())
88
89     AptCnf = apt_pkg.newConfiguration()
90     apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
91     print "APT.CONF IS: " + utils.which_apt_conf_file()
92
93     Arguments = [('d',"debug","Ziyi::Options::Debug", "IntVal"),
94                  ('h',"help","Ziyi::Options::Help"),
95                  ('v',"version","Ziyi::Options::Version")]
96
97     suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
98
99     if suites == []:
100         suites = Cnf.SubTree("Suite").List()
101
102     def real_arch(x):
103         return x != "source" and x != "all"
104
105     for suite in suites:
106         print "Processing: " + suite
107         SuiteBlock = Cnf.SubTree("Suite::" + suite)
108
109         if SuiteBlock.has_key("Untouchable"):
110             print "Skipping: " + suite + " (untouchable)"
111             continue
112
113         suite = string.lower(suite)
114
115         origin = SuiteBlock["Origin"]
116         label = SuiteBlock.get("Label", origin)
117         version = SuiteBlock.get("Version", "")
118         codename = SuiteBlock.get("CodeName", "")
119
120         if SuiteBlock.has_key("NotAutomatic"):
121             notautomatic = "yes"
122         else:
123             notautomatic = ""
124
125         if SuiteBlock.has_key("Components"):
126             components = SuiteBlock.SubTree("Components").List()
127         else:
128             components = []
129
130         nonus = 1
131         if components != []:
132             for c in components:
133                 if c[:7] != "non-US/":
134                     nonus = 0
135         else:
136             nonus = 0
137         if nonus:
138             longsuite = suite + "/non-US"
139         else:
140             longsuite = suite
141
142         tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
143
144         print Cnf["Dir::RootDir"] + tree + "/Release"
145         out = open(Cnf["Dir::RootDir"] + tree + "/Release", "w")
146
147         out.write("Origin: %s\n" % (origin))
148         out.write("Label: %s\n" % (label))
149         out.write("Suite: %s\n" % (suite))
150         if version != "":
151             out.write("Version: %s\n" % (version))
152         if codename != "":
153             out.write("Codename: %s\n" % (codename))
154         out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
155         if notautomatic != "":
156             out.write("NotAutomatic: %s\n" % (notautomatic))
157         out.write("Architectures: %s\n" % (string.join(filter(real_arch, SuiteBlock.SubTree("Architectures").List()))))
158         if components != []:
159             out.write("Components: %s\n" % (string.join(components)))
160
161         out.write("Description: %s\n" % (SuiteBlock["Description"]))
162
163         files = []
164
165         if AptCnf.has_key("tree::%s" % (tree)):
166             for sec in string.split(AptCnf["tree::%s::Sections" % (tree)]):
167                 for arch in string.split(AptCnf["tree::%s::Architectures" % (tree)]):
168                     if arch == "source":
169                         for file in compressnames("tree::%s" % (tree), "Sources", "%s/%s/Sources" % (sec, arch)):
170                             files.append(file)
171                     else:
172                         rel = "%s/binary-%s/Release" % (sec, arch)
173                         relpath = Cnf["Dir::RootDir"]+tree+"/"+rel
174                         if os.path.exists(relpath):
175                             try:
176                                 release = open(relpath, "w")
177                                 #release = open(string.replace(longsuite,"/","_") + "_" + arch + "_" + sec + "_Release", "w")
178                             except IOError:
179                                 print "Couldn't write to " + relpath
180                             else:
181                                 release.write("Archive: %s\n" % (suite))
182                                 if version != "":
183                                     release.write("Version: %s\n" % (version))
184                                 if nonus:
185                                     release.write("Component: non-US/%s\n" % (sec))
186                                 else:
187                                     release.write("Component: %s\n" % (sec))
188                                 release.write("Origin: %s\n" % (origin))
189                                 release.write("Label: %s\n" % (label))
190                                 if notautomatic != "":
191                                     release.write("NotAutomatic: %s\n" % (notautomatic))
192                                 release.write("Architecture: %s\n" % (arch))
193                                 release.close()
194                             files.append("%s/binary-%s/Release" % (sec,arch))
195
196                         disks = "%s/disks-%s" % (sec, arch)
197                         diskspath = Cnf["Dir::RootDir"]+tree+"/"+disks
198                         if os.path.exists(diskspath):
199                             for dir in os.listdir(diskspath):
200                                 if os.path.exists("%s/%s/md5sum.txt" % (diskspath, dir)):
201                                     files.append("%s/%s/md5sum.txt" % (disks, dir))
202
203                         for file in compressnames("tree::%s" % (tree), "Packages", "%s/binary-%s/Packages" % (sec, arch)):
204                             files.append(file)
205
206             if AptCnf.has_key("tree::%s/main" % (tree)):
207                 sec = string.split(AptCnf["tree::%s/main::Sections" % (tree)])[0]
208                 if sec != "debian-installer":
209                     print "ALERT: weird non debian-installer section in %s" % (tree)
210
211                 for arch in string.split(AptCnf["tree::%s/main::Architectures" % (tree)]):
212                     if arch != "source":  # always true
213                         for file in compressnames("tree::%s/main" % (tree), "Packages", "main/%s/binary-%s/Packages" % (sec, arch)):
214                             files.append(file)
215
216         elif AptCnf.has_key("bindirectory::%s" % (tree)):
217             for file in compressnames("bindirectory::%s" % (tree), "Packages", AptCnf["bindirectory::%s::Packages" % (tree)]):
218                 files.append(string.replace(file,tree+"/","",1))
219             for file in compressnames("bindirectory::%s" % (tree), "Sources", AptCnf["bindirectory::%s::Sources" % (tree)]):
220                 files.append(string.replace(file,tree+"/","",1))
221         else:
222             print "ALERT: no tree/bindirectory for %s" % (tree)
223
224         out.write("MD5Sum:\n")
225         print_md5_files(tree, files)
226         out.write("SHA1:\n")
227         print_sha1_files(tree, files)
228
229         out.close()
230         if Cnf.has_key("Dinstall::SigningKeyring"):
231             dest = Cnf["Dir::RootDir"] + tree + "/Release.gpg"
232             if os.path.exists(dest):
233                  os.unlink(dest)
234             os.system("gpg --secret-keyring \"%s\" --no-options --batch --no-tty --armour --detach-sign <%s --output=%s" % (Cnf["Dinstall::SigningKeyring"], 
235                 Cnf["Dir::RootDir"] + tree + "/Release", dest))
236
237 #######################################################################################
238
239 if __name__ == '__main__':
240     main()
241