From ece3d7c6ced9b0f917415ae6b1ec3b8dc1d8ca72 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Thu, 8 Jan 2015 17:13:42 +1300 Subject: [PATCH] temp commit --- console.py | 44 ++++++++++++++----- python-api/gstswitch/controller.py | 7 ++- .../tests/integrationtests/test_controller.py | 2 +- .../tests/unittests/test_controller_unit.py | 4 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/console.py b/console.py index 1ad9322..72d33cb 100644 --- a/console.py +++ b/console.py @@ -21,14 +21,20 @@ class Console(cmd.Cmd): - MAPPING = { - 'none': Controller.COMPOSITE_NONE, - 'pip': Controller.COMPOSITE_PIP, - 'dual_preview': Controller.COMPOSITE_DUAL_PREVIEW, - 'preview': Controller.COMPOSITE_DUAL_PREVIEW, - 'equal': Controller.COMPOSITE_DUAL_EQUAL, - 'dual_equal': Controller.COMPOSITE_DUAL_EQUAL - } + COMPOSITE_MAPPING = { + 'none': Controller.COMPOSITE_NONE, + 'pip': Controller.COMPOSITE_PIP, + 'dual_preview': Controller.COMPOSITE_DUAL_PREVIEW, + 'preview': Controller.COMPOSITE_DUAL_PREVIEW, + 'equal': Controller.COMPOSITE_DUAL_EQUAL, + 'dual_equal': Controller.COMPOSITE_DUAL_EQUAL + } + + SWITCH_MAPPING = { + 'video1': Controller.SWITCH_VIDEO_1, + 'video2': Controller.SWITCH_VIDEO_2, + 'audio': Controller.SWITCH_AUDIO + } def do_get_compose_port(self, line): c = Controller() @@ -55,18 +61,18 @@ def do_get_preview_ports(self, line): def do_set_composite_mode(self, line): try: - val = self.MAPPING[line.lower()] + val = self.COMPOSITE_MAPPING[line.lower()] except KeyError: - self.help_set_composite_mode() + print "Invalid" c = Controller() c.establish_connection() print c.set_composite_mode(val) def help_set_composite_mode(self): - print "Valid modes - {0}".format(", ".join([i for i in self.MAPPING])) + print "Valid modes - {0}".format(", ".join([i for i in self.COMPOSITE_MAPPING])) def complete_set_composite_mode(self, text, line, begidx, endidx): - return [i for i in self.MAPPING if i.startswith(text)] + return [i for i in self.COMPOSITE_MAPPING if i.startswith(text)] def do_adjust_pip(self, line): c = Controller() @@ -75,6 +81,20 @@ def do_adjust_pip(self, line): print print c.adjust_pip(*map(int, line.split())) + def do_switch(self, line): + try: + val = self.SWITCH_MAPPING[line.lower()] + except KeyError: + print "Invalid" + c = Controller() + c.establish_connection() + print c.switch(self.SWITCH_MAPPING[line.split()[0]], int(line.split()[1])) + + def complete_switch(self, text, line, begidx, endidx): + return [i for i in self.SWITCH_MAPPING if i.startswith(text)] + + + diff --git a/python-api/gstswitch/controller.py b/python-api/gstswitch/controller.py index 7568fe1..16426f4 100644 --- a/python-api/gstswitch/controller.py +++ b/python-api/gstswitch/controller.py @@ -22,6 +22,9 @@ class Controller(object): COMPOSITE_PIP = 1 COMPOSITE_DUAL_PREVIEW = 2 COMPOSITE_DUAL_EQUAL = 3 + SWITCH_VIDEO_1 = 4 + SWITCH_VIDEO_2 = 98 + SWITCH_AUDIO = 65 def __init__( self, @@ -304,7 +307,9 @@ def switch(self, channel, port): """Switch the channel to the target port :param channel: The channel to be switched: - 'A', 'B', 'a' + SWITCH_VIDEO_1 + SWITCH_VIDEO_2 + SWITCH_AUDIO :param port: The target port number :returns: True when requested """ diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index 4de3810..c9876e4 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -529,7 +529,7 @@ def switch(self, channel, port, index): def test_switch(self): """Test switch""" dic = [ - [65, 3004] + [Controller.SWITCH_VIDEO_1, 3004] ] start = 5 for i in range(start, 6): diff --git a/python-api/tests/unittests/test_controller_unit.py b/python-api/tests/unittests/test_controller_unit.py index e777f34..aa96d7e 100644 --- a/python-api/tests/unittests/test_controller_unit.py +++ b/python-api/tests/unittests/test_controller_unit.py @@ -364,14 +364,14 @@ def test_unpack(self): controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(True) with pytest.raises(ConnectionReturnError): - controller.switch(1, 2) + controller.switch(Controller.SWITCH_VIDEO_1, 2) def test_normal_unpack(self): """Test if valid""" controller = Controller(address='unix:abstract=abcdef') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(False) - assert controller.switch(1, 2) is True + assert controller.switch(Controller.SWITCH_VIDEO_1, 2) is True class TestClickVideo(object):