-
-
Notifications
You must be signed in to change notification settings - Fork 867
Archives filters #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Archives filters #1554
Changes from all commits
f6b9276
17f2363
f2d4d36
369d0a0
e0e9edf
bd7cc38
089995e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,11 +142,16 @@ def __delitem__(self, name): | |
| name = safe_encode(name) | ||
| del self._archives[name] | ||
|
|
||
| def list(self, sort_by=None, reverse=False): | ||
| # inexpensive Archive.list_archives replacement if we just need .name, .id, .ts | ||
| archives = self.values() # [self[name] for name in self] | ||
| def list(self, sort_by=None, reverse=False, prefix=''): | ||
| """ | ||
| Inexpensive Archive.list_archives replacement if we just need .name, .id, .ts | ||
| Returns list of borg.helpers.ArchiveInfo instances | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please have a look at the usual docstring style and use the same. do a fixup commit.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring style: |
||
| archives = [x for x in self.values() if x.name.startswith(prefix)] | ||
| if sort_by is not None: | ||
| archives = sorted(archives, key=attrgetter(sort_by), reverse=reverse) | ||
| archives = sorted(archives, key=attrgetter(sort_by)) | ||
| if reverse: | ||
| archives.reverse() | ||
| return archives | ||
|
|
||
| def set_raw_dict(self, d): | ||
|
|
@@ -568,10 +573,6 @@ def CompressionSpec(s): | |
| raise ValueError | ||
|
|
||
|
|
||
| def PrefixSpec(s): | ||
| return replace_placeholders(s) | ||
|
|
||
|
|
||
| def dir_is_cachedir(path): | ||
| """Determines whether the specified path is a cache directory (and | ||
| therefore should potentially be excluded from the backup) according to | ||
|
|
@@ -654,6 +655,19 @@ def replace_placeholders(text): | |
| } | ||
| return format_line(text, data) | ||
|
|
||
| PrefixSpec = replace_placeholders | ||
|
|
||
|
|
||
| HUMAN_SORT_KEYS = ['timestamp'] + list(ArchiveInfo._fields) | ||
| HUMAN_SORT_KEYS.remove('ts') | ||
|
|
||
|
|
||
| def SortBySpec(text): | ||
| for token in text.split(','): | ||
| if token not in HUMAN_SORT_KEYS: | ||
| raise ValueError('Invalid sort key: %s' % token) | ||
| return text.replace('timestamp', 'ts') | ||
|
|
||
|
|
||
| def safe_timestamp(item_timestamp_ns): | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens with
borg delete --prefix repo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
BORG_REPOSITORYis set, it would filter all archives with the prefixrepo, otherwise it would complain about a missing location arg.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that was a bad example. ;)