Simplify processing input file sections
This commit is contained in:
parent
ab922928de
commit
77a69d2362
@ -47,43 +47,33 @@ with open(filename, 'r') as stream:
|
||||
print(exc)
|
||||
|
||||
h = wireviz.Harness()
|
||||
# add nodes
|
||||
if 'nodes' in input and type(input['nodes']) == dict:
|
||||
if len(input['nodes']) > 0:
|
||||
for k, o in input['nodes'].items():
|
||||
|
||||
# add items
|
||||
sections = ['nodes','wires','ferrules','connections']
|
||||
types = [dict, dict, dict, list]
|
||||
for sec, ty in zip(sections, types):
|
||||
if sec in input and type(input[sec]) == ty:
|
||||
if len(input[sec]) > 0:
|
||||
if ty == dict:
|
||||
for k, o in input[sec].items():
|
||||
if sec == 'nodes':
|
||||
h.add_node(name=k, **o)
|
||||
else:
|
||||
print('Node list empty')
|
||||
else:
|
||||
print('No node list found')
|
||||
input['nodes'] = {}
|
||||
|
||||
# add wires
|
||||
if 'wires' in input and type(input['wires']) == dict:
|
||||
if len(input['wires']) > 0:
|
||||
for k, o in input['wires'].items():
|
||||
elif sec == 'wires':
|
||||
h.add_cable(name=k, **o)
|
||||
else:
|
||||
print('Wire list empty')
|
||||
else:
|
||||
print('No wire list found')
|
||||
input['wires'] = {}
|
||||
|
||||
if 'ferrules' in input and type(input['ferrules']) == dict:
|
||||
if len(input['wires']) > 0:
|
||||
elif sec == 'ferrules':
|
||||
pass
|
||||
else:
|
||||
print('Ferrule list empty')
|
||||
print('{} section empty'.format(sec))
|
||||
else:
|
||||
print('No ferrule list found')
|
||||
input['ferrules'] = {}
|
||||
print('No {} section found'.format(sec))
|
||||
if ty == dict:
|
||||
input[sec] = {}
|
||||
elif ty == list:
|
||||
input[sec] = []
|
||||
|
||||
# add connections
|
||||
if 'connections' in input:
|
||||
if len(input['connections']) > 0:
|
||||
ferrule_counter = 0
|
||||
conlist = input['connections']
|
||||
for con in conlist:
|
||||
for con in input['connections']:
|
||||
if len(con) == 3: # format: connector -- wire -- conector
|
||||
|
||||
for c in con:
|
||||
@ -188,10 +178,5 @@ if 'connections' in input:
|
||||
|
||||
else:
|
||||
raise Exception('Wrong number of connection parameters')
|
||||
else:
|
||||
print('Connection list empty')
|
||||
else:
|
||||
print('No connection list found')
|
||||
input['connections'] = {}
|
||||
|
||||
h.output(filename='output', format=('png','svg'), view=False)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user