diff --git a/britney.py b/britney.py index f7d0e74..fd8f2b7 100755 --- a/britney.py +++ b/britney.py @@ -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 @@ -1906,6 +1907,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'): @@ -3056,6 +3058,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 diff --git a/britney_util.py b/britney_util.py index 92c58d1..4961f6b 100644 --- a/britney_util.py +++ b/britney_util.py @@ -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("\n") f.write("excuses...") @@ -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] diff --git a/policies/policy.py b/policies/policy.py index 4d3e909..f766cc1 100644 --- a/policies/policy.py +++ b/policies/policy.py @@ -5,6 +5,7 @@ import os import time from hints import Hint, split_into_one_hint_per_package +from britney_util import ensuredir @unique @@ -367,6 +368,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):