From 3b231983242d9f34b4d5ee4b46c2446c8ebc4711 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 6 May 2011 12:27:03 -0700 Subject: [PATCH] singleton imports can take single-file arguments (#184) --- NEWS | 2 ++ beets/importer.py | 11 +++++++++-- beets/ui/commands.py | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 5c825d215..85a901f85 100644 --- a/NEWS +++ b/NEWS @@ -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. diff --git a/beets/importer.py b/beets/importer.py index 06c193f91..413e933bf 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -312,7 +312,8 @@ class ImportTask(object): 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 @@ -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): diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 868c73480..22b79df53 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -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: