-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Set field values on the import command line #1881 #2581
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1da972f
implemented `set_field` cli parsing
bartkl 569098a
store_dict parser action now stores unicode, and implementend set_fie…
bartkl 91722ae
added documentation
bartkl b5a8891
implemented error handling for invalid, non-key/value cli argumnets
bartkl c648781
finished tests for set_fields on importer
bartkl 52d5d23
refactoring according to feedback in pull request
bartkl 53d0421
added docstring for set_fields methods
bartkl 2465898
refactoring according to suggestions in pull request
bartkl 762f9ca
revised to fix flake8 warnings
bartkl 2eb4e3d
Merge branch 'master' into master
bartkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,7 +419,7 @@ class ImportTask(BaseImportTask): | |
from the `candidates` list. | ||
|
||
* `find_duplicates()` Returns a list of albums from `lib` with the | ||
same artist and album name as the task. | ||
same artist and album name as the task. | ||
|
||
* `apply_metadata()` Sets the attributes of the items from the | ||
task's `match` attribute. | ||
|
@@ -429,6 +429,9 @@ class ImportTask(BaseImportTask): | |
* `manipulate_files()` Copy, move, and write files depending on the | ||
session configuration. | ||
|
||
* `set_fields()` Sets the fields given at CLI or configuration to | ||
the specified values. | ||
|
||
* `finalize()` Update the import progress and cleanup the file | ||
system. | ||
""" | ||
|
@@ -530,6 +533,19 @@ def remove_duplicates(self, lib): | |
util.prune_dirs(os.path.dirname(item.path), | ||
lib.directory) | ||
|
||
def set_fields(self): | ||
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. A docstring here might be nice to have! (Perhaps even nicer than the summary in the overall "step sequence" in the overall class docstring.) 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. Added! |
||
"""Sets the fields given at CLI or configuration to the specified | ||
values. | ||
""" | ||
for field, view in config['import']['set_fields'].items(): | ||
value = view.get() | ||
log.debug(u'Set field {1}={2} for {0}', | ||
displayable_path(self.paths), | ||
field, | ||
value) | ||
self.album[field] = value | ||
self.album.store() | ||
|
||
def finalize(self, session): | ||
"""Save progress, clean up files, and emit plugin event. | ||
""" | ||
|
@@ -877,6 +893,19 @@ def choose_match(self, session): | |
def reload(self): | ||
self.item.load() | ||
|
||
def set_fields(self): | ||
"""Sets the fields given at CLI or configuration to the specified | ||
values. | ||
""" | ||
for field, view in config['import']['set_fields'].items(): | ||
value = view.get() | ||
log.debug(u'Set field {1}={2} for {0}', | ||
displayable_path(self.paths), | ||
field, | ||
value) | ||
self.item[field] = value | ||
self.item.store() | ||
|
||
|
||
# FIXME The inheritance relationships are inverted. This is why there | ||
# are so many methods which pass. More responsibility should be delegated to | ||
|
@@ -1385,6 +1414,14 @@ def apply_choice(session, task): | |
|
||
task.add(session.lib) | ||
|
||
# If ``set_fields`` is set, set those fields to the | ||
# configured values. | ||
# NOTE: This cannot be done before the ``task.add()`` call above, | ||
# because then the ``ImportTask`` won't have an `album` for which | ||
# it can set the fields. | ||
if config['import']['set_fields']: | ||
task.set_fields() | ||
|
||
|
||
@pipeline.mutator_stage | ||
def plugin_stage(session, func, task): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
removed a redundant space after 'bell: no'