From 63a83754294de8f4d0ac4d5c8a862bdbf8555818 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 31 Dec 2013 14:57:54 +0100 Subject: [PATCH] local: Review comments and library interface update. Added return value to flush so we can log what is being done. --- docs/ext/local.rst | 2 +- mopidy/backends/local/__init__.py | 15 +++++++++------ mopidy/backends/local/commands.py | 9 ++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/ext/local.rst b/docs/ext/local.rst index 4484ab0d..135a486b 100644 --- a/docs/ext/local.rst +++ b/docs/ext/local.rst @@ -61,7 +61,7 @@ Configuration values .. confval:: local/scan_flush_threshold Number of tracks to wait before telling library it should try and store - it's progress so far. Some libraries might not respect this setting. + its progress so far. Some libraries might not respect this setting. .. confval:: local/excluded_file_extensions diff --git a/mopidy/backends/local/__init__.py b/mopidy/backends/local/__init__.py index 6697d91d..d16eddfb 100644 --- a/mopidy/backends/local/__init__.py +++ b/mopidy/backends/local/__init__.py @@ -50,9 +50,10 @@ class Library(object): """ Local library interface. - Extensions that whish to provide an alternate local library storage backend - need to sub-class this class and install and confgure it with an extension. - Both scanning and library calls will use the active local library. + Extensions that wish to provide an alternate local library storage backend + need to sub-class this class and install and configure it with an + extension. Both scanning and library calls will use the active local + library. :param config: Config dictionary """ @@ -133,10 +134,12 @@ class Library(object): def flush(self): """ - Called for every n-th track indicating that work should be commited, - implementors are free to ignore these hints. + Called for every n-th track indicating that work should be comitted. + Sub-classes are free to ignore these hints. + + :rtype: Boolean indicating if state was flushed. """ - pass + return False def close(self): """ diff --git a/mopidy/backends/local/commands.py b/mopidy/backends/local/commands.py index e4075fc5..9dff43d5 100644 --- a/mopidy/backends/local/commands.py +++ b/mopidy/backends/local/commands.py @@ -56,8 +56,9 @@ class ScanCommand(commands.Command): def __init__(self): super(ScanCommand, self).__init__() - self.add_argument('--limit', action='store', type=int, dest='limit', - default=0, help='Maxmimum number of tracks to scan') + self.add_argument('--limit', + action='store', type=int, dest='limit', default=None, + help='Maxmimum number of tracks to scan') def run(self, args, config): media_dir = config['local']['media_dir'] @@ -114,7 +115,7 @@ class ScanCommand(commands.Command): total = args.limit or len(uris_to_update) start = time.time() - for uri in sorted(uris_to_update)[:args.limit or None]: + for uri in sorted(uris_to_update)[:args.limit]: try: data = scanner.scan(path.path_to_uri(uri_path_mapping[uri])) track = scan.audio_data_to_track(data).copy(uri=uri) @@ -129,6 +130,8 @@ class ScanCommand(commands.Command): remainder = duration / count * (total - count) logger.info('Scanned %d of %d files in %ds, ~%ds left.', count, total, duration, remainder) + # TODO: log if flush succeeded + # TODO: don't flush when count == total library.flush() library.close()