Add '--list-settings' option

This commit is contained in:
Stein Magnus Jodal 2010-08-17 02:34:10 +02:00
parent 61059e7610
commit da184ac896
3 changed files with 31 additions and 2 deletions

View File

@ -33,6 +33,8 @@ greatly improved MPD client support.
- Exit early if not Python >= 2.6, < 3.
- Validate settings at startup and print useful error messages if the settings
has not been updated or anything is misspelled.
- Add command line option :option:`--list-settings` to print the currently
active settings.
- Include Sphinx scripts for building docs, pylintrc, tests and test data in
the packages created by ``setup.py`` for i.e. PyPI.
- MPD frontend:
@ -207,8 +209,8 @@ the established pace of at least a release per month.
- Improvements to MPD protocol handling, making Mopidy work much better with a
group of clients, including ncmpc, MPoD, and Theremin.
- New command line flag ``--dump`` for dumping debug log to ``dump.log`` in the
current directory.
- New command line flag :option:`--dump` for dumping debug log to ``dump.log``
in the current directory.
- New setting :attr:`mopidy.settings.MIXER_ALSA_CONTROL` for forcing what ALSA
control :class:`mopidy.mixers.alsa.AlsaMixer` should use.

View File

@ -13,6 +13,7 @@ from mopidy import get_version, settings, SettingsError
from mopidy.process import CoreProcess
from mopidy.utils import get_class
from mopidy.utils.path import get_or_create_folder
from mopidy.utils.settings import list_settings_optparse_callback
logger = logging.getLogger('mopidy.main')
@ -42,6 +43,9 @@ def _parse_options():
parser.add_option('--dump',
action='store_true', dest='dump',
help='dump debug log to file')
parser.add_option('--list-settings',
action='callback', callback=list_settings_optparse_callback,
help='list current settings')
return parser.parse_args()[0]
def _setup_logging(verbosity_level, dump):

View File

@ -102,3 +102,26 @@ def validate_settings(defaults, settings):
continue
return errors
def list_settings_optparse_callback(*args):
"""
Prints a list of all settings.
Called by optparse when Mopidy is run with the :option:`--list-settings`
option.
"""
from mopidy import settings
errors = settings.get_errors()
lines = []
for (key, value) in sorted(settings.raw_settings.iteritems()):
default_value = settings.default_settings.get(key)
if key.endswith('PASSWORD'):
value = u'********'
lines.append(u'%s:' % key)
lines.append(u' Value: %s' % repr(value))
if value != default_value and default_value is not None:
lines.append(u' Default: %s' % repr(default_value))
if errors.get(key) is not None:
lines.append(u' Error: %s' % errors[key])
print u'Settings: %s' % indent('\n'.join(lines), places=2)
sys.exit(0)