]> git.decadent.org.uk Git - dak.git/blob - dak/show_new.py
merge ftpmaster branch
[dak.git] / dak / show_new.py
1 #!/usr/bin/env python
2
3 # Output html for packages in NEW
4 # Copyright (C) 2007 Joerg Jaspert <joerg@debian.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 # <elmo> I'm James Troup, long term source of all evil in Debian. you may
23 #        know me from such debian-devel-announce gems as "Serious
24 #        Problems With ...."
25
26 ################################################################################
27
28 import copy, os, sys, time
29 import apt_pkg
30 import examine_package
31 import daklib.database
32 import daklib.queue
33 import daklib.utils
34
35 # Globals
36 Cnf = None
37 Options = None
38 Upload = None
39 projectB = None
40 sources = set()
41
42
43 ################################################################################
44 ################################################################################
45 ################################################################################
46
47 def html_header(name, filestoexamine):
48     if name.endswith('.changes'):
49         name = ' '.join(name.split('_')[:2])
50     print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
51 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
52   <head>
53     <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8"
54     />
55     <title>%(name)s - Debian NEW package overview</title>
56     <link type="text/css" rel="stylesheet" href="style.css" />
57     <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
58     <script type="text/javascript">
59       //<![CDATA[
60       <!--
61       function toggle(id, initial, display) {
62         var o = document.getElementById(id);
63         toggleObj(o, initial, display);
64       }
65       function show(id, display) {
66         var o = document.getElementById(id);
67         o.style.display = 'table-row-group';
68       }
69       function toggleObj(o, initial, display) {
70         if(! o.style.display)
71           o.style.display = initial;
72         if(o.style.display == display) {
73           o.style.display = "none";
74         } else {
75           o.style.display = display;
76         }
77       }
78       //-->
79       //]]>
80     </script>
81   </head>
82   <body>
83     <div id="logo">
84       <a href="http://www.debian.org/">
85         <img src="http://www.debian.org/logos/openlogo-nd-50.png"
86         alt="debian logo" /></a>
87       <a href="http://www.debian.org/">
88         <img src="http://www.debian.org/Pics/debian.png"
89         alt="Debian Project" /></a>
90     </div>
91     <div id="titleblock">
92
93       <img src="http://www.debian.org/Pics/red-upperleft.png"
94       id="red-upperleft" alt="corner image"/>
95       <img src="http://www.debian.org/Pics/red-lowerleft.png"
96       id="red-lowerleft" alt="corner image"/>
97       <img src="http://www.debian.org/Pics/red-upperright.png"
98       id="red-upperright" alt="corner image"/>
99       <img src="http://www.debian.org/Pics/red-lowerright.png"
100       id="red-lowerright" alt="corner image"/>
101       <span class="title">
102         Debian NEW package overview for %(name)s
103       </span>
104     </div>
105     """%{"name":name}
106
107     # we assume only one source (.dsc) per changes here
108     print """
109     <div id="menu">
110       <p class="title">Navigation</p>
111       <p><a href="#changes" onclick="show('changes-body')">.changes</a></p>
112       <p><a href="#dsc" onclick="show('dsc-body')">.dsc</a></p>
113       <p><a href="#source-lintian" onclick="show('source-lintian-body')">source lintian</a></p>
114       """
115     for fn in filter(lambda x: x.endswith('.deb') or x.endswith('.udeb'),filestoexamine):
116         packagename = fn.split('_')[0]
117         print """
118         <p class="subtitle">%(pkg)s</p>
119         <p><a href="#binary-%(pkg)s-control" onclick="show('binary-%(pkg)s-control-body')">control file</a></p>
120         <p><a href="#binary-%(pkg)s-lintian" onclick="show('binary-%(pkg)s-lintian-body')">binary lintian</a></p>
121         <p><a href="#binary-%(pkg)s-contents" onclick="show('binary-%(pkg)s-contents-body')">.deb contents</a></p>
122         <p><a href="#binary-%(pkg)s-copyright" onclick="show('binary-%(pkg)s-copyright-body')">copyright</a></p>
123         <p><a href="#binary-%(pkg)s-file-listing" onclick="show('binary-%(pkg)s-file-listing-body')">file listing</a></p>
124         """%{"pkg":packagename}
125     print "    </div>"
126
127 def html_footer():
128     print """    <p class="validate">Timestamp: %s (UTC)</p>"""% (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
129     print """    <p><a href="http://validator.w3.org/check?uri=referer">
130       <img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"
131       style="border: none; height: 31px; width: 88px" /></a>
132     <a href="http://jigsaw.w3.org/css-validator/check/referer">
133       <img src="http://jigsaw.w3.org/css-validator/images/vcss"
134       alt="Valid CSS!" style="border: none; height: 31px; width: 88px" /></a>
135     </p>
136   </body>
137 </html>
138 """
139
140 ################################################################################
141
142
143 def do_pkg(changes_file):
144     Upload.pkg.changes_file = changes_file
145     Upload.init_vars()
146     Upload.update_vars()
147     files = Upload.pkg.files
148     changes = Upload.pkg.changes
149
150     changes["suite"] = copy.copy(changes["distribution"])
151
152     # Find out what's new
153     new = daklib.queue.determine_new(changes, files, projectB, 0)
154
155     stdout_fd = sys.stdout
156
157     htmlname = changes["source"] + "_" + changes["version"] + ".html"
158     sources.add(htmlname)
159     # do not generate html output if that source/version already has one.
160     if not os.path.exists(os.path.join(Cnf["Show-New::HTMLPath"],htmlname)):
161         sys.stdout = open(os.path.join(Cnf["Show-New::HTMLPath"],htmlname),"w")
162
163         filestoexamine = []
164         for pkg in new.keys():
165             for fn in new[pkg]["files"]:
166                 if ( files[fn].has_key("new") and not
167                      files[fn]["type"] in [ "orig.tar.gz", "orig.tar.bz2", "tar.gz", "tar.bz2", "diff.gz", "diff.bz2"] ):
168                     filestoexamine.append(fn)
169
170         html_header(changes["source"], filestoexamine)
171
172         daklib.queue.check_valid(new)
173         examine_package.display_changes(Upload.pkg.changes_file)
174
175         for fn in filter(lambda fn: fn.endswith(".dsc"), filestoexamine):
176             examine_package.check_dsc(fn)
177         for fn in filter(lambda fn: fn.endswith(".deb") or fn.endswith(".udeb"), filestoexamine):
178             examine_package.check_deb(fn)
179
180         html_footer()
181         if sys.stdout != stdout_fd:
182             sys.stdout.close()
183             sys.stdout = stdout_fd
184
185 ################################################################################
186
187 def usage (exit_code=0):
188     print """Usage: dak show-new [OPTION]... [CHANGES]...
189   -h, --help                show this help and exit.
190   -p, --html-path [path]    override output directory.
191   """
192     sys.exit(exit_code)
193
194 ################################################################################
195
196 def init():
197     global Cnf, Options, Upload, projectB
198
199     Cnf = daklib.utils.get_conf()
200
201     Arguments = [('h',"help","Show-New::Options::Help"),
202                  ("p","html-path","Show-New::HTMLPath","HasArg")]
203
204     for i in ["help"]:
205         if not Cnf.has_key("Show-New::Options::%s" % (i)):
206             Cnf["Show-New::Options::%s" % (i)] = ""
207
208     changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
209     Options = Cnf.SubTree("Show-New::Options")
210
211     if Options["help"]:
212         usage()
213
214     Upload = daklib.queue.Upload(Cnf)
215
216     projectB = Upload.projectB
217
218     return changes_files
219
220
221 ################################################################################
222 ################################################################################
223
224 def main():
225     changes_files = init()
226
227     examine_package.use_html=1
228
229     for changes_file in changes_files:
230         changes_file = daklib.utils.validate_changes_file_arg(changes_file, 0)
231         if not changes_file:
232             continue
233         print "\n" + changes_file
234         do_pkg (changes_file)
235     files = set(os.listdir(Cnf["Show-New::HTMLPath"]))
236     to_delete = filter(lambda x: x.endswith(".html"), files.difference(sources))
237     for file in to_delete:
238         os.remove(os.path.join(Cnf["Show-New::HTMLPath"],file))
239
240 ################################################################################
241
242 if __name__ == '__main__':
243     main()