From ebee9620201ad9609e8b6d6a5322672d4bd52479 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 8 May 2011 01:38:04 +0200 Subject: [PATCH 1/4] Test that --help returns the options we expect it to --- tests/help_test.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/help_test.py diff --git a/tests/help_test.py b/tests/help_test.py new file mode 100644 index 00000000..a64877c6 --- /dev/null +++ b/tests/help_test.py @@ -0,0 +1,19 @@ +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_('--quiet' in output) + self.assert_('--verbose' in output) + self.assert_('--save-debug-log' in output) + self.assert_('--list-settings' in output) From 644c87128b1fef5f5b6568b54d176a192d72eca0 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 8 May 2011 01:41:30 +0200 Subject: [PATCH 2/4] Naive workaround for #95 --- mopidy/core.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mopidy/core.py b/mopidy/core.py index d0f2a668..cd49dfa1 100644 --- a/mopidy/core.py +++ b/mopidy/core.py @@ -1,7 +1,17 @@ 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``. +gstreamer_args = [arg for arg in sys.argv[1:] if arg.startswith('--gst')] +mopidy_args = [arg for arg in sys.argv[1:] if not arg.startswith('--gst')] +sys.argv[1:] = gstreamer_args + from pykka.registry import ActorRegistry from mopidy import get_version, settings, OptionalDependencyError @@ -45,7 +55,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/') From f035ea31ef45e66324e01944be974de60256b79e Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 9 May 2011 23:13:06 +0200 Subject: [PATCH 3/4] Allow GStreamer to process --help-gst --- mopidy/core.py | 6 ++++-- tests/help_test.py | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mopidy/core.py b/mopidy/core.py index cd49dfa1..61a47c4b 100644 --- a/mopidy/core.py +++ b/mopidy/core.py @@ -8,8 +8,10 @@ import time # 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``. -gstreamer_args = [arg for arg in sys.argv[1:] if arg.startswith('--gst')] -mopidy_args = [arg for arg in sys.argv[1:] if not arg.startswith('--gst')] +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 diff --git a/tests/help_test.py b/tests/help_test.py index a64877c6..502673be 100644 --- a/tests/help_test.py +++ b/tests/help_test.py @@ -17,3 +17,10 @@ class HelpTest(unittest.TestCase): 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) From b796661dc1cfd28853cb8bbf24485dbde8972c1a Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Mon, 9 May 2011 23:16:45 +0200 Subject: [PATCH 4/4] List --help-gst in Mopidy's --help listing --- mopidy/core.py | 3 +++ tests/help_test.py | 1 + 2 files changed, 4 insertions(+) diff --git a/mopidy/core.py b/mopidy/core.py index 61a47c4b..e510b698 100644 --- a/mopidy/core.py +++ b/mopidy/core.py @@ -45,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)') diff --git a/tests/help_test.py b/tests/help_test.py index 502673be..dccccc9c 100644 --- a/tests/help_test.py +++ b/tests/help_test.py @@ -13,6 +13,7 @@ class HelpTest(unittest.TestCase): 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)