local: Review comments and library interface update.

Added return value to flush so we can log what is being done.
This commit is contained in:
Thomas Adamcik 2013-12-31 14:57:54 +01:00
parent e82ce6256d
commit 63a8375429
3 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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):
"""

View File

@ -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()