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>
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.
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.
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
21 ################################################################################
23 import sys, os, re, time
25 from debian_bundle import deb822
26 from daklib import database
27 from daklib import queue
28 from daklib import utils
30 ################################################################################
34 html_escaping = {'"':'"', '&':'&', '<':'<', '>':'>'}
35 re_html_escaping = re.compile('|'.join(map(re.escape, html_escaping.keys())))
37 return re_html_escaping.sub(lambda x: html_escaping.get(x.group(0)), s)
39 ################################################################################
42 return """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
43 <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
44 <title>Deferred uploads to Debian</title>
45 <link type="text/css" rel="stylesheet" href="style.css">
46 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico">
50 <a href="http://www.debian.org/">
51 <img src="http://www.debian.org/logos/openlogo-nd-50.png" border="0" hspace="0" vspace="0" alt=""></a>
52 <a href="http://www.debian.org/">
53 <img src="http://www.debian.org/Pics/debian.png" border="0" hspace="0" vspace="0" alt="Debian Project"></a>
56 <table class="reddy" width="100%">
59 <img src="http://www.debian.org/Pics/red-upperleft.png" align="left" border="0" hspace="0" vspace="0"
60 alt="" width="15" height="16"></td>
61 <td rowspan="2" class="reddy">Deferred uploads to Debian</td>
63 <img src="http://www.debian.org/Pics/red-upperright.png" align="right" border="0" hspace="0" vspace="0"
64 alt="" width="16" height="16"></td>
68 <img src="http://www.debian.org/Pics/red-lowerleft.png" align="left" border="0" hspace="0" vspace="0"
69 alt="" width="16" height="16"></td>
71 <img src="http://www.debian.org/Pics/red-lowerright.png" align="right" border="0" hspace="0" vspace="0"
72 alt="" width="15" height="16"></td>
78 res = "<p class=\"validate\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
79 res += """<a href="http://validator.w3.org/check?uri=referer">
80 <img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a>
81 <a href="http://jigsaw.w3.org/css-validator/check/referer">
82 <img border="0" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"
83 height="31" width="88"></a>
85 res += "</body></html>"
89 return """<h1>Deferred uploads</h1>
90 <center><table border="0">
92 <th align="center">Change</th>
93 <th align="center">Time remaining</th>
94 <th align="center">Uploader</th>
95 <th align="center">Closes</th>
101 return '</table><br/><p>non-NEW uploads are <a href="/deferred/">available</a>, see the <a href="ftp://ftp-master.debian.org/pub/UploadQueue/README">UploadQueue-README</a> for more information.</p></center><br/>\n'
103 def table_row(changesname, delay, changed_by, closes):
106 res = '<tr class="%s">'%((row_number%2) and 'odd' or 'even')
107 res += (3*'<td valign="top">%s</td>')%tuple(map(html_escape,(changesname,delay,changed_by)))
108 res += ('<td valign="top">%s</td>' %
109 ''.join(map(lambda close: '<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s">#%s</a><br>' % (close, close),closes)))
114 def get_upload_data(changesfn):
115 achanges = deb822.Changes(file(changesfn))
116 changesname = os.path.basename(changesfn)
117 delay = os.path.basename(os.path.dirname(changesfn))
118 m = re.match(r'([0-9]+)-day', delay)
120 delaydays = int(m.group(1))
121 remainingtime = (delaydays>0)*max(0,24*60*60+os.stat(changesfn).st_mtime-time.time())
122 delay = "%d days %02d:%02d" %(max(delaydays-1,0), int(remainingtime/3600),int(remainingtime/60)%60)
126 uploader = achanges.get('changed-by')
127 uploader = re.sub(r'^\s*(\S.*)\s+<.*>',r'\1',uploader)
128 if Cnf.has_key("Show-Deferred::LinkPath"):
130 suites = database.get_suites(achanges['source'],src=1)
131 if 'unstable' not in suites and 'experimental' not in suites:
133 for b in achanges['binary'].split():
134 suites = database.get_suites(b)
135 if 'unstable' not in suites and 'experimental' not in suites:
138 # we don't link .changes because we don't want other people to
139 # upload it with the existing signature.
140 for afn in map(lambda x: x['name'],achanges['files']):
141 lfn = os.path.join(Cnf["Show-Deferred::LinkPath"],afn)
142 qfn = os.path.join(os.path.dirname(changesfn),afn)
143 if os.path.islink(lfn):
145 if os.path.exists(qfn):
148 return (delaydays*24*60*60+remainingtime, changesname, delay, uploader, achanges.get('closes').split())
150 def list_uploads(filelist):
151 uploads = map(get_upload_data, filelist)
156 print ''.join(map(lambda x: table_row(*x[1:]), uploads))
159 print '<h1>Currently no deferred uploads to Debian</h1>'
162 def usage (exit_code=0):
167 print >> f, """Usage: dak show-deferred /path/to/DEFERRED
168 -h, --help show this help and exit.
169 -p, --html-path [path] override output directory.
174 global Cnf, Options, Upload, projectB
175 Cnf = utils.get_conf()
176 Arguments = [('h',"help","Show-Deferred::Options::Help"),
177 ("p","link-path","Show-Deferred::LinkPath","HasArg")]
179 if not Cnf.has_key("Show-Deferred::Options::LinkPath"):
180 Cnf["Show-Deferred::Options::LinkPath"] = "/org/ftp.debian.org/web/deferred/"
181 if not Cnf.has_key("Show-Deferred::Options::%s" % (i)):
182 Cnf["Show-Deferred::Options::%s" % (i)] = ""
183 args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
184 Options = Cnf.SubTree("Show-Deferred::Options")
187 Upload = queue.Upload(Cnf)
188 projectB = Upload.projectB
197 for r,d,f in os.walk(args[0]):
198 filelist += map (lambda x: os.path.join(r,x),
199 filter(lambda x: x.endswith('.changes'), f))
200 list_uploads(filelist)
202 if Cnf.has_key("Show-Deferred::LinkPath"):
204 for r,d,f in os.walk(Cnf["Show-Deferred::LinkPath"]):
206 af = os.path.join(r,af)
207 if not os.path.exists(af):
208 print >> sys.stderr, "obsolete",af