diff --git a/britney2/policies/autopkgtest.py b/britney2/policies/autopkgtest.py index a54df25..69c04a2 100644 --- a/britney2/policies/autopkgtest.py +++ b/britney2/policies/autopkgtest.py @@ -76,7 +76,7 @@ class AutopkgtestPolicy(BasePolicy): # tests requested in this and previous runs # trigger -> src -> [arch] self.pending_tests = None - self.pending_tests_file = os.path.join(self.options.state_dir, 'autopkgtest-pending.json') + self.pending_tests_file = os.path.join(self.state_dir, 'autopkgtest-pending.json') # results map: trigger -> src -> arch -> [passed, version, run_id] # - trigger is "source/version" of an unstable package that triggered @@ -91,7 +91,7 @@ class AutopkgtestPolicy(BasePolicy): if self.options.adt_shared_results_cache: self.results_cache_file = self.options.adt_shared_results_cache else: - self.results_cache_file = os.path.join(self.options.state_dir, 'autopkgtest-results.cache') + self.results_cache_file = os.path.join(self.state_dir, 'autopkgtest-results.cache') try: self.options.adt_ppas = self.options.adt_ppas.strip().split() @@ -116,7 +116,7 @@ class AutopkgtestPolicy(BasePolicy): def initialise(self, britney): super().initialise(britney) - os.makedirs(self.options.state_dir, exist_ok=True) + os.makedirs(self.state_dir, exist_ok=True) self.read_pending_tests() if not hasattr(self.options, 'adt_baseline'): diff --git a/britney2/policies/policy.py b/britney2/policies/policy.py index 986c5b1..a35ef18 100644 --- a/britney2/policies/policy.py +++ b/britney2/policies/policy.py @@ -35,6 +35,10 @@ class BasePolicy(object): logger_name = ".".join((self.__class__.__module__, self.__class__.__name__)) self.logger = logging.getLogger(logger_name) + @property + def state_dir(self): + return self.options.state_dir + def register_hints(self, hint_parser): # pragma: no cover """Register new hints that this policy accepts @@ -299,7 +303,7 @@ class AgePolicy(BasePolicy): fallback_filename = os.path.join(self.suite_info.target_suite.path, 'Dates') using_new_name = False try: - filename = os.path.join(self.options.state_dir, 'age-policy-dates') + filename = os.path.join(self.state_dir, 'age-policy-dates') if not os.path.exists(filename) and os.path.exists(fallback_filename): filename = fallback_filename else: @@ -337,7 +341,7 @@ class AgePolicy(BasePolicy): min_days_default = self._min_days_default fallback_filename = os.path.join(self.suite_info.target_suite.path, 'Urgency') try: - filename = os.path.join(self.options.state_dir, 'age-policy-urgencies') + filename = os.path.join(self.state_dir, 'age-policy-urgencies') if not os.path.exists(filename) and os.path.exists(fallback_filename): filename = fallback_filename except AttributeError: @@ -381,7 +385,7 @@ class AgePolicy(BasePolicy): def _write_dates_file(self): dates = self._dates try: - directory = self.options.state_dir + directory = self.state_dir basename = 'age-policy-dates' old_file = os.path.join(self.suite_info.target_suite.path, 'Dates') except AttributeError: @@ -433,8 +437,8 @@ class RCBugPolicy(BasePolicy): fallback_unstable = os.path.join(source_suite.path, 'BugsV') fallback_testing = os.path.join(target_suite.path, 'BugsV') try: - filename_unstable = os.path.join(self.options.state_dir, 'rc-bugs-%s' % source_suite.name) - filename_testing = os.path.join(self.options.state_dir, 'rc-bugs-%s' % target_suite.name) + filename_unstable = os.path.join(self.state_dir, 'rc-bugs-%s' % source_suite.name) + filename_testing = os.path.join(self.state_dir, 'rc-bugs-%s' % target_suite.name) if not os.path.exists(filename_unstable) and not os.path.exists(filename_testing) and \ os.path.exists(fallback_unstable) and os.path.exists(fallback_testing): filename_unstable = fallback_unstable @@ -560,8 +564,8 @@ class PiupartsPolicy(BasePolicy): source_suite = self.suite_info.primary_source_suite target_suite = self.suite_info.target_suite try: - filename_unstable = os.path.join(self.options.state_dir, 'piuparts-summary-%s.json' % source_suite.name) - filename_testing = os.path.join(self.options.state_dir, 'piuparts-summary-%s.json' % target_suite.name) + filename_unstable = os.path.join(self.state_dir, 'piuparts-summary-%s.json' % source_suite.name) + filename_testing = os.path.join(self.state_dir, 'piuparts-summary-%s.json' % target_suite.name) except AttributeError as e: # pragma: no cover raise RuntimeError("Please set STATE_DIR in the britney configuration") from e self._piuparts['source'] = self._read_piuparts_summary(filename_unstable, keep_url=True)