def read_tasks(config): """A generator yielding all the albums (as ImportTask objects) found 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 if progress: resume_dirs = {} for path in config.paths: resume_dir = progress_get(path) if resume_dir: # Either accept immediately or prompt for input to decide. if config.resume: do_resume = True log.warn('Resuming interrupted import of %s' % path) else: do_resume = config.should_resume_func(config, path) if do_resume: resume_dirs[path] = resume_dir else: # Clear progress; we're starting from the top. progress_set(path, None) for toppath in config.paths: # 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): if progress and resume_dir: # We're fast-forwarding to resume a previous tagging. if path == resume_dir: # We've hit the last good path! Turn off the # fast-forwarding. resume_dir = None continue # Yield all the necessary tasks. if config.singletons: for item in items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(toppath, path) else: yield ImportTask(toppath, path, items) # Indicate the directory is finished. yield ImportTask.done_sentinel(toppath)
def read_tasks(config): """A generator yielding all the albums (as ImportTask objects) found 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 if progress: resume_dirs = {} for path in config.paths: resume_dir = progress_get(path) if resume_dir: # Either accept immediately or prompt for input to decide. if config.resume: do_resume = True log.warn('Resuming interrupted import of %s' % path) else: do_resume = config.should_resume_func(config, path) if do_resume: resume_dirs[path] = resume_dir else: # Clear progress; we're starting from the top. progress_set(path, None) # Look for saved incremental directories. if config.incremental: incremental_skipped = 0 history_dirs = history_get() for toppath in config.paths: # 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, config.ignore): # Skip according to progress. if progress and resume_dir: # We're fast-forwarding to resume a previous tagging. if path == resume_dir: # We've hit the last good path! Turn off the # fast-forwarding. resume_dir = None continue # When incremental, skip paths in the history. if config.incremental and path in history_dirs: log.debug(u'Skipping previously-imported path: %s' % displayable_path(path)) incremental_skipped += 1 continue # Yield all the necessary tasks. if config.singletons: for item in items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(toppath, path) else: yield ImportTask(toppath, path, items) # Indicate the directory is finished. yield ImportTask.done_sentinel(toppath) # Show skipped directories. if config.incremental and incremental_skipped: log.info(u'Incremental import: skipped %i directories.' % incremental_skipped)