From da184ac896831bc67f58a696484488c147634a8f Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Tue, 17 Aug 2010 02:34:10 +0200 Subject: [PATCH] Add '--list-settings' option --- docs/changes.rst | 6 ++++-- mopidy/__main__.py | 4 ++++ mopidy/utils/settings.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 9f5efa84..341ef850 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -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. diff --git a/mopidy/__main__.py b/mopidy/__main__.py index 1ea05d1f..a2230180 100644 --- a/mopidy/__main__.py +++ b/mopidy/__main__.py @@ -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): diff --git a/mopidy/utils/settings.py b/mopidy/utils/settings.py index b478e67e..34457f05 100644 --- a/mopidy/utils/settings.py +++ b/mopidy/utils/settings.py @@ -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)