Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jan 8, 2015
1 parent 37ee270 commit ece3d7c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
44 changes: 32 additions & 12 deletions console.py
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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)]






Expand Down
7 changes: 6 additions & 1 deletion python-api/gstswitch/controller.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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
"""
Expand Down
2 changes: 1 addition & 1 deletion python-api/tests/integrationtests/test_controller.py
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions python-api/tests/unittests/test_controller_unit.py
Expand Up @@ -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):
Expand Down

0 comments on commit ece3d7c

Please sign in to comment.