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