Extends delete command with --oldest & --latest options - #1369
Extends delete command with --oldest & --latest options#1369funkyfuture wants to merge 13 commits into
Conversation
|
|
||
| if args.oldest or args.latest: | ||
| if args.location.archive: | ||
| logger.warning('The options --oldest and --latest have no effect on archive targets.') |
There was a problem hiding this comment.
This branch should abort to avoid unintentionally deleting stuff.
|
Interesting feature. #128 is kinda related, maybe we can factor this into a more generic version that is easier to apply to other commands (e.g. an |
|
sure, more generic is always reasonable. what about these properties / methods?
|
|
or should these rather be attributes of |
|
i followed these thoughts by implementing with this outcome: the functionality of i ended up with something that is not exactly what #128 proposes. it's rather a slicing now, so |
|
I also did implement some --last N stuff for If generalizing that, we need to be careful with defaults (if that code includes handling of that). |
| if self.exit_code: | ||
| break | ||
| else: | ||
| logger.error('There are no archives.') |
There was a problem hiding this comment.
doesn't it always end in here, if there is no exit_code > 0 (warning or error) above?
if we successfully deleted all archives, why does it emit this error? (assuming we wanted to delete all archives)
There was a problem hiding this comment.
no, this is only reached if archives is empty.
There was a problem hiding this comment.
>>> for i in range(3):
... print(i)
... else:
... print("didn't break out of the loop")
...
0
1
2
didn't break out of the loop
There was a problem hiding this comment.
thanks for reminding me that i need to get rid of that misconception i have about for ... else.
i think the simplest would be to allow though i would prefer a default of 1 for each argument, problems arise as the code can't figure out whether and which flag was actually provided by the user. a clever idea to deal with that would be interesting, but still one would need as of now, either of both flags must be used with an explicit argument, which makes it quiet sane, imo. this distinguishes it from the |
|
i tend to move argparsing code to an own module, especially as |
|
we already thought about that, but delayed it because we want to maintain multiple branches concurrently and be able to merge changes in archiver.py without troubles. and we shouldn't do big src cleanup in 1.0-maint. |
|
okay, i can need some feedback here.
the rationale for using i propose to refactor |
| """Delete multiple archives""" | ||
| manifest, key = Manifest.load(repository) | ||
| archives = self._get_archives_slice(args, manifest) | ||
| for i, archive in enumerate(archives): |
There was a problem hiding this comment.
... enumerate(archives, 1) (and remove the +1 below)
|
Just an idea: you cleaned up the toplevel dispatch method to be shorter and just call the 3 _xxxx methods for the 3 cases archive, archives, repo. They could be also functions INSIDE the dispatch method, not methods of Archiver. As you prefixed them with underscore, you indicate "don't call me" somehow anyway, so they could be also private functions defined inside the method? |
|
Can you rebase on current master? |
|
An idea about #1369 (comment): Maybe that is the reason why we rather want to use first and last (not oldest and latest). We could just document, that sort order is by-timestamp (so first means oldest and last means latest), but later, if we feel the need, we could also sort by other criterial (using a sort-by option) and still use the same first/last option to give the index. Not sure if we ever need it, currently there is only timestamp and name that somehow qualify for sorting, but selecting the first/last N of a list sorted by name - not sure if it makes sense. |
whenever i come across such nested callables, i experience a great loss of readability. flat is better than nested. if you really want it like this, tell me. but i really consider it a bad practice.
to be consistent i would also add a |
|
Another point about nesting callables is that the namespace inside a callable is anonymous for all practical purposes, so they would be unreachable for testing. |
|
Related: #128 |
- also ensures that `Archives.list` returns a list
also renames function PrefixSpec to prefix_spec
|
aigh't, i added the |
Current coverage is 84.43% (diff: 93.20%)@@ master #1369 diff @@
==========================================
Files 18 18
Lines 6031 6115 +84
Methods 0 0
Messages 0 0
Branches 1024 1042 +18
==========================================
+ Hits 5145 5163 +18
- Misses 638 697 +59
- Partials 248 255 +7
|
refactors ArchiveChecker to be used as context manager
| break | ||
| if len(archives) - i > 1: | ||
| write('\n') | ||
| write() |
There was a problem hiding this comment.
ehrm, guess you need to keep the \n here. write() does not write one by default, like print() does.
|
this PR is a bit hard to review. single changesets seem to be incomplete, reviewing the overall changes is way to much. |
|
Can you redo your changes and:
|
|
sorry for the mess.
that's the cause for the mixups in the commits. i'll see to consolidate and give a notice. |
|
closing in favor of #1554 |
i added a
--latestand--oldestoption to simply delete the newest resp. oldest backup from a repository. eg, it comes handy in bash scripts:alternatively, it could be implemented as
--last nand--first nwherendefaults to 1.