]> git.decadent.org.uk Git - dak.git/blob - dak/show_new.py
Merge branch 'master' of ssh://ftp-master.debian.org/srv/ftp.debian.org/git/dak
[dak.git] / dak / show_new.py
1 #!/usr/bin/env python
2
3 """ Output html for packages in NEW """
4 # Copyright (C) 2007, 2009 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 from copy import copy
29 import os, sys, time
30 import apt_pkg
31 import examine_package
32
33 from daklib.dbconn import *
34 from daklib.queue import determine_new, check_valid, Upload, get_policy_queue
35 from daklib import utils
36 from daklib.regexes import re_source_ext
37 from daklib.config import Config
38 from daklib import daklog
39 from daklib.changesutils import *
40 from daklib.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED
41 from multiprocessing import Manager
42
43 # Globals
44 Cnf = None
45 Options = None
46 manager = Manager()
47 sources = manager.list()
48
49
50 ################################################################################
51 ################################################################################
52 ################################################################################
53
54 def html_header(name, filestoexamine):
55     if name.endswith('.changes'):
56         name = ' '.join(name.split('_')[:2])
57     result = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
58 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
59   <head>
60     <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8"
61     />
62     <title>%(name)s - Debian NEW package overview</title>
63     <link type="text/css" rel="stylesheet" href="/style.css" />
64     <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
65     <script type="text/javascript">
66       //<![CDATA[
67       <!--
68       function toggle(id, initial, display) {
69         var o = document.getElementById(id);
70         toggleObj(o, initial, display);
71       }
72       function show(id, display) {
73         var o = document.getElementById(id);
74         o.style.display = 'table-row-group';
75       }
76       function toggleObj(o, initial, display) {
77         if(! o.style.display)
78           o.style.display = initial;
79         if(o.style.display == display) {
80           o.style.display = "none";
81         } else {
82           o.style.display = display;
83         }
84       }
85       //-->
86       //]]>
87     </script>
88   </head>
89   <body id="NEW-details-page">
90     <div id="logo">
91       <a href="http://www.debian.org/">
92         <img src="http://www.debian.org/logos/openlogo-nd-50.png"
93         alt="debian logo" /></a>
94       <a href="http://www.debian.org/">
95         <img src="http://www.debian.org/Pics/debian.png"
96         alt="Debian Project" /></a>
97     </div>
98     <div id="titleblock">
99       <img src="http://www.debian.org/Pics/red-upperleft.png"
100       id="red-upperleft" alt="corner image"/>
101       <img src="http://www.debian.org/Pics/red-lowerleft.png"
102       id="red-lowerleft" alt="corner image"/>
103       <img src="http://www.debian.org/Pics/red-upperright.png"
104       id="red-upperright" alt="corner image"/>
105       <img src="http://www.debian.org/Pics/red-lowerright.png"
106       id="red-lowerright" alt="corner image"/>
107       <span class="title">
108         Debian NEW package overview for %(name)s
109       </span>
110     </div>
111
112     """%{"name":name}
113
114     # we assume only one source (.dsc) per changes here
115     result += """
116     <div id="menu">
117       <p class="title">Navigation</p>
118       <p><a href="#changes" onclick="show('changes-body')">.changes</a></p>
119       <p><a href="#dsc" onclick="show('dsc-body')">.dsc</a></p>
120       <p><a href="#source-lintian" onclick="show('source-lintian-body')">source lintian</a></p>
121
122 """
123     for fn in filter(lambda x: x.endswith('.deb') or x.endswith('.udeb'),filestoexamine):
124         packagename = fn.split('_')[0]
125         result += """
126         <p class="subtitle">%(pkg)s</p>
127         <p><a href="#binary-%(pkg)s-control" onclick="show('binary-%(pkg)s-control-body')">control file</a></p>
128         <p><a href="#binary-%(pkg)s-lintian" onclick="show('binary-%(pkg)s-lintian-body')">binary lintian</a></p>
129         <p><a href="#binary-%(pkg)s-contents" onclick="show('binary-%(pkg)s-contents-body')">.deb contents</a></p>
130         <p><a href="#binary-%(pkg)s-copyright" onclick="show('binary-%(pkg)s-copyright-body')">copyright</a></p>
131         <p><a href="#binary-%(pkg)s-file-listing" onclick="show('binary-%(pkg)s-file-listing-body')">file listing</a></p>
132
133 """%{"pkg":packagename}
134     result += "    </div>"
135     return result
136
137 def html_footer():
138     result = """    <p class="validate">Timestamp: %s (UTC)</p>
139 """% (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
140     result += """    <p><a href="http://validator.w3.org/check?uri=referer">
141       <img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"
142       style="border: none; height: 31px; width: 88px" /></a>
143     <a href="http://jigsaw.w3.org/css-validator/check/referer">
144       <img src="http://jigsaw.w3.org/css-validator/images/vcss"
145       alt="Valid CSS!" style="border: none; height: 31px; width: 88px" /></a>
146     </p>
147   </body>
148 </html>
149 """
150     return result
151
152 ################################################################################
153
154
155 def do_pkg(changes_file):
156     changes_file = utils.validate_changes_file_arg(changes_file, 0)
157     if not changes_file:
158         return
159     print "\n" + changes_file
160
161     session = DBConn().session()
162     u = Upload()
163     u.pkg.changes_file = changes_file
164     # We can afoord not to check the signature before loading the changes file
165     # as we've validated it already (otherwise it couldn't be in new)
166     # and we can more quickly skip over already processed files this way
167     u.load_changes(changes_file)
168
169     origchanges = os.path.abspath(u.pkg.changes_file)
170
171     # Still be cautious in case paring the changes file went badly
172     if u.pkg.changes.has_key('source') and u.pkg.changes.has_key('version'):
173         htmlname = u.pkg.changes["source"] + "_" + u.pkg.changes["version"] + ".html"
174         htmlfile = os.path.join(cnf["Show-New::HTMLPath"], htmlname)
175     else:
176         # Changes file was bad
177         print "Changes file %s missing source or version field" % changes_file
178         session.close()
179         return
180
181     # Have we already processed this?
182     if os.path.exists(htmlfile) and \
183         os.stat(htmlfile).st_mtime > os.stat(origchanges).st_mtime:
184             sources.append(htmlname)
185             session.close()
186             return (PROC_STATUS_SUCCESS, '%s already up-to-date' % htmlfile)
187
188     # Now we'll load the fingerprint
189     (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changes_file, session=session)
190     new_queue = get_policy_queue('new', session );
191     u.pkg.directory = new_queue.path
192     u.update_subst()
193     files = u.pkg.files
194     changes = u.pkg.changes
195     sources.append(htmlname)
196
197     for deb_filename, f in files.items():
198         if deb_filename.endswith(".udeb") or deb_filename.endswith(".deb"):
199             u.binary_file_checks(deb_filename, session)
200             u.check_binary_against_db(deb_filename, session)
201         else:
202             u.source_file_checks(deb_filename, session)
203             u.check_source_against_db(deb_filename, session)
204     u.pkg.changes["suite"] = u.pkg.changes["distribution"]
205
206     new, byhand = determine_new(u.pkg.changes_file, u.pkg.changes, files, 0, dsc=u.pkg.dsc, session=session)
207
208     outfile = open(os.path.join(cnf["Show-New::HTMLPath"],htmlname),"w")
209
210     filestoexamine = []
211     for pkg in new.keys():
212         for fn in new[pkg]["files"]:
213             filestoexamine.append(fn)
214
215     print >> outfile, html_header(changes["source"], filestoexamine)
216
217     check_valid(new, session)
218     distribution = changes["distribution"].keys()[0]
219     print >> outfile, examine_package.display_changes(distribution, changes_file)
220
221     for fn in filter(lambda fn: fn.endswith(".dsc"), filestoexamine):
222         print >> outfile, examine_package.check_dsc(distribution, fn, session)
223     for fn in filter(lambda fn: fn.endswith(".deb") or fn.endswith(".udeb"), filestoexamine):
224         print >> outfile, examine_package.check_deb(distribution, fn, session)
225
226     print >> outfile, html_footer()
227
228     outfile.close()
229     session.close()
230
231     return (PROC_STATUS_SUCCESS, '%s already updated' % htmlfile)
232
233 ################################################################################
234
235 def usage (exit_code=0):
236     print """Usage: dak show-new [OPTION]... [CHANGES]...
237   -h, --help                show this help and exit.
238   -p, --html-path [path]    override output directory.
239   """
240     sys.exit(exit_code)
241
242 ################################################################################
243
244 def init(session):
245     global cnf, Options
246
247     cnf = Config()
248
249     Arguments = [('h',"help","Show-New::Options::Help"),
250                  ("p","html-path","Show-New::HTMLPath","HasArg")]
251
252     for i in ["help"]:
253         if not cnf.has_key("Show-New::Options::%s" % (i)):
254             cnf["Show-New::Options::%s" % (i)] = ""
255
256     changes_files = apt_pkg.ParseCommandLine(cnf.Cnf,Arguments,sys.argv)
257     if len(changes_files) == 0:
258         new_queue = get_policy_queue('new', session );
259         changes_files = utils.get_changes_files(new_queue.path)
260
261     Options = cnf.SubTree("Show-New::Options")
262
263     if Options["help"]:
264         usage()
265
266     return changes_files
267
268
269 ################################################################################
270 ################################################################################
271
272 def main():
273     session = DBConn().session()
274     changes_files = init(session)
275
276     examine_package.use_html=1
277
278     pool = DakProcessPool()
279     for changes_file in changes_files:
280         pool.apply_async(do_pkg, (changes_file,))
281     pool.close()
282     pool.join()
283
284     files = set(os.listdir(cnf["Show-New::HTMLPath"]))
285     to_delete = filter(lambda x: x.endswith(".html"), files.difference(set(sources)))
286     for f in to_delete:
287         os.remove(os.path.join(cnf["Show-New::HTMLPath"],f))
288
289 ################################################################################
290
291 if __name__ == '__main__':
292     main()