]> git.decadent.org.uk Git - dak.git/blob - tools/debianqueued-0.9/show-deferred
add summary of deferred queue
[dak.git] / tools / debianqueued-0.9 / show-deferred
1 #!/usr/bin/env python
2
3 # based on queue-report
4 #    Copyright (C) 2001, 2002, 2003, 2005, 2006  James Troup <james@nocrew.org>
5 # Copyright (C) 2008 Thomas Viehmann <tv@beamnet.de>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 import sys, os, re, time
24 from debian_bundle import deb822
25
26 ################################################################################
27
28 row_number = 0
29
30 html_escaping = {'"':'&quot;', '&':'&amp;', '<':'&lt;', '>':'&gt;'}
31 re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys())))
32 def html_escape(s):
33     return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s)
34
35 ################################################################################
36
37 def header():
38   return  """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
39         <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
40         <title>Deferred uploads to Debian</title>
41         <link type="text/css" rel="stylesheet" href="style.css">
42         <link rel="shortcut icon" href="http://www.debian.org/favicon.ico">
43         </head>
44         <body>
45         <div align="center">
46         <a href="http://www.debian.org/">
47      <img src="http://www.debian.org/logos/openlogo-nd-50.png" border="0" hspace="0" vspace="0" alt=""></a>
48         <a href="http://www.debian.org/">
49      <img src="http://www.debian.org/Pics/debian.png" border="0" hspace="0" vspace="0" alt="Debian Project"></a>
50         </div>
51         <br />
52         <table class="reddy" width="100%">
53         <tr>
54         <td class="reddy">
55     <img src="http://www.debian.org/Pics/red-upperleft.png" align="left" border="0" hspace="0" vspace="0"
56      alt="" width="15" height="16"></td>
57         <td rowspan="2" class="reddy">Deferred uploads to Debian</td>
58         <td class="reddy">
59     <img src="http://www.debian.org/Pics/red-upperright.png" align="right" border="0" hspace="0" vspace="0"
60      alt="" width="16" height="16"></td>
61         </tr>
62         <tr>
63         <td class="reddy">
64     <img src="http://www.debian.org/Pics/red-lowerleft.png" align="left" border="0" hspace="0" vspace="0"
65      alt="" width="16" height="16"></td>
66         <td class="reddy">
67     <img src="http://www.debian.org/Pics/red-lowerright.png" align="right" border="0" hspace="0" vspace="0"
68      alt="" width="15" height="16"></td>
69         </tr>
70         </table>
71         """
72
73 def footer():
74     res = "<p class=\"validate\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
75     res += """<a href="http://validator.w3.org/check?uri=referer">
76     <img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a>
77         <a href="http://jigsaw.w3.org/css-validator/check/referer">
78     <img border="0" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"
79      height="31" width="88"></a>
80     """
81     res += "</body></html>"
82     return res
83
84 def table_header():
85     return """<h1>Deferred uploads</h1>
86       <center><table border="0">
87         <tr>
88           <th align="center">Change</th>
89           <th align="center">Time remaining</th>
90           <th align="center">Uploader</th>
91           <th align="center">Closes</th>
92         </tr>
93         """
94     return res
95
96 def table_footer():
97     return '</table></center><br>\n'
98
99 def table_row(changesname, delay, changed_by, closes):
100     global row_number
101
102     res = '<tr class="%s">'%(['even','odd'][row_number %2])
103     res += (3*'<td valign="top">%s</td>')%tuple(map(html_escape,(changesname,delay,changed_by)))
104     res += ('<td valign="top">%s</td>' % 
105              ''.join(map(lambda close:  '<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s">#%s</a><br>' % (close, close),closes)))
106     res += '</tr>\n'
107     row_number+=1
108     return res
109
110 def get_upload_data(changesfn):
111     achanges = deb822.Changes(file(changesfn))
112     changesname = os.path.basename(changesfn)
113     delay = os.path.basename(os.path.dirname(changesfn))
114     m = re.match(r'([0-9]+)-day', delay)
115     if m:
116         delaydays = int(m.group(1))
117         remainingtime = max(0,24*60*60+os.stat(changesfn).st_mtime-time.time())
118         delay = "%d days %02d:%02d" %(delaydays, int(remainingtime/3600),int(remainingtime/60)%60)
119     else:
120         remainingtime = 0
121     #print dir(achanges)
122     #print achanges.keys()
123     uploader = achanges.get('changed-by')
124     uploader = re.sub(r'\s+(\S.*)\s+<.*>',r'\1',uploader)
125     return (delaydays*24*60*60+remainingtime, changesname, delay, uploader, achanges.get('closes').split())
126
127 def list_uploads(filelist):
128     uploads = map(get_upload_data, filelist)
129     uploads.sort()
130     print header()
131     if uploads:
132         print table_header()
133         print ''.join(map(lambda x: table_row(*x[1:]), uploads))
134         print table_footer()
135     else:
136         print '<h1>Currently no deferred uploads to Debian</h1>'
137     print footer()
138
139 list_uploads(sys.argv[1:])