Skip to content

Commit

Permalink
Add console python script
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jan 16, 2015
1 parent 50c55fa commit b0cdb96
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""
Usage -
`python console.py`
(Cmd)help
Autocompletions should work...
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/python-api')

from gstswitch.server import Server
from gstswitch.helpers import *
from gstswitch.controller import Controller
import cmd
import inspect



class Console(cmd.Cmd):

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()
c.establish_connection()
print c.get_compose_port()

def help_get_compose_port(self):
print "Get the Compose Port"

def do_get_encode_port(self, line):
c = Controller()
c.establish_connection()
print c.get_encode_port()

def do_get_audio_port(self, line):
c = Controller()
c.establish_connection()
print c.get_audio_port()

def do_get_preview_ports(self, line):
c = Controller()
c.establish_connection()
print c.get_preview_ports()

def do_set_composite_mode(self, line):
try:
val = self.COMPOSITE_MAPPING[line.lower()]
except KeyError:
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.COMPOSITE_MAPPING]))

def complete_set_composite_mode(self, text, line, begidx, endidx):
return [i for i in self.COMPOSITE_MAPPING if i.startswith(text)]

def do_adjust_pip(self, line):
c = Controller()
c.establish_connection()
if len(line.split()) != 4:
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)]






if __name__ == '__main__':
con = Console()
con.cmdloop()

0 comments on commit b0cdb96

Please sign in to comment.