Skip to content

Commit eb65492

Browse files
committed
Add (Unix) TimestampMatcher
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
1 parent 3ba0dcb commit eb65492

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

rotate_backups/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,30 @@ def search(self, entry: str) -> FilenameMatch:
312312
return FilenameMatch(match)
313313

314314

315+
class TimestampMatch:
316+
entry: str = None
317+
field: str = None
318+
319+
def __init__(self, entry: str, timestamp='mtime'):
320+
self.entry = entry
321+
self.field = f'st_{timestamp}'
322+
323+
def match_to_datetime(self) -> datetime.datetime:
324+
return datetime.datetime.fromtimestamp(
325+
getattr(os.stat(self.entry), self.field)
326+
)
327+
328+
329+
class TimestampMatcher:
330+
timestamp: str = None
331+
332+
def __init__(self, timestamp='mtime'):
333+
self.timestamp = timestamp
334+
335+
def search(self, entry: str) -> Match:
336+
return TimestampMatch(entry, self.timestamp)
337+
338+
315339
class RotateBackups(PropertyManager):
316340

317341
"""Python API for the ``rotate-backups`` program."""

0 commit comments

Comments
 (0)