Skip to content

Commit

Permalink
lint and docs - controller.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Sep 3, 2013
1 parent b5fc7ef commit 808797d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
2 changes: 1 addition & 1 deletion python-api/.pylintrc
Expand Up @@ -220,7 +220,7 @@ max-statements=50
max-parents=7

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=20

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
Expand Down
3 changes: 3 additions & 0 deletions python-api/gstswitch/__init__.py
@@ -0,0 +1,3 @@
"""
Python API for gst-switch
"""
91 changes: 62 additions & 29 deletions python-api/gstswitch/controller.py
@@ -1,11 +1,17 @@
#IMPORTS
"""
The controller is the interface for all remote method calls over dbus.
The Controller class creates the controller,
which can be used to invoke the remote methods.
"""

import ast
from connection import Connection
from exception import ConnectionReturnError
from ..gstswitch.connection import Connection
from ..gstswitch.exception import ConnectionReturnError

__all__ = ["Controller", ]



class Controller(object):
"""A Class to control all interactions with the gst-switch-srv over dbus.
Provides the interface for higher level interactions
Expand All @@ -20,13 +26,23 @@ def __init__(
default_interface="info.duzy.gst.switch.SwitchControllerInterface"):

super(Controller, self).__init__()

self._address = None
self._bus_name = None
self._object_path = None
self._default_interface = None
self.connection = None

self.address = address
self.bus_name = bus_name
self.object_path = object_path
self.default_interface = default_interface

@property
def address(self):
"""
Get the address
"""
return self._address

@address.setter
Expand All @@ -47,6 +63,8 @@ def address(self, address):

@property
def bus_name(self):
"""Get the bus name
"""
if self._bus_name is None:
return None
return self._bus_name
Expand All @@ -64,6 +82,8 @@ def bus_name(self, bus_name):

@property
def object_path(self):
"""Get the object path
"""
return self._object_path

@object_path.setter
Expand All @@ -86,6 +106,8 @@ def object_path(self, object_path):

@property
def default_interface(self):
"""Get the default interface
"""
return self._default_interface

@default_interface.setter
Expand Down Expand Up @@ -132,7 +154,8 @@ def get_compose_port(self):
compose_port = conn.unpack()[0]
return compose_port
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values.'
'Should return a GVariant tuple')

def get_encode_port(self):
"""Get the encode port number
Expand All @@ -145,7 +168,8 @@ def get_encode_port(self):
encode_port = conn.unpack()[0]
return encode_port
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values.'
' Should return a GVariant tuple')

def get_audio_port(self):
"""Get the audio port number
Expand All @@ -158,7 +182,8 @@ def get_audio_port(self):
audio_port = conn.unpack()[0]
return audio_port
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')

def get_preview_ports(self):
"""Get all the preview ports
Expand All @@ -169,10 +194,11 @@ def get_preview_ports(self):
conn = self.connection.get_preview_ports()
try:
res = conn.unpack()[0]
preview_ports = self._parse_preview_ports(res)
preview_ports = parse_preview_ports(res)
return preview_ports
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')

def set_composite_mode(self, mode):
"""Set the current composite mode. Modes between 0 and 3 are allowed.
Expand All @@ -190,7 +216,8 @@ def set_composite_mode(self, mode):
if res is True:
print "Set composite mode to %s" % (str(mode))
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid '
'values. Should return a GVariant tuple')
else:
pass
# raise some Exception
Expand All @@ -214,7 +241,8 @@ def set_encode_mode(self, channel):
# raise some exception
return res
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')

def new_record(self):
"""Start a new recording
Expand All @@ -231,7 +259,8 @@ def new_record(self):
else:
pass
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')
return res

def adjust_pip(self, xpos, ypos, width, height):
Expand All @@ -247,10 +276,11 @@ def adjust_pip(self, xpos, ypos, width, height):
try:
conn = self.connection.adjust_pip(xpos, ypos, width, height)
res = conn.unpack()[0]
print "adjust pip xpos:%s ypos:%s w:%s h:%s" % (str(xpos), str(ypos),
str(width), str(height))
print "adjust pip xpos:%s ypos:%s w:%s h:%s" % (
str(xpos), str(ypos), str(width), str(height))
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')
#to-do - parse
return res

Expand All @@ -271,7 +301,8 @@ def switch(self, channel, port):
pass
return res
except AttributeError:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')

def click_video(self, xpos, ypos, width, height):
"""User click on the video
Expand All @@ -287,12 +318,13 @@ def click_video(self, xpos, ypos, width, height):
conn = self.connection.click_video(xpos, ypos, width, height)
res = conn.unpack()[0]
if res is True:
print "Click video: xpos:%s ypos:%s width:%s height:%s" % (str(xpos), str(ypos),
str(width), str(height))
print "Click video: xpos:%s ypos:%s width:%s height:%s" % (
str(xpos), str(ypos), str(width), str(height))
else:
pass
except:
raise ConnectionReturnError('Connection returned invalid values. Should return a GVariant tuple')
raise ConnectionReturnError('Connection returned invalid values. '
'Should return a GVariant tuple')
return res

def mark_face(self, faces):
Expand All @@ -314,14 +346,15 @@ def mark_tracking(self, faces):
self.establish_connection()
self.connection.mark_tracking(faces)

def _parse_preview_ports(self, res):
"""Parses the preview_ports string"""
# res = '[(a, b, c), (a, b, c)*]'
try:
liststr = ast.literal_eval(res)
except (ValueError, SyntaxError):
raise ConnectionReturnError("Connection returned invalid values: {0}".format(res))
preview_ports = []
for tupl in liststr:
preview_ports.append(int(tupl[0]))
return preview_ports
def parse_preview_ports(res):
"""Parses the preview_ports string"""
# res = '[(a, b, c), (a, b, c)*]'
try:
liststr = ast.literal_eval(res)
except (ValueError, SyntaxError):
raise ConnectionReturnError("Connection returned invalid values:{0}"
.format(res))
preview_ports = []
for tupl in liststr:
preview_ports.append(int(tupl[0]))
return preview_ports

0 comments on commit 808797d

Please sign in to comment.