Merge branch 'feature/95-fix-help-command' into develop

This commit is contained in:
Stein Magnus Jodal 2011-05-09 23:25:13 +02:00
commit d605964dce
2 changed files with 43 additions and 1 deletions

View File

@ -1,7 +1,19 @@
import logging
import optparse
import sys
import time
# Extract any non-GStreamer arguments, and leave the GStreamer arguments for
# processing by GStreamer. This needs to be done before GStreamer is imported,
# so that GStreamer doesn't hijack e.g. ``--help``.
# NOTE This naive fix does not support values like ``bar`` in
# ``--gst-foo bar``. Use equals to pass values, like ``--gst-foo=bar``.
def is_gst_arg(arg):
return arg.startswith('--gst') or arg == '--help-gst'
gstreamer_args = [arg for arg in sys.argv[1:] if is_gst_arg(arg)]
mopidy_args = [arg for arg in sys.argv[1:] if not is_gst_arg(arg)]
sys.argv[1:] = gstreamer_args
from pykka.registry import ActorRegistry
from mopidy import get_version, settings, OptionalDependencyError
@ -33,6 +45,9 @@ def main():
def parse_options():
parser = optparse.OptionParser(version=u'Mopidy %s' % get_version())
parser.add_option('--help-gst',
action='store_true', dest='help_gst',
help='show GStreamer help options')
parser.add_option('-q', '--quiet',
action='store_const', const=0, dest='verbosity_level',
help='less output (warning level)')
@ -45,7 +60,7 @@ def parse_options():
parser.add_option('--list-settings',
action='callback', callback=list_settings_optparse_callback,
help='list current settings')
return parser.parse_args()[0]
return parser.parse_args(args=mopidy_args)[0]
def setup_settings():
get_or_create_folder('~/.mopidy/')

27
tests/help_test.py Normal file
View File

@ -0,0 +1,27 @@
import os
import subprocess
import sys
import unittest
import mopidy
class HelpTest(unittest.TestCase):
def test_help_has_mopidy_options(self):
mopidy_dir = os.path.dirname(mopidy.__file__)
args = [sys.executable, mopidy_dir, '--help']
process = subprocess.Popen(args, stdout=subprocess.PIPE)
output = process.communicate()[0]
self.assert_('--version' in output)
self.assert_('--help' in output)
self.assert_('--help-gst' in output)
self.assert_('--quiet' in output)
self.assert_('--verbose' in output)
self.assert_('--save-debug-log' in output)
self.assert_('--list-settings' in output)
def test_help_gst_has_gstreamer_options(self):
mopidy_dir = os.path.dirname(mopidy.__file__)
args = [sys.executable, mopidy_dir, '--help-gst']
process = subprocess.Popen(args, stdout=subprocess.PIPE)
output = process.communicate()[0]
self.assert_('--gst-version' in output)