[add] series CLI - --sort-by argument for series show#1836
Conversation
When using the `series show` CLI subcommand, you can now specify `--sort-by entity` to sort by entity ID or `--sort-by seen` for last seen date (default), and `--descending` or `--ascending` to specify the sort order.
flexget/plugins/cli/series.py
Outdated
| help='Show the releases FlexGet has seen for a given series ') | ||
| show_parser = subparsers.add_parser('show', parents=[series_parser, table_parser], | ||
| help='Show the releases FlexGet has seen for a given series') | ||
| show_parser.add_argument('--sort-by', choices=('seen', 'entity'), default='seen', |
There was a problem hiding this comment.
Maybe name the options age and entity_id?
There was a problem hiding this comment.
age is a good idea. I was trying to avoid using underscored suffixes in an attribute as I think it makes it easier to remember and use, but I can change it if you feel strongly about it.
There was a problem hiding this comment.
You're right about underscore. Is identifier too much of an internal lingo?
There was a problem hiding this comment.
I think it might be - plus the column is headed as "Entity ID" in the resulting table, so I think entity or entityid makes it simpler.
There was a problem hiding this comment.
Though I suppose "entity" is pretty internal, too. Maybe we change the column heading to "Identifier" and make the option the same?
There was a problem hiding this comment.
Any strong feelings on how to proceed? I think I like identifier or series best, and change the name of the column to "Identifier" or "Series ID", respectively.
| show_order = show_parser.add_mutually_exclusive_group(required=False) | ||
| show_order.add_argument('--descending', dest='order', action='store_true', help='Sort in descending order') | ||
| show_order.add_argument('--ascending', dest='order', action='store_false', help='Sort in ascending order') | ||
|
|
There was a problem hiding this comment.
I don't remember what happens if you don't use this group at all. What's the default?
There was a problem hiding this comment.
The default is False (ascending) as set in filter/series.py. But your comment got me thinking, if it's left off, what does options.order end up being? It worked fine in my testing though.
There was a problem hiding this comment.
store_true stores a default of False (and the inverse for store_false). If neither is specified on the command line, order is given the default value of the first add_argument call.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--sort-by', choices=('age', 'entity'), default='age')
order = parser.add_mutually_exclusive_group(required=False)
order.add_argument('--ascending', dest='order', action='store_false')
order.add_argument('--descending', dest='order', action='store_true')
>>> parser.parse_args('--sort-by age'.split())
Namespace(order=True, sort_by='age')
There was a problem hiding this comment.
If i remember correctly, setting a store boolean type of action sets the default to the opposite action. So if your action is store_true the default will be False.
However, since you've got two action on the same dest, the last one added takes precedence, and in this case sets True as the default.
There was a problem hiding this comment.
The first one added takes precedence. I echoed it on the command line without specifying the argument and it was False. I then tried adding a third option, so the order was store_true, store_false, store_true, and it was still False.
flexget/plugins/filter/series.py
Outdated
| episodes = show_episodes(series, session=session) | ||
| seasons = show_seasons(series, session=session) | ||
| return sorted(episodes + seasons, key=lambda e: (e.first_seen or datetime.min, e.identifier)) | ||
| if sort_by == 'entity': |
There was a problem hiding this comment.
Maybe something like this:
if sort_by == 'entity':
key=lambda e: e.identifier
else:
key=lambda e: e.first_seen or datetime.min, e.identifier
return sorted(episodes + seasons, key=key, reverse=reverse)|
This is done right? |
|
Yes sir. |
Motivation for changes:
I want to sort by entity ID.
Detailed changes:
When using the
series showCLI subcommand, you can now specify--sort-by identifierto sort by entity ID (aka season/episode) or--sort-by agefor last seen date (default), and--descendingor--ascendingto specify the sort order.get_all_entitiesnow supports return entities sorted byidentifieror age (default).Renamed 'Entity ID' and 'Latest age' columns in
series showoutput to 'Identifier' and 'Last seen', respectively.