]> git.decadent.org.uk Git - dak.git/blob - dak/show_new.py
Merge commit 'ftpmaster/master' into sqlalchemy
[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 from copy import copy
29 import os, sys, time
30 import apt_pkg
31 import examine_package
32
33 from daklib.queue import determine_new, check_valid
34 from daklib import utils
35
36 # Globals
37 Cnf = None
38 Options = None
39 sources = set()
40
41
42 ################################################################################
43 ################################################################################
44 ################################################################################
45
46 def html_header(name, filestoexamine):
47     if name.endswith('.changes'):
48         name = ' '.join(name.split('_')[:2])
49     print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
50 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
51   <head>
52     <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8"
53     />
54     <title>%(name)s - Debian NEW package overview</title>
55     <link type="text/css" rel="stylesheet" href="/style.css" />
56     <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
57     <script type="text/javascript">
58       //<![CDATA[
59       <!--
60       function toggle(id, initial, display) {
61         var o = document.getElementById(id);
62         toggleObj(o, initial, display);
63       }
64       function show(id, display) {
65         var o = document.getElementById(id);
66         o.style.display = 'table-row-group';
67       }
68       function toggleObj(o, initial, display) {
69         if(! o.style.display)
70           o.style.display = initial;
71         if(o.style.display == display) {
72           o.style.display = "none";
73         } else {
74           o.style.display = display;
75         }
76       }
77       //-->
78       //]]>
79     </script>
80   </head>
81   <body id="NEW-details-page">
82     <div id="logo">
83       <a href="http://www.debian.org/">
84         <img src="http://www.debian.org/logos/openlogo-nd-50.png"
85         alt="debian logo" /></a>
86       <a href="http://www.debian.org/">
87         <img src="http://www.debian.org/Pics/debian.png"
88         alt="Debian Project" /></a>
89     </div>
90     <div id="titleblock">
91       <img src="http://www.debian.org/Pics/red-upperleft.png"
92       id="red-upperleft" alt="corner image"/>
93       <img src="http://www.debian.org/Pics/red-lowerleft.png"
94       id="red-lowerleft" alt="corner image"/>
95       <img src="http://www.debian.org/Pics/red-upperright.png"
96       id="red-upperright" alt="corner image"/>
97       <img src="http://www.debian.org/Pics/red-lowerright.png"
98       id="red-lowerright" alt="corner image"/>
99       <span class="title">
100         Debian NEW package overview for %(name)s
101       </span>
102     </div>
103     """%{"name":name}
104
105     # we assume only one source (.dsc) per changes here
106     print """
107     <div id="menu">
108       <p class="title">Navigation</p>
109       <p><a href="#changes" onclick="show('changes-body')">.changes</a></p>
110       <p><a href="#dsc" onclick="show('dsc-body')">.dsc</a></p>
111       <p><a href="#source-lintian" onclick="show('source-lintian-body')">source lintian</a></p>
112       """
113     for fn in filter(lambda x: x.endswith('.deb') or x.endswith('.udeb'),filestoexamine):
114         packagename = fn.split('_')[0]
115         print """
116         <p class="subtitle">%(pkg)s</p>
117         <p><a href="#binary-%(pkg)s-control" onclick="show('binary-%(pkg)s-control-body')">control file</a></p>
118         <p><a href="#binary-%(pkg)s-lintian" onclick="show('binary-%(pkg)s-lintian-body')">binary lintian</a></p>
119         <p><a href="#binary-%(pkg)s-contents" onclick="show('binary-%(pkg)s-contents-body')">.deb contents</a></p>
120         <p><a href="#binary-%(pkg)s-copyright" onclick="show('binary-%(pkg)s-copyright-body')">copyright</a></p>
121         <p><a href="#binary-%(pkg)s-file-listing" onclick="show('binary-%(pkg)s-file-listing-body')">file listing</a></p>
122         """%{"pkg":packagename}
123     print "    </div>"
124
125 def html_footer():
126     print """    <p class="validate">Timestamp: %s (UTC)</p>"""% (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
127     print """    <p><a href="http://validator.w3.org/check?uri=referer">
128       <img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"
129       style="border: none; height: 31px; width: 88px" /></a>
130     <a href="http://jigsaw.w3.org/css-validator/check/referer">
131       <img src="http://jigsaw.w3.org/css-validator/images/vcss"
132       alt="Valid CSS!" style="border: none; height: 31px; width: 88px" /></a>
133     </p>
134   </body>
135 </html>
136 """
137
138 ################################################################################
139
140
141 def do_pkg(changes_file):
142     c = Changes()
143     c.load_dot_dak(changes_file)
144     files = c.files
145     changes = c.changes
146
147     c.changes["suite"] = copy(c.changes["distribution"])
148     distribution = c.changes["distribution"].keys()[0]
149     # Find out what's new
150     new = determine_new(c.changes, c.files, 0)
151
152     stdout_fd = sys.stdout
153
154     htmlname = c.changes["source"] + "_" + c.changes["version"] + ".html"
155     sources.add(htmlname)
156     # do not generate html output if that source/version already has one.
157     if not os.path.exists(os.path.join(Cnf["Show-New::HTMLPath"],htmlname)):
158         sys.stdout = open(os.path.join(Cnf["Show-New::HTMLPath"],htmlname),"w")
159
160         filestoexamine = []
161         for pkg in new.keys():
162             for fn in new[pkg]["files"]:
163                 if ( c.files[fn].has_key("new") and not
164                      c.files[fn]["type"] in [ "orig.tar.gz", "orig.tar.bz2", "tar.gz", "tar.bz2", "diff.gz", "diff.bz2"] ):
165                     filestoexamine.append(fn)
166
167         html_header(c.changes["source"], filestoexamine)
168
169         check_valid(new)
170         examine_package.display_changes( distribution, changes_file)
171
172         for fn in filter(lambda fn: fn.endswith(".dsc"), filestoexamine):
173             examine_package.check_dsc(distribution, fn)
174         for fn in filter(lambda fn: fn.endswith(".deb") or fn.endswith(".udeb"), filestoexamine):
175             examine_package.check_deb(distribution, fn)
176
177         html_footer()
178         if sys.stdout != stdout_fd:
179             sys.stdout.close()
180             sys.stdout = stdout_fd
181
182 ################################################################################
183
184 def usage (exit_code=0):
185     print """Usage: dak show-new [OPTION]... [CHANGES]...
186   -h, --help                show this help and exit.
187   -p, --html-path [path]    override output directory.
188   """
189     sys.exit(exit_code)
190
191 ################################################################################
192
193 def init():
194     global Cnf, Options
195
196     Cnf = utils.get_conf()
197
198     Arguments = [('h',"help","Show-New::Options::Help"),
199                  ("p","html-path","Show-New::HTMLPath","HasArg")]
200
201     for i in ["help"]:
202         if not Cnf.has_key("Show-New::Options::%s" % (i)):
203             Cnf["Show-New::Options::%s" % (i)] = ""
204
205     changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
206     Options = Cnf.SubTree("Show-New::Options")
207
208     if Options["help"]:
209         usage()
210
211     return changes_files
212
213
214 ################################################################################
215 ################################################################################
216
217 def main():
218     changes_files = init()
219
220     examine_package.use_html=1
221
222     for changes_file in changes_files:
223         changes_file = utils.validate_changes_file_arg(changes_file, 0)
224         if not changes_file:
225             continue
226         print "\n" + changes_file
227         do_pkg (changes_file)
228     files = set(os.listdir(Cnf["Show-New::HTMLPath"]))
229     to_delete = filter(lambda x: x.endswith(".html"), files.difference(sources))
230     for f in to_delete:
231         os.remove(os.path.join(Cnf["Show-New::HTMLPath"],f))
232
233 ################################################################################
234
235 if __name__ == '__main__':
236     main()