mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-03-18 14:51:17 +00:00
Make sure that containing directories exist before writing output files
We don't use os.makedirs(dir, exist_ok=True) as that is too strict: it fails if the directory already exists with different permissions (e. g. with 775). Thus introduce a helper function ensuredir().
This commit is contained in:
parent
027b18f931
commit
7877a8500d
@ -207,6 +207,7 @@ from britney_util import (old_libraries_format, undo_changes,
|
||||
old_libraries, is_nuninst_asgood_generous,
|
||||
clone_nuninst, check_installability,
|
||||
create_provides_map,
|
||||
ensuredir,
|
||||
)
|
||||
from policies.policy import AgePolicy, RCBugPolicy, PolicyVerdict
|
||||
|
||||
@ -1857,6 +1858,7 @@ class Britney(object):
|
||||
if not self.options.dry_run:
|
||||
self.log("> Writing Excuses to %s" % self.options.excuses_output, type="I")
|
||||
sorted_excuses = sorted(excuses.values(), key=lambda x: x.sortkey())
|
||||
ensuredir(os.path.dirname(self.options.excuses_output))
|
||||
write_excuses(sorted_excuses, self.options.excuses_output,
|
||||
output_format="legacy-html")
|
||||
if hasattr(self.options, 'excuses_yaml_output'):
|
||||
@ -3007,6 +3009,7 @@ class Britney(object):
|
||||
except AttributeError:
|
||||
return
|
||||
|
||||
ensuredir(os.path.dirname(self.options.upgrade_output))
|
||||
with open(self.options.upgrade_output, 'w', encoding='utf-8') as f:
|
||||
self.__output = f
|
||||
|
||||
|
@ -352,6 +352,16 @@ def make_migrationitem(package, sources, VERSION=VERSION):
|
||||
return MigrationItem("%s/%s" % (item.uvname, sources[item.suite][item.package].version))
|
||||
|
||||
|
||||
def ensuredir(dir):
|
||||
"""Create dir if it does not exist
|
||||
|
||||
os.makedirs(dir, exist_ok=True) is too strict as that will fail if the
|
||||
direcotry already exists with different permissions.
|
||||
"""
|
||||
if not os.path.isdir(dir):
|
||||
os.makedirs(dir)
|
||||
|
||||
|
||||
def write_excuses(excuselist, dest_file, output_format="yaml"):
|
||||
"""Write the excuses to dest_file
|
||||
|
||||
@ -360,6 +370,7 @@ def write_excuses(excuselist, dest_file, output_format="yaml"):
|
||||
or "legacy-html".
|
||||
"""
|
||||
if output_format == "yaml":
|
||||
ensuredir(os.path.dirname(dest_file))
|
||||
with open(dest_file, 'w', encoding='utf-8') as f:
|
||||
edatalist = [e.excusedata() for e in excuselist]
|
||||
excusesdata = {
|
||||
@ -368,6 +379,7 @@ def write_excuses(excuselist, dest_file, output_format="yaml"):
|
||||
}
|
||||
f.write(yaml.dump(excusesdata, default_flow_style=False, allow_unicode=True))
|
||||
elif output_format == "legacy-html":
|
||||
ensuredir(os.path.dirname(dest_file))
|
||||
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("<html><head><title>excuses...</title>")
|
||||
@ -431,6 +443,7 @@ def write_controlfiles(sources, packages, suite, basedir):
|
||||
(PROVIDES, 'Provides'), (CONFLICTS, 'Conflicts'),
|
||||
(ESSENTIAL, 'Essential'))
|
||||
|
||||
ensuredir(basedir)
|
||||
for arch in packages_s:
|
||||
filename = os.path.join(basedir, 'Packages_%s' % arch)
|
||||
binaries = packages_s[arch][0]
|
||||
|
@ -6,6 +6,7 @@ import time
|
||||
from urllib.parse import quote
|
||||
|
||||
from hints import Hint, split_into_one_hint_per_package
|
||||
from britney_util import ensuredir
|
||||
|
||||
|
||||
@unique
|
||||
@ -383,6 +384,7 @@ class AgePolicy(BasePolicy):
|
||||
basename = 'Dates'
|
||||
old_file = None
|
||||
filename = os.path.join(directory, basename)
|
||||
ensuredir(directory)
|
||||
filename_tmp = os.path.join(directory, '%s_new' % basename)
|
||||
with open(filename_tmp, 'w', encoding='utf-8') as fd:
|
||||
for pkg in sorted(dates):
|
||||
|
Loading…
x
Reference in New Issue
Block a user