Add defaults to .ini args and refactor add_driver
This commit is contained in:
@ -1617,7 +1617,7 @@ def put_mkDriver(MyDriver):
|
||||
txt += ['}']
|
||||
emit(txt)
|
||||
|
||||
def put_postamble(MyDriver):
|
||||
def put_add_driver(MyDriver):
|
||||
txt = ['']
|
||||
if 'add_args' in MyDriver:
|
||||
line = 'proc %s::add_driver {name device_class simulation_flag ip_address tcp_port %s} {' % (MyDriver['namespace'], MyDriver['add_args'])
|
||||
@ -1664,7 +1664,10 @@ def put_postamble(MyDriver):
|
||||
txt += [' } catch_message ]']
|
||||
txt += [' handle_exception ${catch_status} ${catch_message}']
|
||||
txt += ['}']
|
||||
txt += ['']
|
||||
emit(txt)
|
||||
|
||||
def put_postamble(MyDriver):
|
||||
txt = ['']
|
||||
txt += ['namespace eval %s {' % MyDriver['namespace']]
|
||||
txt += [' namespace export debug_threshold']
|
||||
txt += [' namespace export debug_log']
|
||||
@ -1686,10 +1689,10 @@ def put_postamble(MyDriver):
|
||||
txt += [' set simulation_flag "[string tolower [SplitReply [%s]]]"' % MyDriver['simulation_group']]
|
||||
line = ' %s::add_driver ${name} "%s"' % (MyDriver['namespace'], MyDriver['class'])
|
||||
for arg in ['simulation_flag', 'ip_address', 'tcp_port']:
|
||||
line += ' "${%s}"' % arg
|
||||
line += ' ${%s}' % arg
|
||||
if 'add_args_lst' in MyDriver:
|
||||
for arg in MyDriver['add_args_lst']:
|
||||
line += ' "${%s}"' % arg
|
||||
line += ' ${%s}' % arg
|
||||
txt += [line]
|
||||
txt += ['}']
|
||||
txt += ['']
|
||||
@ -1760,11 +1763,20 @@ def put_read_config(MyDriver):
|
||||
if 'add_args_lst' in MyDriver:
|
||||
txt += [' set arg_list [list]']
|
||||
txt += [' set missing_list [list]']
|
||||
default_list = []
|
||||
for arg in [key for key in MyDriver['add_args_lst'] if MyDriver['add_args_map'][key] is not None]:
|
||||
default_list += [arg, MyDriver['add_args_map'][arg]]
|
||||
if len(default_list) > 0:
|
||||
txt += [' array unset default_map']
|
||||
txt += [' array set default_map [list %s]' % ' '.join(default_list)]
|
||||
txt += [' foreach arg {' + ' '.join(MyDriver['add_args_lst']) + '} {']
|
||||
txt += [' if {[dict exists $u $arg]} {']
|
||||
txt += [' lappend arg_list "[dict get $u $arg]"']
|
||||
txt += [' } elseif {[dict exists $v $arg]} {']
|
||||
txt += [' lappend arg_list "[dict get $v $arg]"']
|
||||
if len(default_list) > 0:
|
||||
txt += [' } elseif {[info exists default_map($arg)]} {']
|
||||
txt += [' lappend arg_list $default_map($arg)']
|
||||
txt += [' } else {']
|
||||
txt += [' ${ns}::sics_log 9 "Missing configuration value $arg"']
|
||||
txt += [' lappend missing_list $arg']
|
||||
@ -1844,6 +1856,7 @@ def generate_driver(MyDriver):
|
||||
put_preamble(MyDriver)
|
||||
put_standard_code(MyDriver)
|
||||
put_mkDriver(MyDriver)
|
||||
put_add_driver(MyDriver)
|
||||
put_postamble(MyDriver)
|
||||
put_read_config(MyDriver)
|
||||
put_check_config(MyDriver)
|
||||
|
Reference in New Issue
Block a user