]> git.decadent.org.uk Git - dak.git/blob - dak/show_new.py
Merge remote branch 'twerner/show-new' into merge
[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
41 # Globals
42 Cnf = None
43 Options = None
44 sources = set()
45
46
47 ################################################################################
48 ################################################################################
49 ################################################################################
50
51 def html_header(name, filestoexamine):
52     if name.endswith('.changes'):
53         name = ' '.join(name.split('_')[:2])
54     print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
55 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
56   <head>
57     <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8"
58     />
59     <title>%(name)s - Debian NEW package overview</title>
60     <link type="text/css" rel="stylesheet" href="/style.css" />
61     <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
62     <script type="text/javascript">
63       //<![CDATA[
64       <!--
65       function toggle(id, initial, display) {
66         var o = document.getElementById(id);
67         toggleObj(o, initial, display);
68       }
69       function show(id, display) {
70         var o = document.getElementById(id);
71         o.style.display = 'table-row-group';
72       }
73       function toggleObj(o, initial, display) {
74         if(! o.style.display)
75           o.style.display = initial;
76         if(o.style.display == display) {
77           o.style.display = "none";
78         } else {
79           o.style.display = display;
80         }
81       }
82       //-->
83       //]]>
84     </script>
85   </head>
86   <body id="NEW-details-page">
87     <div id="logo">
88       <a href="http://www.debian.org/">
89         <img src="http://www.debian.org/logos/openlogo-nd-50.png"
90         alt="debian logo" /></a>
91       <a href="http://www.debian.org/">
92         <img src="http://www.debian.org/Pics/debian.png"
93         alt="Debian Project" /></a>
94     </div>
95     <div id="titleblock">
96       <img src="http://www.debian.org/Pics/red-upperleft.png"
97       id="red-upperleft" alt="corner image"/>
98       <img src="http://www.debian.org/Pics/red-lowerleft.png"
99       id="red-lowerleft" alt="corner image"/>
100       <img src="http://www.debian.org/Pics/red-upperright.png"
101       id="red-upperright" alt="corner image"/>
102       <img src="http://www.debian.org/Pics/red-lowerright.png"
103       id="red-lowerright" alt="corner image"/>
104       <span class="title">
105         Debian NEW package overview for %(name)s
106       </span>
107     </div>
108     """%{"name":name}
109
110     # we assume only one source (.dsc) per changes here
111     print """
112     <div id="menu">
113       <p class="title">Navigation</p>
114       <p><a href="#changes" onclick="show('changes-body')">.changes</a></p>
115       <p><a href="#dsc" onclick="show('dsc-body')">.dsc</a></p>
116       <p><a href="#source-lintian" onclick="show('source-lintian-body')">source lintian</a></p>
117       """
118     for fn in filter(lambda x: x.endswith('.deb') or x.endswith('.udeb'),filestoexamine):
119         packagename = fn.split('_')[0]
120         print """
121         <p class="subtitle">%(pkg)s</p>
122         <p><a href="#binary-%(pkg)s-control" onclick="show('binary-%(pkg)s-control-body')">control file</a></p>
123         <p><a href="#binary-%(pkg)s-lintian" onclick="show('binary-%(pkg)s-lintian-body')">binary lintian</a></p>
124         <p><a href="#binary-%(pkg)s-contents" onclick="show('binary-%(pkg)s-contents-body')">.deb contents</a></p>
125         <p><a href="#binary-%(pkg)s-copyright" onclick="show('binary-%(pkg)s-copyright-body')">copyright</a></p>
126         <p><a href="#binary-%(pkg)s-file-listing" onclick="show('binary-%(pkg)s-file-listing-body')">file listing</a></p>
127         """%{"pkg":packagename}
128     print "    </div>"
129
130 def html_footer():
131     print """    <p class="validate">Timestamp: %s (UTC)</p>"""% (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
132     print """    <p><a href="http://validator.w3.org/check?uri=referer">
133       <img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"
134       style="border: none; height: 31px; width: 88px" /></a>
135     <a href="http://jigsaw.w3.org/css-validator/check/referer">
136       <img src="http://jigsaw.w3.org/css-validator/images/vcss"
137       alt="Valid CSS!" style="border: none; height: 31px; width: 88px" /></a>
138     </p>
139   </body>
140 </html>
141 """
142 #"""
143 ################################################################################
144
145
146 def do_pkg(changes_file):
147     session = DBConn().session()
148     u = Upload()
149     u.pkg.changes_file = changes_file
150     (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changes_file)
151     u.load_changes(changes_file)
152     new_queue = get_policy_queue('new', session );
153     u.pkg.directory = new_queue.path
154     u.update_subst()
155     origchanges = os.path.abspath(u.pkg.changes_file)
156     files = u.pkg.files
157     changes = u.pkg.changes
158
159     for deb_filename, f in files.items():
160         if deb_filename.endswith(".udeb") or deb_filename.endswith(".deb"):
161             u.binary_file_checks(deb_filename, session)
162             u.check_binary_against_db(deb_filename, session)
163         else:
164             u.source_file_checks(deb_filename, session)
165             u.check_source_against_db(deb_filename, session)
166     u.pkg.changes["suite"] = u.pkg.changes["distribution"]
167
168     new = determine_new(u.pkg.changes, files, 0)
169
170     stdout_fd = sys.stdout
171
172     htmlname = changes["source"] + "_" + changes["version"] + ".html"
173     sources.add(htmlname)
174     # do not generate html output if that source/version already has one.
175     if not os.path.exists(os.path.join(cnf["Show-New::HTMLPath"],htmlname)):
176         sys.stdout = open(os.path.join(cnf["Show-New::HTMLPath"],htmlname),"w")
177
178         filestoexamine = []
179         for pkg in new.keys():
180             for fn in new[pkg]["files"]:
181                 filestoexamine.append(fn)
182
183         html_header(changes["source"], filestoexamine)
184
185         check_valid(new)
186         distribution = changes["distribution"].keys()[0]
187         examine_package.display_changes(distribution, changes_file)
188
189         for fn in filter(lambda fn: fn.endswith(".dsc"), filestoexamine):
190             examine_package.check_dsc(distribution, fn)
191         for fn in filter(lambda fn: fn.endswith(".deb") or fn.endswith(".udeb"), filestoexamine):
192             examine_package.check_deb(distribution, fn)
193
194         html_footer()
195         if sys.stdout != stdout_fd:
196             sys.stdout.close()
197             sys.stdout = stdout_fd
198     session.close()
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
219     for i in ["help"]:
220         if not cnf.has_key("Show-New::Options::%s" % (i)):
221             cnf["Show-New::Options::%s" % (i)] = ""
222
223     changes_files = apt_pkg.ParseCommandLine(cnf.Cnf,Arguments,sys.argv)
224     if len(changes_files) == 0:
225         new_queue = get_policy_queue('new', session );
226         changes_files = utils.get_changes_files(new_queue.path)
227
228     Options = cnf.SubTree("Show-New::Options")
229
230     if Options["help"]:
231         usage()
232
233     return changes_files
234
235
236 ################################################################################
237 ################################################################################
238
239 def main():
240     session = DBConn().session()
241     changes_files = init(session)
242
243     examine_package.use_html=1
244
245     for changes_file in changes_files:
246         changes_file = utils.validate_changes_file_arg(changes_file, 0)
247         if not changes_file:
248             continue
249         print "\n" + changes_file
250         do_pkg (changes_file)
251
252     files = set(os.listdir(cnf["Show-New::HTMLPath"]))
253     to_delete = filter(lambda x: x.endswith(".html"), files.difference(sources))
254     for f in to_delete:
255         os.remove(os.path.join(cnf["Show-New::HTMLPath"],f))
256
257 ################################################################################
258
259 if __name__ == '__main__':
260     main()