Bugfix quasi terminato

master
Guido Longoni 2019-09-27 18:55:52 +02:00
parent 4df4253e61
commit 92bc86c48b
2 changed files with 75 additions and 66 deletions

View File

@ -44,7 +44,7 @@ MKPcommands = {
'defPrefix': False, 'defPrefix': False,
'begin': '\x02', # STX 'begin': '\x02', # STX
'end': '\x03', # ETX 'end': '\x03', # ETX
'command': 'TZ{imagename};{printMode};{queueNo};{delay}\r{fieldContent}\r{counterStart}', 'command': 'TZ{imageName};{printMode};{queueNo};{delay}\r{fieldContent}\r{counterStart}',
'success': '\x06\x02([0-9])OK\x03', 'success': '\x06\x02([0-9])OK\x03',
'error': '([0-9])E([0-9])', 'error': '([0-9])E([0-9])',
'args': ['imageName', 'printMode', 'fieldContent'], 'args': ['imageName', 'printMode', 'fieldContent'],

View File

@ -13,17 +13,23 @@ import re
def cmdString(cmdName, **cmdArgs): def cmdString(cmdName, **cmdArgs):
cmdDict = cmd.MKPcommands[cmdName] cmdDict = cmd.MKPcommands[cmdName]
mandatory_args = set(cmdDict['args']) mandatory_args = set(cmdDict['args'])
optional_args = set(cmdDict['optargs']) if 'optArgs' in cmdDict and cmdDict['optArgs'] is not None:
optional_args = set(cmdDict['optArgs'])
else:
optional_args = set()
my_args = set(cmdArgs.keys()) my_args = set(cmdArgs.keys())
if my_args.intersection(mandatory_args) != my_args: if len(my_args) < len(mandatory_args) or my_args.intersection(mandatory_args) != my_args:
raise ValueError('Argomenti obbligatori errati o mancanti.') raise ValueError('Argomenti obbligatori errati o mancanti.')
if len(my_args-mandatory_args-optional_args) > 0: if len(my_args-mandatory_args-optional_args) > 0:
raise Warning('Forniti argomenti sconosciuti!') raise Warning('Forniti argomenti sconosciuti!')
argDict = {**{a: cmdArgs[a] for a in mandatory_args} argDict = { ** { a: cmdArgs[a] for a in mandatory_args},
** {a: cmdArgs[a] if a in my_args else '' for a in optional_args} ** { a: cmdArgs[a] if a in my_args else '' for a in optional_args} }
}
arg_groups = [i.group(1) for i in re.finditer(r'[^;]((\{[^}]*\};)+\{[^}]*\})[^;]',cmd.MKPcommands[cmdName]['command'])]
replacements = [(g,';'.join([a.format(**argDict) for a in g.split(';') if len(a.format(**argDict)) > 0])) for g in arg_groups]
return str(cmd.DEFprefix['begin'] if cmdDict['defPrefix'] else cmdDict['begin']) \ return str(cmd.DEFprefix['begin'] if cmdDict['defPrefix'] else cmdDict['begin']) \
+ re.sub(r';+', ';', cmdDict['command'].format(argDict)) \ + re.sub(r';+', ';', cmdDict['command'].format(**argDict)) \
+ str(cmd.DEFprefix['end'] + str(cmd.DEFprefix['end']
if cmdDict['defPrefix'] else cmdDict['end']) if cmdDict['defPrefix'] else cmdDict['end'])
@ -60,3 +66,6 @@ def checkError(cmdName, response):
if error_codes: if error_codes:
return error_codes.groups() return error_codes.groups()
return None return None
testala=cmdString('callPrintImage',imageName='Pippus',printMode='10',fieldContent='qualcosa\rqualcosaltro\rciao')