|
71 | 71 | :class:`~dateutil.relativedelta.relativedelta` objects as values. This |
72 | 72 | dictionary is generated based on the tuples in :data:`ORDERED_FREQUENCIES`. |
73 | 73 | """ |
74 | | - |
75 | | -TIMESTAMP_PATTERN = re.compile(r''' |
| 74 | +TIMESTAMP = r''' |
76 | 75 | # Required components. |
77 | 76 | (?P<year>\d{4} ) \D? |
78 | 77 | (?P<month>\d{2}) \D? |
|
83 | 82 | (?P<minute>\d{2}) \D? |
84 | 83 | (?P<second>\d{2})? |
85 | 84 | )? |
86 | | -''', re.VERBOSE) |
| 85 | +''' |
| 86 | + |
87 | 87 | """ |
88 | 88 | A compiled regular expression object used to match timestamps encoded in |
89 | 89 | filenames. |
@@ -197,6 +197,7 @@ def load_config_file(configuration_file=None, expand=True): |
197 | 197 | options = dict(include_list=split(items.get('include-list', '')), |
198 | 198 | exclude_list=split(items.get('exclude-list', '')), |
199 | 199 | io_scheduling_class=items.get('ionice'), |
| 200 | + timestamp=items.get('timestamp'), |
200 | 201 | strict=coerce_boolean(items.get('strict', 'yes')), |
201 | 202 | prefer_recent=coerce_boolean(items.get('prefer-recent', 'no'))) |
202 | 203 | # Don't override the value of the 'removal_command' property unless the |
@@ -254,6 +255,10 @@ def __init__(self, rotation_scheme, **options): |
254 | 255 | options.update(rotation_scheme=rotation_scheme) |
255 | 256 | super(RotateBackups, self).__init__(**options) |
256 | 257 |
|
| 258 | + @cached_property(writable=True) |
| 259 | + def timestamp(self): |
| 260 | + return TIMESTAMP |
| 261 | + |
257 | 262 | @mutable_property |
258 | 263 | def config_file(self): |
259 | 264 | """ |
@@ -557,15 +562,19 @@ def collect_backups(self, location): |
557 | 562 | location = coerce_location(location) |
558 | 563 | logger.info("Scanning %s for backups ..", location) |
559 | 564 | location.ensure_readable() |
| 565 | + pattern=re.compile(self.timestamp, re.VERBOSE) |
560 | 566 | for entry in natsort(location.context.list_entries(location.directory)): |
561 | | - match = TIMESTAMP_PATTERN.search(entry) |
| 567 | +# match = TIMESTAMP_PATTERN.search(entry) |
| 568 | + match = pattern.search( entry) |
562 | 569 | if match: |
563 | 570 | if self.exclude_list and any(fnmatch.fnmatch(entry, p) for p in self.exclude_list): |
564 | 571 | logger.verbose("Excluded %s (it matched the exclude list).", entry) |
565 | 572 | elif self.include_list and not any(fnmatch.fnmatch(entry, p) for p in self.include_list): |
566 | 573 | logger.verbose("Excluded %s (it didn't match the include list).", entry) |
567 | 574 | else: |
568 | 575 | try: |
| 576 | +# for group in match.groups('0'): |
| 577 | +# print group |
569 | 578 | backups.append(Backup( |
570 | 579 | pathname=os.path.join(location.directory, entry), |
571 | 580 | timestamp=datetime.datetime(*(int(group, 10) for group in match.groups('0'))), |
|
0 commit comments