-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Selective field updates #2231
Selective field updates #2231
Conversation
@@ -1190,6 +1196,10 @@ def update_func(lib, opts, args): | |||
u'-p', u'--pretend', action='store_true', | |||
help=u"show all changes but do nothing" | |||
) | |||
update_cmd.parser.add_option( | |||
u'-F', u'--field', default=None, action='append', dest='fields', |
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.
I use -F
here instead of -f
since the latter is already used by optparse for custom path formatting. If you want it to be something else, I'd be cool with it.
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.
-F
seems like a great spelling! Thanks for adding to the docs and tests. ✨
I have a couple of cosmetic suggestions and one substantive one: I'm not sure we need the new parameter to the move
method.
@@ -342,15 +342,17 @@ def __delattr__(self, key): | |||
|
|||
# Database interaction (CRUD methods). | |||
|
|||
def store(self): | |||
def store(self, fields_to_store=None): | |||
"""Save the object's metadata into the library database. | |||
""" |
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.
This is just cosmetic, but I would prefer to use (a) a simpler parameter name like fields
and (b) documentation in the docstring here to explain exactly what it does.
"""Save the object's metadata into the library database. | ||
""" | ||
self._check_db() | ||
|
||
# Build assignments for query. | ||
assignments = [] | ||
subvars = [] | ||
for key in self._fields: | ||
if fields_to_store is None: | ||
fields_to_store = self._fields |
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.
This is again just cosmetic, but I like to put these default-value if
blocks to the very top of the function to make it clear what the default values are.
def store(self): | ||
super(LibModel, self).store() | ||
def store(self, fields_to_store=None): | ||
super(LibModel, self).store(fields_to_store) |
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.
(The parameter name should be consistent with the above, if it changes.)
@@ -729,7 +729,8 @@ def remove(self, delete=False, with_album=True): | |||
|
|||
self._db._memotable = {} | |||
|
|||
def move(self, copy=False, link=False, basedir=None, with_album=True): | |||
def move(self, copy=False, link=False, basedir=None, with_album=True, | |||
fields_to_store=None): |
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.
I'm not sure move
needs the new parameter—it's a little unintuitive for clients, and the only reason we store here is to update the paths for files.
@@ -1000,7 +1001,7 @@ def move_art(self, copy=False, link=False): | |||
util.prune_dirs(os.path.dirname(old_art), | |||
self._db.directory) | |||
|
|||
def move(self, copy=False, link=False, basedir=None): | |||
def move(self, copy=False, link=False, basedir=None, fields_to_store=None): |
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.
(As above.)
@@ -1108,7 +1110,7 @@ def set_art(self, path, copy=True): | |||
|
|||
plugins.send('art_set', album=self) | |||
|
|||
def store(self): | |||
def store(self, fields_to_store=None): | |||
"""Update the database with the album information. The album's | |||
tracks are also updated. | |||
""" |
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.
(This probably also needs the name change and docstring expansion.)
@@ -1081,11 +1081,16 @@ def list_func(lib, opts, args): | |||
|
|||
# update: Update library contents according to on-disk tags. | |||
|
|||
def update_items(lib, query, album, move, pretend): | |||
def update_items(lib, query, album, move, pretend, fields): | |||
"""For all the items matched by the query, update the library to | |||
reflect the item's embedded tags. |
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.
fields
needs a mention in the docstring.
if move and fields is not None and 'path' not in fields: | ||
# Special case: if an item needs to be moved, the path field has to | ||
# updated; otherwise the new path will not be reflected in the | ||
# database |
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.
Missing a period in this comment.
|
||
# Save changes. | ||
if not pretend: | ||
if changed: | ||
# Move the item if it's in the library. | ||
if move and lib.directory in ancestry(item.path): | ||
item.move() | ||
item.move(fields_to_store=fields) |
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.
Because we're about to call item.store
, maybe the right thing to do here is just to disable the redundant store to the database inside item.move
.
I've pushed a fix for the small cosmetic changes you asked for. The Thoughts? |
Fantastic; thank you! I think the Nice work! ✨ |
PR to fix #2229