Make args optional and fix some issues

This commit is contained in:
Douglas Clowes
2014-01-31 17:53:05 +11:00
parent a0c9b78f30
commit a2120c79e8

View File

@ -529,25 +529,28 @@ def build_variable(MyDriver, p):
def build_group(MyDriver, p): def build_group(MyDriver, p):
if Verbose: if Verbose:
print 'Group:', p print 'Group:', p[0]['name'], p
push_context() push_context()
MyGroup = {} MyGroup = {}
MyGroup['Groups'] = {} MyGroup['Groups'] = {}
MyGroup['Vars'] = {} MyGroup['Vars'] = {}
for item in [i for i in p if 'Variable' not in i]: # the sequence of both variables and non-variables is significant
if Verbose: # Therefore, they have to be processed in a single sequence
print "Group Item:", item if p[0]['name']:
for key in item.keys():
MyGroup[key] = item[key]
if key in ContextStack[ContextIndex]:
ContextStack[ContextIndex][key] = item[key]
if MyGroup['name']:
if len(ContextStack[ContextIndex]['path']) > 0: if len(ContextStack[ContextIndex]['path']) > 0:
ContextStack[ContextIndex]['path'] += '/' ContextStack[ContextIndex]['path'] += '/'
ContextStack[ContextIndex]['path'] += MyGroup['name'] ContextStack[ContextIndex]['path'] += p[0]['name']
for item in [i for i in p if 'Variable' in i]: for item in p:
MyVar = build_variable(MyDriver, item['Variable']) if 'Variable' in item:
MyGroup['Vars'][MyVar['name']] = MyVar MyVar = build_variable(MyDriver, item['Variable'])
MyGroup['Vars'][MyVar['name']] = MyVar
else:
if Verbose:
print "Group Item:", item
for key in item:
MyGroup[key] = item[key]
if key in ContextStack[ContextIndex]:
ContextStack[ContextIndex][key] = item[key]
pop_context() pop_context()
return MyGroup return MyGroup
@ -649,14 +652,14 @@ def put_preamble(MyDriver):
def put_write_function(MyDriver, func): def put_write_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['proc %s::%s {tc_root nextState cmd} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root nextState cmd_str} {' % (MyDriver['namespace'], func)]
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd}"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func]
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' hdelprop [sct] geterror'] txt += [' hdelprop [sct] geterror']
txt += [' }'] txt += [' }']
txt += [' set par [sct target]'] txt += [' set par [sct target]']
txt += [' set cmd "${cmd}${par}"'] txt += [' set cmd "${cmd_str}${par}"']
if func in MyDriver['Funcs']: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -670,7 +673,7 @@ def put_check_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] resp=[sct result]"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] resp=[sct result]"' % func]
if func in MyDriver['Funcs']: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -680,12 +683,13 @@ def put_check_function(MyDriver, func):
def put_fetch_function(MyDriver, func): def put_fetch_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['proc %s::%s {tc_root nextState cmd} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root nextState cmd_str} {' % (MyDriver['namespace'], func)]
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd}"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func]
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' hdelprop [sct] geterror'] txt += [' hdelprop [sct] geterror']
txt += [' }'] txt += [' }']
if func in MyDriver['Funcs']: txt += [' set cmd "${cmd_str}"']
if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -709,7 +713,7 @@ def put_read_function(MyDriver, func):
txt += [' sct geterror "${data}"'] txt += [' sct geterror "${data}"']
txt += [' return -code error "[sct geterror]"'] txt += [' return -code error "[sct geterror]"']
txt += [' }'] txt += [' }']
if func in MyDriver['Funcs']: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -745,7 +749,7 @@ def put_check(MyDriver):
txt += [' # upperlimit not set, use target'] txt += [' # upperlimit not set, use target']
txt += [' set hilimit [sct target]'] txt += [' set hilimit [sct target]']
txt += [' }'] txt += [' }']
if 'check' in MyDriver['Funcs']: if 'check' in MyDriver['Funcs'] and len(MyDriver['Funcs']['check']['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs']['check']['text'] txt += MyDriver['Funcs']['check']['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -774,7 +778,7 @@ def put_checklimits(MyDriver):
txt += [' # upperlimit not set, use target'] txt += [' # upperlimit not set, use target']
txt += [' set hilimit [sct target]'] txt += [' set hilimit [sct target]']
txt += [' }'] txt += [' }']
if 'checklimits' in MyDriver['Funcs']: if 'checklimits' in MyDriver['Funcs'] and len(MyDriver['Funcs']['checklimits']['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs']['checklimits']['text'] txt += MyDriver['Funcs']['checklimits']['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -790,7 +794,7 @@ def put_checkstatus(MyDriver):
txt = [''] txt = ['']
txt += ['# checkstatus function for driveable interface'] txt += ['# checkstatus function for driveable interface']
txt += ['proc %s::checkstatus {tc_root} {' % MyDriver['namespace']] txt += ['proc %s::checkstatus {tc_root} {' % MyDriver['namespace']]
if 'checkstatus' in MyDriver['Funcs']: if 'checkstatus' in MyDriver['Funcs'] and len(MyDriver['Funcs']['checkstatus']['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs']['checkstatus']['text'] txt += MyDriver['Funcs']['checkstatus']['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -814,7 +818,7 @@ def put_halt(MyDriver):
txt += ['proc %s::halt {tc_root} {' % MyDriver['namespace']] txt += ['proc %s::halt {tc_root} {' % MyDriver['namespace']]
txt += [' debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"'] txt += [' debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"']
txt += [' ### TODO hset [sct] [hval [sct]]'] txt += [' ### TODO hset [sct] [hval [sct]]']
if 'halt' in MyDriver['Funcs']: if 'halt' in MyDriver['Funcs'] and len(MyDriver['Funcs']['halt']['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs']['halt']['text'] txt += MyDriver['Funcs']['halt']['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
@ -1080,7 +1084,11 @@ def put_group(MyDriver, MyGroup):
def put_mk_sct_driver(MyDriver): def put_mk_sct_driver(MyDriver):
txt = [''] txt = ['']
txt += ['proc %s::mk_sct_%s { sct_controller name %s } {' % (MyDriver['namespace'], MyDriver['name'], MyDriver['make_args'])] if 'make_args' in MyDriver:
line = 'proc %s::mk_sct_%s { sct_controller name %s } {' % (MyDriver['namespace'], MyDriver['name'], MyDriver['make_args'])
else:
line = 'proc %s::mk_sct_%s { sct_controller name } {' % (MyDriver['namespace'], MyDriver['name'])
txt += [line]
txt += [' debug_log 1 "mk_sct_%s for ${name}"' % MyDriver['name']] txt += [' debug_log 1 "mk_sct_%s for ${name}"' % MyDriver['name']]
txt += [' set ns "[namespace current]"'] txt += [' set ns "[namespace current]"']
txt += [' set catch_status [ catch {'] txt += [' set catch_status [ catch {']
@ -1154,7 +1162,11 @@ def put_postamble(MyDriver):
txt += [' namespace export mk_sct_%s' % MyDriver['name']] txt += [' namespace export mk_sct_%s' % MyDriver['name']]
txt += ['}'] txt += ['}']
txt += [''] txt += ['']
txt += ['proc add_%s {name IP port %s} {' % (MyDriver['name'], MyDriver['add_args'])] if 'add_args' in MyDriver:
line = 'proc add_%s {name IP port %s} {' % (MyDriver['name'], MyDriver['add_args'])
else:
line = 'proc add_%s {name IP port} {' % MyDriver['name']
txt += [line]
txt += [' set ns "%s"' % MyDriver['namespace']] txt += [' set ns "%s"' % MyDriver['namespace']]
txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']] txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']]
txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']] txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']]
@ -1162,17 +1174,26 @@ def put_postamble(MyDriver):
txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"'] txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"']
txt += [' makesctcontroller sct_${name} aqadapter ${port}'] txt += [' makesctcontroller sct_${name} aqadapter ${port}']
txt += [' } else {'] txt += [' } else {']
txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} %s ${IP}:${port} %s"' % (MyDriver['protocol'], MyDriver['protocol_args'].replace('\\', '\\\\').replace('"', '\\"'))] if 'protocol_args' in MyDriver:
txt += [' makesctcontroller sct_${name} %s ${IP}:${port} %s' % (MyDriver['protocol'], MyDriver['protocol_args'])] protocol_args = MyDriver['protocol_args'].replace('\\', '\\\\').replace('"', '\\"')
txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} %s ${IP}:${port} %s"' % (MyDriver['protocol'], protocol_args)]
txt += [' makesctcontroller sct_${name} %s ${IP}:${port} %s' % (MyDriver['protocol'], MyDriver['protocol_args'])]
else:
txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} %s ${IP}:${port}"' % MyDriver['protocol']]
txt += [' makesctcontroller sct_${name} %s ${IP}:${port}' % MyDriver['protocol']]
txt += [' }'] txt += [' }']
txt += [' }'] txt += [' }']
make_args = '' make_args = ''
for arg in MyDriver['make_args'].split(): if 'make_args' in MyDriver:
if len(make_args) > 0: for arg in MyDriver['make_args'].split():
make_args += ' ' if len(make_args) > 0:
make_args += '${' + arg + '}' make_args += ' '
txt += [' ${ns}::debug_log 1 "mk_sct_%s sct_${name} ${name} %s"' % (MyDriver['name'], make_args)] make_args += '${' + arg + '}'
txt += [' ${ns}::mk_sct_%s sct_${name} ${name} %s' % (MyDriver['name'], make_args)] txt += [' ${ns}::debug_log 1 "mk_sct_%s sct_${name} ${name} %s"' % (MyDriver['name'], make_args)]
txt += [' ${ns}::mk_sct_%s sct_${name} ${name} %s' % (MyDriver['name'], make_args)]
else:
txt += [' ${ns}::debug_log 1 "mk_sct_%s sct_${name} ${name}"' % MyDriver['name']]
txt += [' ${ns}::mk_sct_%s sct_${name} ${name}' % MyDriver['name']]
# TODO # TODO
#txt += [' ${ns}::debug_log 1 "makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler"'] #txt += [' ${ns}::debug_log 1 "makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler"']
# txt += [' makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler'] # txt += [' makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler']