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):
|
def get_config_schema(self):
|
||||||
schema = super(Extension, self).get_config_schema()
|
schema = super(Extension, self).get_config_schema()
|
||||||
|
schema['scan_timeout'] = config.Integer(minimum=0)
|
||||||
schema['media_dir'] = config.Path()
|
schema['media_dir'] = config.Path()
|
||||||
schema['playlists_dir'] = config.Path()
|
schema['playlists_dir'] = config.Path()
|
||||||
schema['tag_cache_file'] = config.Path()
|
schema['tag_cache_file'] = config.Path()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
[local]
|
[local]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
scan_timeout = 1000
|
||||||
media_dir = $XDG_MUSIC_DIR
|
media_dir = $XDG_MUSIC_DIR
|
||||||
playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists
|
playlists_dir = $XDG_DATA_DIR/mopidy/local/playlists
|
||||||
tag_cache_file = $XDG_DATA_DIR/mopidy/local/tag_cache
|
tag_cache_file = $XDG_DATA_DIR/mopidy/local/tag_cache
|
||||||
|
|||||||
@ -97,9 +97,14 @@ def main():
|
|||||||
logging.warning('Failed %s: %s', uri, error)
|
logging.warning('Failed %s: %s', uri, error)
|
||||||
logging.debug('Debug info for %s: %s', uri, debug)
|
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.')
|
logging.info('Scanning new and modified tracks.')
|
||||||
# TODO: just pass the library in instead?
|
# TODO: just pass the library in instead?
|
||||||
scanner = Scanner(uris_update, store, debug)
|
scanner = Scanner(uris_update, store, debug, scan_timeout)
|
||||||
try:
|
try:
|
||||||
scanner.start()
|
scanner.start()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@ -176,12 +181,14 @@ def translator(data):
|
|||||||
|
|
||||||
|
|
||||||
class Scanner(object):
|
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.data = {}
|
||||||
self.uris = iter(uris)
|
self.uris = iter(uris)
|
||||||
self.data_callback = data_callback
|
self.data_callback = data_callback
|
||||||
self.error_callback = error_callback
|
self.error_callback = error_callback
|
||||||
|
self.scan_timeout = scan_timeout
|
||||||
self.loop = gobject.MainLoop()
|
self.loop = gobject.MainLoop()
|
||||||
|
self.timeout_id = None
|
||||||
|
|
||||||
self.fakesink = gst.element_factory_make('fakesink')
|
self.fakesink = gst.element_factory_make('fakesink')
|
||||||
self.fakesink.set_property('signal-handoffs', True)
|
self.fakesink.set_property('signal-handoffs', True)
|
||||||
@ -252,6 +259,13 @@ class Scanner(object):
|
|||||||
self.error_callback(uri, error, debug)
|
self.error_callback(uri, error, debug)
|
||||||
self.next_uri()
|
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):
|
def get_duration(self):
|
||||||
self.pipe.get_state() # Block until state change is done.
|
self.pipe.get_state() # Block until state change is done.
|
||||||
try:
|
try:
|
||||||
@ -262,6 +276,9 @@ class Scanner(object):
|
|||||||
|
|
||||||
def next_uri(self):
|
def next_uri(self):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
if self.timeout_id:
|
||||||
|
gobject.source_remove(self.timeout_id)
|
||||||
|
self.timeout_id = None
|
||||||
try:
|
try:
|
||||||
uri = next(self.uris)
|
uri = next(self.uris)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
@ -269,6 +286,7 @@ class Scanner(object):
|
|||||||
return False
|
return False
|
||||||
self.pipe.set_state(gst.STATE_NULL)
|
self.pipe.set_state(gst.STATE_NULL)
|
||||||
self.uribin.set_property('uri', uri)
|
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)
|
self.pipe.set_state(gst.STATE_PLAYING)
|
||||||
return True
|
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.scan('scanner/image')
|
||||||
self.assert_(self.errors)
|
self.assert_(self.errors)
|
||||||
|
|
||||||
|
def test_log_file_is_ignored(self):
|
||||||
|
self.scan('scanner/example.log')
|
||||||
|
self.assert_(self.errors)
|
||||||
|
|
||||||
@unittest.SkipTest
|
@unittest.SkipTest
|
||||||
def test_song_without_time_is_handeled(self):
|
def test_song_without_time_is_handeled(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user