~laney/ubuntu-archive-tools/cm-show-fix-released

« back to all changes in this revision

Viewing changes to priority-mismatches

  • Committer: Colin Watson
  • Date: 2014-07-01 12:02:06 UTC
  • Revision ID: cjwatson@canonical.com-20140701120206-qnmfbpwmeu3to2kf
*-mismatches: Optionally produce HTML versions of reports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import atexit
31
31
from collections import defaultdict
32
32
import gzip
 
33
try:
 
34
    from html import escape
 
35
except ImportError:
 
36
    from cgi import escape
33
37
from optparse import OptionParser
34
38
import os
35
39
import re
36
40
import shutil
37
41
import sys
38
42
import tempfile
 
43
from textwrap import dedent
39
44
import time
40
45
 
41
46
import apt_pkg
101
106
    return pkgs
102
107
 
103
108
 
104
 
def process(suite, components, arch):
 
109
def process(options, arch):
 
110
    suite = options.suite
 
111
    components = options.component.split(',')
 
112
 
105
113
    archive = os.path.expanduser('~/mirror/ubuntu/')
106
114
 
107
115
    if suite in ("warty", "hoary"):
197
205
            for pkg in changed[oldprio][newprio]:
198
206
                print("%s" % pkg)
199
207
            print()
 
208
            if options.html_output is not None:
 
209
                print("<h3>%s</h3>" % escape(header), file=options.html_output)
 
210
                print("<ul>", file=options.html_output)
 
211
                for pkg in changed[oldprio][newprio]:
 
212
                    print(
 
213
                        "<li>%s</li>" % escape(pkg), file=options.html_output)
 
214
                print("</ul>", file=options.html_output)
200
215
 
201
216
 
202
217
def main():
205
220
    parser.add_option(
206
221
        "-l", "--launchpad", dest="launchpad_instance", default="production")
207
222
    parser.add_option('-o', '--output-file', help='output to this file')
 
223
    parser.add_option('--html-output-file', help='output HTML to this file')
208
224
    parser.add_option('-a', '--architecture',
209
225
                      help='look at germinate output for this architecture')
210
226
    parser.add_option('-c', '--component',
220
236
 
221
237
    if options.output_file is not None:
222
238
        sys.stdout = open('%s.new' % options.output_file, 'w')
 
239
    if options.html_output_file is not None:
 
240
        options.html_output = open('%s.new' % options.html_output_file, 'w')
 
241
    else:
 
242
        options.html_output = None
223
243
 
224
 
    print('Generated: %s' % time.strftime('%a %b %e %H:%M:%S %Z %Y'))
 
244
    options.timestamp = time.strftime('%a %b %e %H:%M:%S %Z %Y')
 
245
    print('Generated: %s' % options.timestamp)
225
246
    print()
226
247
 
 
248
    if options.html_output is not None:
 
249
        print(dedent("""\
 
250
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 
251
             "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
252
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 
253
            <head>
 
254
              <meta http-equiv="Content-Type"
 
255
                    content="text/html; charset=utf-8" />
 
256
              <title>Priority mismatches for %s</title>
 
257
              <style type="text/css">
 
258
                body { background: #CCCCB0; color: black; }
 
259
              </style>
 
260
            </head>
 
261
            <body>
 
262
            <h1>Priority mismatches for %s</h1>
 
263
            """) % (escape(options.suite), escape(options.suite)),
 
264
            file=options.html_output)
 
265
 
227
266
    if options.architecture is None:
228
267
        for arch in ('amd64', 'arm64', 'armhf', 'i386', 'powerpc', 'ppc64el'):
229
268
            print(arch)
230
269
            print('=' * len(arch))
231
270
            print()
232
 
            process(options.suite, options.component.split(','), arch)
 
271
            if options.html_output is not None:
 
272
                print("<h2>%s</h2>" % escape(arch), file=options.html_output)
 
273
            process(options, arch)
233
274
    else:
234
 
        process(options.suite, options.component.split(','),
235
 
                options.architecture)
 
275
        process(options, options.architecture)
236
276
 
 
277
    if options.html_output_file is not None:
 
278
        print(
 
279
            "<p><small>Generated: %s</small></p>" % escape(options.timestamp),
 
280
            file=options.html_output)
 
281
        print("</body></html>", file=options.html_output)
 
282
        options.html_output.close()
 
283
        os.rename(
 
284
            '%s.new' % options.html_output_file, options.html_output_file)
237
285
    if options.output_file is not None:
238
286
        sys.stdout.close()
239
287
        os.rename('%s.new' % options.output_file, options.output_file)