Make sure that containing directories exist before writing output files

ubuntu/rebased
Colin Watson 11 years ago committed by Iain Lane
parent c582733989
commit 3b8daa98ec
No known key found for this signature in database
GPG Key ID: E352D5C51C5041D4

@ -797,6 +797,7 @@ class Britney(object):
# write excuses to the output file # write excuses to the output file
if not self.options.dry_run: if not self.options.dry_run:
self.logger.info("> Writing Excuses to %s", self.options.excuses_output) self.logger.info("> Writing Excuses to %s", self.options.excuses_output)
os.makedirs(os.path.dirname(self.options.excuses_output), exist_ok=True)
write_excuses(excuses, self.options.excuses_output, write_excuses(excuses, self.options.excuses_output,
output_format="legacy-html") output_format="legacy-html")
if hasattr(self.options, 'excuses_yaml_output'): if hasattr(self.options, 'excuses_yaml_output'):
@ -1545,6 +1546,7 @@ class Britney(object):
" as this is a dry-run.") " as this is a dry-run.")
elif hasattr(self.options, 'upgrade_output'): elif hasattr(self.options, 'upgrade_output'):
upgrade_output = getattr(self.options, 'upgrade_output') upgrade_output = getattr(self.options, 'upgrade_output')
os.makedirs(os.path.dirname(self.options.upgrade_output), exist_ok=True)
file_handler = logging.FileHandler(upgrade_output, mode='w', encoding='utf-8') file_handler = logging.FileHandler(upgrade_output, mode='w', encoding='utf-8')
output_formatter = logging.Formatter('%(message)s') output_formatter = logging.Formatter('%(message)s')
file_handler.setFormatter(output_formatter) file_handler.setFormatter(output_formatter)

@ -516,6 +516,7 @@ class AgePolicy(BasePolicy):
basename = 'Dates' basename = 'Dates'
old_file = None old_file = None
filename = os.path.join(directory, basename) filename = os.path.join(directory, basename)
os.makedirs(directory, exist_ok=True)
filename_tmp = os.path.join(directory, '%s_new' % basename) filename_tmp = os.path.join(directory, '%s_new' % basename)
with open(filename_tmp, 'w', encoding='utf-8') as fd: with open(filename_tmp, 'w', encoding='utf-8') as fd:
for pkg in sorted(dates): for pkg in sorted(dates):

@ -299,7 +299,6 @@ def write_heidi_delta(filename, all_selected):
fd.write('%s%s %s %s\n' % (prefix, item.package, fd.write('%s%s %s %s\n' % (prefix, item.package,
item.version, item.architecture)) item.version, item.architecture))
def write_excuses(excuses, dest_file, output_format="yaml"): def write_excuses(excuses, dest_file, output_format="yaml"):
"""Write the excuses to dest_file """Write the excuses to dest_file
@ -309,6 +308,7 @@ def write_excuses(excuses, dest_file, output_format="yaml"):
""" """
excuselist = sorted(excuses.values(), key=lambda x: x.sortkey()) excuselist = sorted(excuses.values(), key=lambda x: x.sortkey())
if output_format == "yaml": if output_format == "yaml":
os.makedirs(os.path.dirname(dest_file), exist_ok=True)
with open(dest_file, 'w', encoding='utf-8') as f: with open(dest_file, 'w', encoding='utf-8') as f:
edatalist = [e.excusedata(excuses) for e in excuselist] edatalist = [e.excusedata(excuses) for e in excuselist]
excusesdata = { excusesdata = {
@ -317,6 +317,7 @@ def write_excuses(excuses, dest_file, output_format="yaml"):
} }
f.write(yaml.dump(excusesdata, default_flow_style=False, allow_unicode=True)) f.write(yaml.dump(excusesdata, default_flow_style=False, allow_unicode=True))
elif output_format == "legacy-html": elif output_format == "legacy-html":
os.makedirs(os.path.dirname(dest_file), exist_ok=True)
with open(dest_file, 'w', encoding='utf-8') as f: with open(dest_file, 'w', encoding='utf-8') 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("<!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("<html><head><title>excuses...</title>")

Loading…
Cancel
Save