mirror of
https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
synced 2025-05-22 16:01:35 +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
f32a8e37da
commit
a2dcb26901
@ -208,6 +208,7 @@ from britney2.utils import (old_libraries_format, undo_changes,
|
|||||||
create_provides_map, read_release_file,
|
create_provides_map, read_release_file,
|
||||||
read_sources_file, get_dependency_solvers,
|
read_sources_file, get_dependency_solvers,
|
||||||
invalidate_excuses, compile_nuninst,
|
invalidate_excuses, compile_nuninst,
|
||||||
|
ensuredir,
|
||||||
)
|
)
|
||||||
|
|
||||||
__author__ = 'Fabio Tranchitella and the Debian Release Team'
|
__author__ = 'Fabio Tranchitella and the Debian Release Team'
|
||||||
@ -1633,6 +1634,7 @@ class Britney(object):
|
|||||||
if not self.options.dry_run:
|
if not self.options.dry_run:
|
||||||
self.log("> Writing Excuses to %s" % self.options.excuses_output, type="I")
|
self.log("> Writing Excuses to %s" % self.options.excuses_output, type="I")
|
||||||
sorted_excuses = sorted(excuses.values(), key=lambda x: x.sortkey())
|
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,
|
write_excuses(sorted_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'):
|
||||||
@ -2742,6 +2744,7 @@ class Britney(object):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
ensuredir(os.path.dirname(self.options.upgrade_output))
|
||||||
with open(self.options.upgrade_output, 'w', encoding='utf-8') as f:
|
with open(self.options.upgrade_output, 'w', encoding='utf-8') as f:
|
||||||
self.__output = f
|
self.__output = f
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from urllib.parse import quote
|
|||||||
import apt_pkg
|
import apt_pkg
|
||||||
|
|
||||||
from britney2.hints import Hint, split_into_one_hint_per_package
|
from britney2.hints import Hint, split_into_one_hint_per_package
|
||||||
|
from britney2.utils import ensuredir
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
@ -385,6 +386,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)
|
||||||
|
ensuredir(directory)
|
||||||
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):
|
||||||
|
@ -346,6 +346,16 @@ def make_migrationitem(package, sources):
|
|||||||
return MigrationItem("%s/%s" % (item.uvname, sources[item.suite][item.package].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"):
|
def write_excuses(excuselist, dest_file, output_format="yaml"):
|
||||||
"""Write the excuses to dest_file
|
"""Write the excuses to dest_file
|
||||||
|
|
||||||
@ -354,6 +364,7 @@ def write_excuses(excuselist, dest_file, output_format="yaml"):
|
|||||||
or "legacy-html".
|
or "legacy-html".
|
||||||
"""
|
"""
|
||||||
if output_format == "yaml":
|
if output_format == "yaml":
|
||||||
|
ensuredir(os.path.dirname(dest_file))
|
||||||
with open(dest_file, 'w', encoding='utf-8') as f:
|
with open(dest_file, 'w', encoding='utf-8') as f:
|
||||||
edatalist = [e.excusedata() for e in excuselist]
|
edatalist = [e.excusedata() for e in excuselist]
|
||||||
excusesdata = {
|
excusesdata = {
|
||||||
@ -362,6 +373,7 @@ def write_excuses(excuselist, 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":
|
||||||
|
ensuredir(os.path.dirname(dest_file))
|
||||||
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>")
|
||||||
@ -425,6 +437,7 @@ def write_controlfiles(sources, packages, suite, basedir):
|
|||||||
(PROVIDES, 'Provides'), (CONFLICTS, 'Conflicts'),
|
(PROVIDES, 'Provides'), (CONFLICTS, 'Conflicts'),
|
||||||
(ESSENTIAL, 'Essential'))
|
(ESSENTIAL, 'Essential'))
|
||||||
|
|
||||||
|
ensuredir(basedir)
|
||||||
for arch in packages_s:
|
for arch in packages_s:
|
||||||
filename = os.path.join(basedir, 'Packages_%s' % arch)
|
filename = os.path.join(basedir, 'Packages_%s' % arch)
|
||||||
binaries = packages_s[arch][0]
|
binaries = packages_s[arch][0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user