AgePolicy: Create the (new) date file automatically

Closes: Debian/britney2#13
Signed-off-by: Niels Thykier <niels@thykier.net>
pre-rebase-2016-10-25
Niels Thykier 8 years ago
parent 190be31014
commit 6de0c3408c

@ -281,13 +281,20 @@ class AgePolicy(BasePolicy):
"""Parse the dates file"""
dates = self._dates
fallback_filename = os.path.join(self.options.testing, 'Dates')
using_new_name = False
try:
filename = os.path.join(self.options.state_dir, 'age-policy-dates')
if not os.path.exists(filename) and os.path.exists(fallback_filename):
filename = fallback_filename
else:
using_new_name = True
except AttributeError:
if os.path.exists(fallback_filename):
filename = fallback_filename
else:
raise RuntimeError("Please set STATE_DIR in the britney configuration")
try:
with open(filename, encoding='utf-8') as fd:
for line in fd:
# <source> <version> <date>
@ -298,6 +305,13 @@ class AgePolicy(BasePolicy):
dates[l[0]] = (l[1], int(l[2]))
except ValueError:
pass
except FileNotFoundError:
if not using_new_name:
# If we using the legacy name, then just give up
raise
self.log("%s does not appear to exist. Creating it" % filename)
with open(filename, mode='wx', encoding='utf-8'):
pass
def _read_urgencies_file(self, britney):
urgencies = self._urgencies

Loading…
Cancel
Save