Skip to content
Snippets Groups Projects
Commit f77556e3 authored by ptangu01's avatar ptangu01
Browse files

format code style pep8 but not on methods yet

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@1357 b32b6428-25c9-4566-ad07-03861ab6144f
parent aadabc39
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
#
# Copyright 2014, Jérôme Colin, Jérôme Kerdreux, Philippe Tanguy, Telecom Bretagne.
# Copyright 2014, Jérôme Colin, Jérôme Kerdreux, Philippe Tanguy,
# Telecom Bretagne.
#
# This file is part of xAAL.
#
......@@ -37,7 +38,12 @@ logger=logging.getLogger(__name__)
class Engine(object):
def __init__(self,address=config.ADDR,port=config.PORT,hops=config.HOPS,passphrase=config.PASSPHRASE):
def __init__(
self,
address=config.ADDR,
port=config.PORT,
hops=config.HOPS,
passphrase=config.PASSPHRASE):
cipherKey = tools.pass2key(passphrase)
self.__nc = NetworkConnector(address=address, port=port, hops=hops)
self.__mf = MessageFactory(cipherKey)
......@@ -135,7 +141,8 @@ class Engine(object):
break
def upAlive(self, dev):
"""update alive for device dev from the alives list of tuples (dev,aliveTimeout)
"""update alive for device dev from the alives
list of tuples (dev,aliveTimeout)
:param dev: instance of xAAL device
:type dev: Device
"""
......@@ -189,7 +196,8 @@ class Engine(object):
devices[attr.getDevice()][attr.getName()] = attr.getValue()
for dev in devices:
msg = self.__mf.buildMSG(dev,[],"notify","attributesChange",devices[dev])
msg = self.__mf.buildMSG(
dev, [], "notify", "attributesChange", devices[dev])
self.queueTx(msg)
self.__attributesChange = [] # empty array
......@@ -233,7 +241,12 @@ class Engine(object):
try:
result = runAction(msg, target)
if result:
self.sendReply(dev = target,targets = [msg.getSource()], action = msg.getAction(),body=result)
self.sendReply(
dev=target,
targets=[
msg.getSource()],
action=msg.getAction(),
body=result)
except DeviceError as e:
self.sendError(target, e.code, e.description)
except XAALError as e:
......@@ -244,7 +257,11 @@ class Engine(object):
#####################################################
def getBusConfig(self):
nc = self.getNetworkConnector()
return {"address" : nc.getAddr(), "port" : nc.getPort(), "hops": nc.getHops(),"stack_version:": nc.getStackVersion()}
return {
"address": nc.getAddr(),
"port": nc.getPort(),
"hops": nc.getHops(),
"stack_version:": nc.getStackVersion()}
def getCipherKey(self):
return self.getMessageFactory().getCipherKey()
......@@ -279,7 +296,6 @@ class Engine(object):
except CallbackError as e:
logger.error(e.message)
#####################################################
# Mainloops & run ..
#####################################################
......@@ -356,8 +372,10 @@ def filterMsgForDevices(msg,devices):
results.append(dev)
return results
def runAction(msg, device):
"""Extract & run an action (match with exposed method) from a msg on the selected device.
"""Extract & run an action (match with exposed method) from a msg
on the selected device.
Return:
- None
- result from method if method return something
......@@ -375,7 +393,9 @@ def runAction(msg,device):
try:
bodyParams = msg.getParameters(args)
except KeyError as e:
raise XAALError("Wrong method parameter %s for action %s"%(e.message,action))
raise XAALError(
"Wrong method parameter %s for action %s" %
(e.message, action))
for p in range(0, len(args)):
params[args[p]] = bodyParams[args[p]]
......@@ -384,6 +404,7 @@ def runAction(msg,device):
raise XAALError("Method %s not found" % action)
return result
def getArgumentsForMethod(method):
args = inspect.getargspec(method)
try:
......@@ -398,5 +419,3 @@ class CallbackError(Exception):
def __init__(self, code, desc):
self.code = code
self.description = desc
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment