Chance type of core.restore_state config value

Change to boolean to simplify the user configuration.
This commit is contained in:
Jens Luetjen 2016-02-06 15:48:43 +01:00
parent df55c3ebd9
commit 9d8034869d
5 changed files with 10 additions and 61 deletions

View File

@ -113,21 +113,13 @@ Core config section
.. confval:: core/restore_state
Restore last state at start. Defaults to ``off``.
When set to ``true``, Mopidy saves the state when it ends and
restores the state at next start.
Save state when Mopidy ends and restore state at next start.
Allowed values:
- ``off``: restore nothing
- ``volume``: restore volume
- ``load``: restore settings, volume and play queue
- ``last``: like ``load``, additional start playback if last state was
'playing'
- ``play``: like ``load``, additional start playback
Default is ``false``.
.. _audio-config:
Audio configuration
===================

View File

@ -21,8 +21,7 @@ _core_schema['config_dir'] = Path()
_core_schema['data_dir'] = Path()
# MPD supports at most 10k tracks, some clients segfault when this is exceeded.
_core_schema['max_tracklist_length'] = Integer(minimum=1, maximum=10000)
_core_schema['restore_state'] = String(
optional=True, choices=['off', 'volume', 'load', 'last', 'play'])
_core_schema['restore_state'] = Boolean(optional=True)
_logging_schema = ConfigSchema('logging')
_logging_schema['color'] = Boolean()

View File

@ -3,7 +3,7 @@ cache_dir = $XDG_CACHE_DIR/mopidy
config_dir = $XDG_CONFIG_DIR/mopidy
data_dir = $XDG_DATA_DIR/mopidy
max_tracklist_length = 10000
restore_state = off
restore_state = false
[logging]
color = true

View File

@ -145,8 +145,9 @@ class Core(
try:
coverage = []
if self._config and 'restore_state' in self._config['core']:
coverage = self._config_to_coverage(
self._config['core']['restore_state'])
if self._config['core']['restore_state']:
coverage = ['tracklist', 'mode', 'play-last', 'volume',
'history']
if len(coverage):
self._load_state(coverage)
except Exception as e:
@ -156,32 +157,11 @@ class Core(
""" Do not call this function. It is for internal use at shutdown."""
try:
if self._config and 'restore_state' in self._config['core']:
amount = self._config['core']['restore_state']
if amount and 'off' != amount:
if self._config['core']['restore_state']:
self._save_state()
except Exception as e:
logger.warn('Unexpected error while saving state: %s', str(e))
@staticmethod
def _config_to_coverage(value):
coverage = []
if not value or 'off' == value:
pass
elif 'volume' == value:
coverage = ['volume']
elif 'load' == value:
coverage = ['tracklist', 'mode', 'volume', 'history']
elif 'last' == value:
coverage = ['tracklist', 'mode', 'play-last', 'volume',
'history']
elif 'play' == value:
coverage = ['tracklist', 'mode', 'play-always', 'volume',
'history']
else:
logger.warn('Unknown value for config '
'core.restore_state: %s', value)
return coverage
def _get_data_dir(self):
# get or create data director for core
data_dir_path = bytes(

View File

@ -54,7 +54,7 @@ class CoreActorExportRestoreTest(unittest.TestCase):
config = {
'core': {
'max_tracklist_length': 10000,
'restore_state': 'last',
'restore_state': True,
'data_dir': self.temp_dir,
}
}
@ -73,25 +73,3 @@ class CoreActorExportRestoreTest(unittest.TestCase):
def test_restore_state(self):
self.core.setup()
# TODO: implement meaningful test
def test_export_coverage_none(self):
result = Core._config_to_coverage(None)
self.assertEqual(result, [])
result = Core._config_to_coverage('off')
self.assertEqual(result, [])
def test_export_coverage(self):
result = Core._config_to_coverage('volume')
self.assertEqual(result, ['volume'])
result = Core._config_to_coverage('load')
target = ['tracklist', 'mode', 'volume', 'history']
self.assertEqual(result, target)
result = Core._config_to_coverage('last')
target = ['tracklist', 'mode', 'play-last', 'volume', 'history']
self.assertEqual(result, target)
result = Core._config_to_coverage('play')
target = ['tracklist', 'mode', 'play-always', 'volume', 'history']
self.assertEqual(result, target)