]> git.decadent.org.uk Git - dak.git/blob - dak/show_new.py
Debug suites might also miss the source package
[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 import policy
34 from daklib.dbconn import *
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.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED
40 from multiprocessing import Manager, TimeoutError
41
42 # Globals
43 Cnf = None
44 Options = None
45 manager = Manager()
46 sources = manager.list()
47 htmlfiles_to_process = manager.list()
48 timeout_str = "Timed out while processing"
49
50
51 ################################################################################
52 ################################################################################
53 ################################################################################
54
55 def html_header(name, missing):
56     if name.endswith('.changes'):
57         name = ' '.join(name.split('_')[:2])
58     result = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
59 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
60   <head>
61     <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8"
62     />
63     <title>%(name)s - Debian NEW package overview</title>
64     <link type="text/css" rel="stylesheet" href="/style.css" />
65     <link rel="shortcut icon" href="https://www.debian.org/favicon.ico" />
66     <script type="text/javascript">
67       //<![CDATA[
68       <!--
69       function toggle(id, initial, display) {
70         var o = document.getElementById(id);
71         toggleObj(o, initial, display);
72       }
73       function show(id, display) {
74         var o = document.getElementById(id);
75         o.style.display = 'table-row-group';
76       }
77       function toggleObj(o, initial, display) {
78         if(! o.style.display)
79           o.style.display = initial;
80         if(o.style.display == display) {
81           o.style.display = "none";
82         } else {
83           o.style.display = display;
84         }
85       }
86       //-->
87       //]]>
88     </script>
89   </head>
90   <body id="NEW-details-page">
91     <div id="logo">
92       <a href="https://www.debian.org/">
93         <img src="https://www.debian.org/logos/openlogo-nd-50.png"
94         alt="debian logo" /></a>
95       <a href="https://www.debian.org/">
96         <img src="https://www.debian.org/Pics/debian.png"
97         alt="Debian Project" /></a>
98     </div>
99     <div id="titleblock">
100       <img src="https://www.debian.org/Pics/red-upperleft.png"
101       id="red-upperleft" alt="corner image"/>
102       <img src="https://www.debian.org/Pics/red-lowerleft.png"
103       id="red-lowerleft" alt="corner image"/>
104       <img src="https://www.debian.org/Pics/red-upperright.png"
105       id="red-upperright" alt="corner image"/>
106       <img src="https://www.debian.org/Pics/red-lowerright.png"
107       id="red-lowerright" alt="corner image"/>
108       <span class="title">
109         Debian NEW package overview for %(name)s
110       </span>
111     </div>
112
113     """%{"name":name}
114
115     # we assume only one source (.dsc) per changes here
116     result += """
117     <div id="menu">
118       <p class="title">Navigation</p>
119       <p><a href="#changes" onclick="show('changes-body')">.changes</a></p>
120       <p><a href="#dsc" onclick="show('dsc-body')">.dsc</a></p>
121       <p><a href="#source-lintian" onclick="show('source-lintian-body')">source lintian</a></p>
122
123 """
124     for binarytype, packagename in filter(lambda m: m[0] in ('deb', 'udeb'), missing):
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 += "</body></html>"
141     return result
142
143 ################################################################################
144
145
146 def do_pkg(upload_id):
147     cnf = Config()
148
149     session = DBConn().session()
150     upload = session.query(PolicyQueueUpload).filter_by(id=upload_id).one()
151
152     queue = upload.policy_queue
153     changes = upload.changes
154
155     origchanges = os.path.join(queue.path, changes.changesname)
156     print origchanges
157
158     htmlname = "{0}_{1}.html".format(changes.source, changes.version)
159     htmlfile = os.path.join(cnf['Show-New::HTMLPath'], htmlname)
160
161     # Have we already processed this?
162     if os.path.exists(htmlfile) and \
163         os.stat(htmlfile).st_mtime > time.mktime(changes.created.timetuple()):
164             with open(htmlfile, "r") as fd:
165                 if fd.read() != timeout_str:
166                     sources.append(htmlname)
167                     return (PROC_STATUS_SUCCESS,
168                             '%s already up-to-date' % htmlfile)
169
170     # Go, process it... Now!
171     htmlfiles_to_process.append(htmlfile)
172     sources.append(htmlname)
173
174     group = cnf.get('Dinstall::UnprivGroup') or None
175
176     with open(htmlfile, 'w') as outfile:
177       with policy.UploadCopy(upload, group=group) as upload_copy:
178         handler = policy.PolicyQueueUploadHandler(upload, session)
179         missing = [ (o['type'], o['package']) for o in handler.missing_overrides() ]
180         distribution = changes.distribution
181
182         print >>outfile, html_header(changes.source, missing)
183         print >>outfile, examine_package.display_changes(distribution, origchanges)
184
185         if upload.source is not None and ('dsc', upload.source.source) in missing:
186             fn = os.path.join(upload_copy.directory, upload.source.poolfile.basename)
187             print >>outfile, examine_package.check_dsc(distribution, fn, session)
188         for binary in upload.binaries:
189             if (binary.binarytype, binary.package) not in missing:
190                 continue
191             fn = os.path.join(upload_copy.directory, binary.poolfile.basename)
192             print >>outfile, examine_package.check_deb(distribution, fn, session)
193
194         print >>outfile, html_footer()
195
196     session.close()
197     htmlfiles_to_process.remove(htmlfile)
198     return (PROC_STATUS_SUCCESS, '{0} already updated'.format(htmlfile))
199
200 ################################################################################
201
202 def usage (exit_code=0):
203     print """Usage: dak show-new [OPTION]... [CHANGES]...
204   -h, --help                show this help and exit.
205   -p, --html-path [path]    override output directory.
206   """
207     sys.exit(exit_code)
208
209 ################################################################################
210
211 def init(session):
212     global cnf, Options
213
214     cnf = Config()
215
216     Arguments = [('h',"help","Show-New::Options::Help"),
217                  ("p","html-path","Show-New::HTMLPath","HasArg"),
218                  ('q','queue','Show-New::Options::Queue','HasArg')]
219
220     for i in ["help"]:
221         if not cnf.has_key("Show-New::Options::%s" % (i)):
222             cnf["Show-New::Options::%s" % (i)] = ""
223
224     changesnames = apt_pkg.parse_commandline(cnf.Cnf,Arguments,sys.argv)
225     Options = cnf.subtree("Show-New::Options")
226
227     if Options["help"]:
228         usage()
229
230     queue_names = Options.find('Queue', 'new').split(',')
231     uploads = session.query(PolicyQueueUpload) \
232         .join(PolicyQueueUpload.policy_queue).filter(PolicyQueue.queue_name.in_(queue_names)) \
233         .join(PolicyQueueUpload.changes).order_by(DBChange.source)
234
235     if len(changesnames) > 0:
236         uploads = uploads.filter(DBChange.changesname.in_(changesnames))
237
238     return uploads
239
240
241 ################################################################################
242 ################################################################################
243
244 def main():
245     examine_package.use_html = True
246     pool = DakProcessPool(processes=5)
247
248     session = DBConn().session()
249     upload_ids = [ u.id for u in init(session) ]
250     session.close()
251
252     for upload_id in upload_ids:
253         pool.apply_async(do_pkg, [upload_id])
254     pool.close()
255
256     #p.wait(timeout=600)
257     pool.join()
258     for htmlfile in htmlfiles_to_process:
259         with open(htmlfile, "w") as fd:
260             fd.write(timeout_str)
261
262     files = set(os.listdir(cnf["Show-New::HTMLPath"]))
263     to_delete = filter(lambda x: x.endswith(".html"), files.difference(set(sources)))
264     for f in to_delete:
265         os.remove(os.path.join(cnf["Show-New::HTMLPath"],f))
266
267 ################################################################################
268
269 if __name__ == '__main__':
270     main()