]> git.decadent.org.uk Git - dak.git/blob - dak/show_new.py
Merge Thomas fix for check_hashes
[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):
48     if name.endswith('.changes'):
49         name = ' '.join(name.split('_')[:2])
50     print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
51         <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">"""
52     print "<title>%s - Debian NEW package overview</title>" % (name)
53     print """<link type="text/css" rel="stylesheet" href="/style.css">
54         <link rel="shortcut icon" href="http://www.debian.org/favicon.ico">
55         </head>
56         <body>
57         <div align="center">
58         <a href="http://www.debian.org/">
59      <img src="http://www.debian.org/logos/openlogo-nd-50.png" border="0" hspace="0" vspace="0" alt=""></a>
60         <a href="http://www.debian.org/">
61      <img src="http://www.debian.org/Pics/debian.png" border="0" hspace="0" vspace="0" alt="Debian Project"></a>
62         </div>
63         <br />
64         <table class="reddy" width="100%">
65         <tr>
66         <td class="reddy">
67     <img src="http://www.debian.org/Pics/red-upperleft.png" align="left" border="0" hspace="0" vspace="0"
68      alt="" width="15" height="16"></td>"""
69     print """<td rowspan="2" class="reddy">Debian NEW package overview for %s</td>""" % (name)
70     print """<td class="reddy">
71     <img src="http://www.debian.org/Pics/red-upperright.png" align="right" border="0" hspace="0" vspace="0"
72      alt="" width="16" height="16"></td>
73         </tr>
74         <tr>
75         <td class="reddy">
76     <img src="http://www.debian.org/Pics/red-lowerleft.png" align="left" border="0" hspace="0" vspace="0"
77      alt="" width="16" height="16"></td>
78         <td class="reddy">
79     <img src="http://www.debian.org/Pics/red-lowerright.png" align="right" border="0" hspace="0" vspace="0"
80      alt="" width="15" height="16"></td>
81         </tr>
82         </table>
83         """
84
85 def html_footer():
86     print "<p class=\"validate\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
87     print """<a href="http://validator.w3.org/check?uri=referer">
88     <img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a>
89         <a href="http://jigsaw.w3.org/css-validator/check/referer">
90     <img border="0" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"
91      height="31" width="88"></a>
92     """
93     print "</body></html>"
94
95
96 ################################################################################
97
98
99 def do_pkg(changes_file):
100     Upload.pkg.changes_file = changes_file
101     Upload.init_vars()
102     Upload.update_vars()
103     files = Upload.pkg.files
104     changes = Upload.pkg.changes
105
106     changes["suite"] = copy.copy(changes["distribution"])
107
108     # Find out what's new
109     new = daklib.queue.determine_new(changes, files, projectB, 0)
110
111     stdout_fd = sys.stdout
112
113     htmlname = changes["source"] + "_" + changes["version"] + ".html"
114     sources.add(htmlname)
115     # do not generate html output if that source/version already has one.
116     if not os.path.exists(os.path.join(Cnf["Show-New::HTMLPath"],htmlname)):
117         sys.stdout = open(os.path.join(Cnf["Show-New::HTMLPath"],htmlname),"w")
118         html_header(changes["source"])
119
120         daklib.queue.check_valid(new)
121         examine_package.display_changes(Upload.pkg.changes_file)
122
123         for pkg in new.keys():
124             for file in new[pkg]["files"]:
125                 if ( files[file].has_key("new") and not
126                      files[file]["type"] in [ "orig.tar.gz", "orig.tar.bz2", "tar.gz", "tar.bz2", "diff.gz", "diff.bz2"] ):
127                     if file.endswith(".deb") or file.endswith(".udeb"):
128                         examine_package.check_deb(file)
129                     elif file.endswith(".dsc"):
130                         examine_package.check_dsc(file)
131
132         html_footer()
133         if sys.stdout != stdout_fd:
134             sys.stdout.close()
135             sys.stdout = stdout_fd
136
137 ################################################################################
138
139 def usage (exit_code=0):
140     print """Usage: dak show-new [OPTION]... [CHANGES]...
141   -h, --help                show this help and exit.
142   """
143     sys.exit(exit_code)
144
145 ################################################################################
146
147 def init():
148     global Cnf, Options, Upload, projectB
149
150     Cnf = daklib.utils.get_conf()
151
152     Arguments = [('h',"help","Show-New::Options::Help")]
153
154     for i in ["help"]:
155         if not Cnf.has_key("Show-New::Options::%s" % (i)):
156             Cnf["Show-New::Options::%s" % (i)] = ""
157
158     changes_files = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
159     Options = Cnf.SubTree("Show-New::Options")
160
161     if Options["help"]:
162         usage()
163
164     Upload = daklib.queue.Upload(Cnf)
165
166     projectB = Upload.projectB
167
168     return changes_files
169
170
171 ################################################################################
172 ################################################################################
173
174 def main():
175     changes_files = init()
176
177     examine_package.use_html=1
178
179     for changes_file in changes_files:
180         changes_file = daklib.utils.validate_changes_file_arg(changes_file, 0)
181         if not changes_file:
182             continue
183         print "\n" + changes_file
184         do_pkg (changes_file)
185     files = set(os.listdir(Cnf["Show-New::HTMLPath"]))
186     to_delete = files.difference(sources)
187     for file in to_delete:
188         os.remove(os.path.join(Cnf["Show-New::HTMLPath"],file))
189
190 ################################################################################
191
192 if __name__ == '__main__':
193     main()