Scanner: Fix deadlock on incorrectly identified files
This commit is contained in:
parent
608b9c9b6c
commit
3c6a0543f5
@ -18,6 +18,7 @@ class Extension(ext.Extension):
|
||||
|
||||
def get_config_schema(self):
|
||||
schema = super(Extension, self).get_config_schema()
|
||||
schema['scan_timeout'] = config.Integer(minimum=0)
|
||||
schema['media_dir'] = config.Path()
|
||||
schema['playlists_dir'] = config.Path()
|
||||
schema['tag_cache_file'] = config.Path()
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
[local]
|
||||
enabled = true
|
||||
scan_timeout = 1000
|
||||
media_dir = $XDG_MUSIC_DIR
|
||||
playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists
|
||||
tag_cache_file = $XDG_DATA_DIR/mopidy/local/tag_cache
|
||||
|
||||
@ -97,9 +97,14 @@ def main():
|
||||
logging.warning('Failed %s: %s', uri, error)
|
||||
logging.debug('Debug info for %s: %s', uri, debug)
|
||||
|
||||
if not config['local']['scan_timeout']:
|
||||
scan_timeout = 1000
|
||||
else:
|
||||
scan_timeout = config['local']['scan_timeout']
|
||||
|
||||
logging.info('Scanning new and modified tracks.')
|
||||
# TODO: just pass the library in instead?
|
||||
scanner = Scanner(uris_update, store, debug)
|
||||
scanner = Scanner(uris_update, store, debug, scan_timeout)
|
||||
try:
|
||||
scanner.start()
|
||||
except KeyboardInterrupt:
|
||||
@ -176,12 +181,14 @@ def translator(data):
|
||||
|
||||
|
||||
class Scanner(object):
|
||||
def __init__(self, uris, data_callback, error_callback=None):
|
||||
def __init__(self, uris, data_callback, error_callback=None, scan_timeout=1000):
|
||||
self.data = {}
|
||||
self.uris = iter(uris)
|
||||
self.data_callback = data_callback
|
||||
self.error_callback = error_callback
|
||||
self.scan_timeout = scan_timeout
|
||||
self.loop = gobject.MainLoop()
|
||||
self.timeout_id = None
|
||||
|
||||
self.fakesink = gst.element_factory_make('fakesink')
|
||||
self.fakesink.set_property('signal-handoffs', True)
|
||||
@ -252,6 +259,13 @@ class Scanner(object):
|
||||
self.error_callback(uri, error, debug)
|
||||
self.next_uri()
|
||||
|
||||
def process_timeout(self):
|
||||
if self.error_callback:
|
||||
uri = self.uribin.get_property('uri')
|
||||
self.error_callback(uri, 'Processing timeout after %i seconds' % self.timeout, 'debug')
|
||||
self.next_uri()
|
||||
return True
|
||||
|
||||
def get_duration(self):
|
||||
self.pipe.get_state() # Block until state change is done.
|
||||
try:
|
||||
@ -262,6 +276,9 @@ class Scanner(object):
|
||||
|
||||
def next_uri(self):
|
||||
self.data = {}
|
||||
if self.timeout_id:
|
||||
gobject.source_remove(self.timeout_id)
|
||||
self.timeout_id = None
|
||||
try:
|
||||
uri = next(self.uris)
|
||||
except StopIteration:
|
||||
@ -269,6 +286,7 @@ class Scanner(object):
|
||||
return False
|
||||
self.pipe.set_state(gst.STATE_NULL)
|
||||
self.uribin.set_property('uri', uri)
|
||||
self.timeout_id = gobject.timeout_add(self.scan_timeout, self.process_timeout)
|
||||
self.pipe.set_state(gst.STATE_PLAYING)
|
||||
return True
|
||||
|
||||
|
||||
BIN
tests/data/scanner/example.log
Normal file
BIN
tests/data/scanner/example.log
Normal file
Binary file not shown.
@ -210,6 +210,10 @@ class ScannerTest(unittest.TestCase):
|
||||
self.scan('scanner/image')
|
||||
self.assert_(self.errors)
|
||||
|
||||
def test_log_file_is_ignored(self):
|
||||
self.scan('scanner/example.log')
|
||||
self.assert_(self.errors)
|
||||
|
||||
@unittest.SkipTest
|
||||
def test_song_without_time_is_handeled(self):
|
||||
pass
|
||||
|
||||
Loading…
Reference in New Issue
Block a user