Skip to content

Commit 4b27e70

Browse files
committed
Allow to pass stat-timestamp in config
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
1 parent c6f61d7 commit 4b27e70

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

rotate_backups/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def load_config_file(configuration_file=None, expand=True):
228228
# 'timestamp-pattern' configuration file option has a value set.
229229
if items.get('timestamp-pattern'):
230230
options['timestamp_pattern'] = items['timestamp-pattern']
231+
if items.get('stat-timestamp'):
232+
options['stat_timestamp'] = items['stat-timestamp']
231233
# Expand filename patterns?
232234
if expand and location.have_wildcards:
233235
logger.verbose("Expanding filename pattern %s on %s ..", location.directory, location.context)
@@ -404,9 +406,6 @@ def __init__(self, rotation_scheme, **options):
404406
"""
405407
options.update(rotation_scheme=rotation_scheme)
406408
super(RotateBackups, self).__init__(**options)
407-
if self.stat_timestamp:
408-
logger.info("Using file mtime to determine file date")
409-
self.matcher = FilestatMatcher()
410409

411410
@mutable_property
412411
def config_file(self):
@@ -550,6 +549,15 @@ def rotation_scheme(self):
550549
@mutable_property
551550
def stat_timestamp(self):
552551
"""Whether to use the files' mtime instead of parsing their name."""
552+
return isinstance(self.match, FilestatMatcher)
553+
554+
@stat_timestamp.setter
555+
def stat_timestamp(self, value):
556+
if value:
557+
logger.info("Using file mtime to determine file date")
558+
self.matcher = FilestatMatcher()
559+
elif isinstance(self.match, FilestatMatcher):
560+
del self.matcher
553561

554562
@mutable_property
555563
def strict(self):

rotate_backups/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ def test_rotate_backups_mtime(self):
258258
parser.set(subdir, 'monthly', '12')
259259
parser.set(subdir, 'yearly', 'always')
260260
parser.set(subdir, 'ionice', 'idle')
261+
parser.set(subdir, 'stat-timestamp', 'yes')
261262
with open(config_file, 'w') as handle:
262263
parser.write(handle)
263264
self.create_sample_backup_set(root)
264265
map = self.apply_mtime_and_rename(root, subdir)
265-
run_cli(main, '--verbose', '--config=%s' % config_file,
266-
'--stat-timestamp')
266+
run_cli(main, '--verbose', '--config=%s' % config_file)
267267
backups_that_were_preserved = set(os.listdir(subdir))
268268
assert backups_that_were_preserved == set([map[e]
269269
for e in expected_to_be_preserved])

0 commit comments

Comments
 (0)