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:
parent
e82ce6256d
commit
63a8375429
@ -61,7 +61,7 @@ Configuration values
|
|||||||
.. confval:: local/scan_flush_threshold
|
.. confval:: local/scan_flush_threshold
|
||||||
|
|
||||||
Number of tracks to wait before telling library it should try and store
|
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
|
.. confval:: local/excluded_file_extensions
|
||||||
|
|
||||||
|
|||||||
@ -50,9 +50,10 @@ class Library(object):
|
|||||||
"""
|
"""
|
||||||
Local library interface.
|
Local library interface.
|
||||||
|
|
||||||
Extensions that whish to provide an alternate local library storage backend
|
Extensions that wish to provide an alternate local library storage backend
|
||||||
need to sub-class this class and install and confgure it with an extension.
|
need to sub-class this class and install and configure it with an
|
||||||
Both scanning and library calls will use the active local library.
|
extension. Both scanning and library calls will use the active local
|
||||||
|
library.
|
||||||
|
|
||||||
:param config: Config dictionary
|
:param config: Config dictionary
|
||||||
"""
|
"""
|
||||||
@ -133,10 +134,12 @@ class Library(object):
|
|||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"""
|
"""
|
||||||
Called for every n-th track indicating that work should be commited,
|
Called for every n-th track indicating that work should be comitted.
|
||||||
implementors are free to ignore these hints.
|
Sub-classes are free to ignore these hints.
|
||||||
|
|
||||||
|
:rtype: Boolean indicating if state was flushed.
|
||||||
"""
|
"""
|
||||||
pass
|
return False
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -56,8 +56,9 @@ class ScanCommand(commands.Command):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ScanCommand, self).__init__()
|
super(ScanCommand, self).__init__()
|
||||||
self.add_argument('--limit', action='store', type=int, dest='limit',
|
self.add_argument('--limit',
|
||||||
default=0, help='Maxmimum number of tracks to scan')
|
action='store', type=int, dest='limit', default=None,
|
||||||
|
help='Maxmimum number of tracks to scan')
|
||||||
|
|
||||||
def run(self, args, config):
|
def run(self, args, config):
|
||||||
media_dir = config['local']['media_dir']
|
media_dir = config['local']['media_dir']
|
||||||
@ -114,7 +115,7 @@ class ScanCommand(commands.Command):
|
|||||||
total = args.limit or len(uris_to_update)
|
total = args.limit or len(uris_to_update)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
for uri in sorted(uris_to_update)[:args.limit or None]:
|
for uri in sorted(uris_to_update)[:args.limit]:
|
||||||
try:
|
try:
|
||||||
data = scanner.scan(path.path_to_uri(uri_path_mapping[uri]))
|
data = scanner.scan(path.path_to_uri(uri_path_mapping[uri]))
|
||||||
track = scan.audio_data_to_track(data).copy(uri=uri)
|
track = scan.audio_data_to_track(data).copy(uri=uri)
|
||||||
@ -129,6 +130,8 @@ class ScanCommand(commands.Command):
|
|||||||
remainder = duration / count * (total - count)
|
remainder = duration / count * (total - count)
|
||||||
logger.info('Scanned %d of %d files in %ds, ~%ds left.',
|
logger.info('Scanned %d of %d files in %ds, ~%ds left.',
|
||||||
count, total, duration, remainder)
|
count, total, duration, remainder)
|
||||||
|
# TODO: log if flush succeeded
|
||||||
|
# TODO: don't flush when count == total
|
||||||
library.flush()
|
library.flush()
|
||||||
|
|
||||||
library.close()
|
library.close()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user