Skip to content

Commit

Permalink
singleton imports can take single-file arguments (beetbox#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed May 6, 2011
1 parent 69f392c commit 3b23198
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -17,6 +17,8 @@
respected in BPD's browsing hierarchy. This may come at a performance
cost, however. The virtual filesystem used by BPD is available for
reuse by plugins (e.g., the FUSE plugin).
* Singleton imports ("beet import -s") can now take individual files as
arguments as well as directories.
* Fix crash when autotagging files with no metadata.
* Fix a rare deadlock when finishing the import pipeline.

Expand Down
11 changes: 9 additions & 2 deletions beets/importer.py
Expand Up @@ -312,7 +312,8 @@ def should_skip(self):

def read_tasks(config):
"""A generator yielding all the albums (as ImportTask objects) found
in the user-specified list of paths.
in the user-specified list of paths. In the case of a singleton
import, yields single-item tasks instead.
"""
# Look for saved progress.
progress = config.resume is not False
Expand All @@ -336,7 +337,13 @@ def read_tasks(config):
progress_set(path, None)

for toppath in config.paths:
# Produce each path.
# Check whether the path is to a file.
if config.singletons and not os.path.isdir(syspath(toppath)):
item = library.Item.from_path(toppath)
yield ImportTask.item_task(item)
continue

# Produce paths under this directory.
if progress:
resume_dir = resume_dirs.get(toppath)
for path, items in autotag.albums_in_dir(toppath):
Expand Down
4 changes: 3 additions & 1 deletion beets/ui/commands.py
Expand Up @@ -417,8 +417,10 @@ def import_files(lib, paths, copy, write, autot, logpath, art, threaded,
"""
# Check the user-specified directories.
for path in paths:
if not os.path.isdir(syspath(path)):
if not singletons and not os.path.isdir(syspath(path)):
raise ui.UserError('not a directory: ' + path)
elif singletons and not os.path.exists(syspath(path)):
raise ui.UserError('no such file: ' + path)

# Check parameter consistency.
if quiet and timid:
Expand Down

0 comments on commit 3b23198

Please sign in to comment.