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