diff --git a/MkpWIFI/protocol.py b/MkpWIFI/protocol.py index 099a65e..0ee5b01 100644 --- a/MkpWIFI/protocol.py +++ b/MkpWIFI/protocol.py @@ -5,15 +5,18 @@ Created on Fri Sep 27 14:35:31 2019 @author: Guido Longoni - guidolongoni@gmail.com """ - import commands as cmd +import types +import copy import functools import re - def cmdString(cmdName, **cmdArgs): cmdDict = cmd.MKPcommands[cmdName] - mandatory_args = set(cmdDict['args']) + if 'args' in cmdDict and cmdDict['args'] is not None: + mandatory_args = set(cmdDict['args']) + else: + mandatory_args = set() if 'optArgs' in cmdDict and cmdDict['optArgs'] is not None: optional_args = set(cmdDict['optArgs']) else: @@ -34,7 +37,6 @@ def cmdString(cmdName, **cmdArgs): + str(cmd.DEFprefix['end'] if cmdDict['defPrefix'] else cmdDict['end']) - def checkResponse(cmdName, response): sucKey = 'success' cmdDict = cmd.MKPcommands[cmdName] @@ -57,7 +59,6 @@ def checkResponse(cmdName, response): error = checkError(cmdName, response) return error - def checkError(cmdName, response): errKey = 'error' cmdDict = cmd.MKPcommands[cmdName] @@ -68,5 +69,10 @@ def checkError(cmdName, response): return error_codes.groups() return None +cloneFcn = lambda f1,f2: types.FunctionType(copy.copy(f1.__code__), copy.copy(f1.__globals__), name=f2, argdefs=copy.copy(f1.__defaults__), closure=copy.copy(f1.__closure__)) +for k in cmd.MKPcommands.keys(): + setattr(cmd, '_'+k, functools.partial(cloneFcn(cmdString,k),k)) + #globals()[k] = functools.partial(cloneFcn(cmdString,k),k) -testala=cmdString('callPrintImage',imageName='Pippus',printMode='10',fieldContent='qualcosa\rqualcosaltro\rciao') + +testala=cmd._callPrintImage(imageName='Pippus',printMode='10',fieldContent='qualcosa\rqualcosaltro\rciao') \ No newline at end of file