util: Add new "write_excuses" function

Signed-off-by: Niels Thykier <niels@thykier.net>
debian
Niels Thykier 11 years ago
parent 4b690fac00
commit a378bb6060

@ -186,14 +186,12 @@ import string
import time
import optparse
import urllib
import yaml
import apt_pkg
from functools import reduce, partial
from itertools import chain, ifilter, product
from operator import attrgetter
from datetime import datetime
if __name__ == '__main__':
# Check if there is a python-search dir for this version of
@ -217,7 +215,8 @@ from hints import HintCollection
from britney_util import (old_libraries_format, same_source, undo_changes,
register_reverses, compute_reverse_tree,
read_nuninst, write_nuninst, write_heidi,
eval_uninst, newly_uninst, make_migrationitem)
eval_uninst, newly_uninst, make_migrationitem,
write_excuses)
from consts import (VERSION, SECTION, BINARIES, MAINTAINER, FAKESRC,
SOURCE, SOURCEVER, ARCHITECTURE, DEPENDS, CONFLICTS,
PROVIDES, RDEPENDS, RCONFLICTS, MULTIARCH, ESSENTIAL)
@ -1668,28 +1667,12 @@ class Britney(object):
# write excuses to the output file
if not self.options.dry_run:
self.__log("> Writing Excuses to %s" % self.options.excuses_output, type="I")
f = open(self.options.excuses_output, 'w')
f.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n")
f.write("<html><head><title>excuses...</title>")
f.write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"></head><body>\n")
f.write("<p>Generated: " + time.strftime("%Y.%m.%d %H:%M:%S %z", time.gmtime(time.time())) + "</p>\n")
f.write("<ul>\n")
for e in self.excuses:
f.write("<li>%s" % e.html())
f.write("</ul></body></html>\n")
f.close()
write_excuses(self.excuses, self.options.excuses_output,
output_format="legacy-html")
if hasattr(self.options, 'excuses_yaml_output'):
self.__log("> Writing YAML Excuses to %s" % self.options.excuses_yaml_output, type="I")
f = open(self.options.excuses_yaml_output, 'w')
excuselist = []
for e in self.excuses:
excuselist.append(e.excusedata())
excusesdata = {}
excusesdata["sources"] = excuselist
excusesdata["generated"] = datetime.utcnow()
f.write(yaml.dump(excusesdata, default_flow_style=False, allow_unicode=True))
f.close()
write_excuses(self.excuses, self.options.excuses_yaml_output,
output_format="yaml")
self.__log("Update Excuses generation completed", type="I")

@ -23,9 +23,12 @@
import apt_pkg
from functools import partial
from datetime import datetime
from itertools import chain, ifilter, ifilterfalse, izip, repeat
import re
import time
import yaml
from migrationitem import MigrationItem, UnversionnedMigrationItem
from consts import (VERSION, BINARIES, PROVIDES, DEPENDS, CONFLICTS,
@ -413,3 +416,34 @@ def make_migrationitem(package, sources, VERSION=VERSION):
item = UnversionnedMigrationItem(package)
return MigrationItem("%s/%s" % (item.uvname, sources[item.suite][item.package][VERSION]))
def write_excuses(excuses, dest_file, output_format="yaml"):
"""Write the excuses to dest_file
Writes a list of excuses in a specified output_format to the
path denoted by dest_file. The output_format can either be "yaml"
or "legacy-html".
"""
if output_format == "yaml":
with open(dest_file, 'w') as f:
excuselist = []
for e in excuses:
excuselist.append(e.excusedata())
excusesdata = {}
excusesdata["sources"] = excuselist
excusesdata["generated"] = datetime.utcnow()
f.write(yaml.dump(excusesdata, default_flow_style=False, allow_unicode=True))
elif output_format == "legacy-html":
with open(dest_file, 'w') as f:
f.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n")
f.write("<html><head><title>excuses...</title>")
f.write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"></head><body>\n")
f.write("<p>Generated: " + time.strftime("%Y.%m.%d %H:%M:%S %z", time.gmtime(time.time())) + "</p>\n")
f.write("<ul>\n")
for e in excuses:
f.write("<li>%s" % e.html())
f.write("</ul></body></html>\n")
else:
raise ValueError('Output format must be either "yaml or "legacy-html"')

Loading…
Cancel
Save