coding style: adopt pep8
Change-Id: Ic037f925271c970406284e52a00a6c56d048452e
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import fileinput
|
import fileinput
|
||||||
|
|
||||||
|
|
||||||
class LineHandler():
|
class LineHandler():
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -14,6 +15,7 @@ class LineHandler():
|
|||||||
'''
|
'''
|
||||||
self.send_line("> " + line)
|
self.send_line("> " + line)
|
||||||
|
|
||||||
|
|
||||||
class LineServer():
|
class LineServer():
|
||||||
|
|
||||||
def __init__(self, isfile, lineHandlerClass):
|
def __init__(self, isfile, lineHandlerClass):
|
||||||
|
@ -33,26 +33,37 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
class SecopError(Exception):
|
class SecopError(Exception):
|
||||||
|
|
||||||
def __init__(self, message, text):
|
def __init__(self, message, text):
|
||||||
Exception.__init__(self, message, text)
|
Exception.__init__(self, message, text)
|
||||||
|
|
||||||
|
|
||||||
class UnknownDeviceError(SecopError):
|
class UnknownDeviceError(SecopError):
|
||||||
|
|
||||||
def __init__(self, message, args):
|
def __init__(self, message, args):
|
||||||
SecopError.__init__(self, "NoSuchDevice", args[0])
|
SecopError.__init__(self, "NoSuchDevice", args[0])
|
||||||
|
|
||||||
|
|
||||||
class UnknownParamError(SecopError):
|
class UnknownParamError(SecopError):
|
||||||
|
|
||||||
def __init__(self, message, args):
|
def __init__(self, message, args):
|
||||||
SecopError.__init__(self, "NoSuchParam", "%s:%s" % args)
|
SecopError.__init__(self, "NoSuchParam", "%s:%s" % args)
|
||||||
|
|
||||||
|
|
||||||
class UnknownPropError(SecopError):
|
class UnknownPropError(SecopError):
|
||||||
|
|
||||||
def __init__(self, message, args):
|
def __init__(self, message, args):
|
||||||
SecopError.__init__(self, "NoSuchProperty", "%s:%s:%s" % args)
|
SecopError.__init__(self, "NoSuchProperty", "%s:%s:%s" % args)
|
||||||
|
|
||||||
|
|
||||||
class SyntaxError(SecopError):
|
class SyntaxError(SecopError):
|
||||||
|
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
SecopError.__init__(self, "SyntaxError", message)
|
SecopError.__init__(self, "SyntaxError", message)
|
||||||
|
|
||||||
|
|
||||||
class OtherError(SecopError):
|
class OtherError(SecopError):
|
||||||
|
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
SecopError.__init__(self, "OtherError", message)
|
SecopError.__init__(self, "OtherError", message)
|
||||||
|
|
||||||
@ -64,12 +75,14 @@ def encode(input):
|
|||||||
return enc
|
return enc
|
||||||
return inp
|
return inp
|
||||||
|
|
||||||
|
|
||||||
def gettype(obj):
|
def gettype(obj):
|
||||||
typ = str(type(obj).__name__)
|
typ = str(type(obj).__name__)
|
||||||
if typ == "unicode":
|
if typ == "unicode":
|
||||||
typ = "string"
|
typ = "string"
|
||||||
return typ
|
return typ
|
||||||
|
|
||||||
|
|
||||||
def wildcard(dictionary, pattern):
|
def wildcard(dictionary, pattern):
|
||||||
list = []
|
list = []
|
||||||
if pattern == "":
|
if pattern == "":
|
||||||
@ -89,11 +102,14 @@ def wildcard(dictionary, pattern):
|
|||||||
|
|
||||||
|
|
||||||
class SecopClientProps(object):
|
class SecopClientProps(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.reply_items = {".": "t", "writable": 1}
|
self.reply_items = {".": "t", "writable": 1}
|
||||||
self.compact_output = {".": 0, "writable": 1}
|
self.compact_output = {".": 0, "writable": 1}
|
||||||
|
|
||||||
|
|
||||||
class SecopLineHandler(lineserver.LineHandler):
|
class SecopLineHandler(lineserver.LineHandler):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
lineserver.LineHandler.__init__(self, *args, **kwargs)
|
lineserver.LineHandler.__init__(self, *args, **kwargs)
|
||||||
self.props = SecopClientProps()
|
self.props = SecopClientProps()
|
||||||
@ -118,7 +134,6 @@ class SecopLineHandler(lineserver.LineHandler):
|
|||||||
self.send_line("~%s~ %s" % (e.args[0], e.args[1]))
|
self.send_line("~%s~ %s" % (e.args[0], e.args[1]))
|
||||||
self.send_line("")
|
self.send_line("")
|
||||||
|
|
||||||
|
|
||||||
def get_device(self, d):
|
def get_device(self, d):
|
||||||
if d == "":
|
if d == "":
|
||||||
d = "."
|
d = "."
|
||||||
@ -193,11 +208,12 @@ class SecopLineHandler(lineserver.LineHandler):
|
|||||||
try:
|
try:
|
||||||
val = (typ)(value)
|
val = (typ)(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise SyntaxError("can not convert '%s' to %s" % (value, gettype(value)))
|
raise SyntaxError("can not convert '%s' to %s" %
|
||||||
|
(value, gettype(value)))
|
||||||
parDict["."] = val
|
parDict["."] = val
|
||||||
parDict["t"] = datetime.utcnow()
|
parDict["t"] = datetime.utcnow()
|
||||||
self.send_line(self.output_path(d, p, ".") + "=" + encode(parDict["."]))
|
self.send_line(self.output_path(d, p, ".") +
|
||||||
|
"=" + encode(parDict["."]))
|
||||||
|
|
||||||
def read(self, pathArg):
|
def read(self, pathArg):
|
||||||
self.clear_output_path()
|
self.clear_output_path()
|
||||||
@ -240,7 +256,8 @@ class SecopLineHandler(lineserver.LineHandler):
|
|||||||
if path[2] == "":
|
if path[2] == "":
|
||||||
msg = self.output_path(d, p, "") + "=" + encode(paramDict["."])
|
msg = self.output_path(d, p, "") + "=" + encode(paramDict["."])
|
||||||
for y in replyitems:
|
for y in replyitems:
|
||||||
if y == ".": continue # do not show the value twice
|
if y == ".":
|
||||||
|
continue # do not show the value twice
|
||||||
try:
|
try:
|
||||||
msg += ";" + y + "=" + encode(paramDict[y])
|
msg += ";" + y + "=" + encode(paramDict[y])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -296,7 +313,8 @@ else:
|
|||||||
server = lineserver.LineServer("localhost", port, SecopLineHandler)
|
server = lineserver.LineServer("localhost", port, SecopLineHandler)
|
||||||
|
|
||||||
|
|
||||||
secNodeDict=json.load(open("secnode.json", "r"), object_pairs_hook=OrderedDict)
|
secNodeDict = json.load(open("secnode.json", "r"),
|
||||||
|
object_pairs_hook=OrderedDict)
|
||||||
#json.dump(secNodeDict, open("secnode_out.json", "w"), indent=2, separators=(",",":"))
|
#json.dump(secNodeDict, open("secnode_out.json", "w"), indent=2, separators=(",",":"))
|
||||||
for d in secNodeDict:
|
for d in secNodeDict:
|
||||||
devDict = secNodeDict[d]
|
devDict = secNodeDict[d]
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import asyncore
|
import asyncore
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
|
||||||
class LineHandler(asyncore.dispatcher_with_send):
|
class LineHandler(asyncore.dispatcher_with_send):
|
||||||
|
|
||||||
def __init__(self, sock):
|
def __init__(self, sock):
|
||||||
@ -34,6 +35,7 @@ class LineHandler(asyncore.dispatcher_with_send):
|
|||||||
'''
|
'''
|
||||||
self.send_line("> " + line)
|
self.send_line("> " + line)
|
||||||
|
|
||||||
|
|
||||||
class LineServer(asyncore.dispatcher):
|
class LineServer(asyncore.dispatcher):
|
||||||
|
|
||||||
def __init__(self, host, port, lineHandlerClass):
|
def __init__(self, host, port, lineHandlerClass):
|
||||||
|
@ -72,5 +72,3 @@ class Temp(Driveable):
|
|||||||
|
|
||||||
def write_target(self, target):
|
def write_target(self, target):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,5 +212,3 @@ class HelpRequest(Request):
|
|||||||
|
|
||||||
class HelpReply(Reply):
|
class HelpReply(Reply):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user