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)
|
print(exc)
|
||||||
|
|
||||||
h = wireviz.Harness()
|
h = wireviz.Harness()
|
||||||
# add nodes
|
|
||||||
if 'nodes' in input and type(input['nodes']) == dict:
|
# add items
|
||||||
if len(input['nodes']) > 0:
|
sections = ['nodes','wires','ferrules','connections']
|
||||||
for k, o in input['nodes'].items():
|
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)
|
h.add_node(name=k, **o)
|
||||||
else:
|
elif sec == 'wires':
|
||||||
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():
|
|
||||||
h.add_cable(name=k, **o)
|
h.add_cable(name=k, **o)
|
||||||
else:
|
elif sec == 'ferrules':
|
||||||
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:
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print('Ferrule list empty')
|
print('{} section empty'.format(sec))
|
||||||
else:
|
else:
|
||||||
print('No ferrule list found')
|
print('No {} section found'.format(sec))
|
||||||
input['ferrules'] = {}
|
if ty == dict:
|
||||||
|
input[sec] = {}
|
||||||
|
elif ty == list:
|
||||||
|
input[sec] = []
|
||||||
|
|
||||||
# add connections
|
# add connections
|
||||||
if 'connections' in input:
|
ferrule_counter = 0
|
||||||
if len(input['connections']) > 0:
|
for con in input['connections']:
|
||||||
ferrule_counter = 0
|
|
||||||
conlist = input['connections']
|
|
||||||
for con in conlist:
|
|
||||||
if len(con) == 3: # format: connector -- wire -- conector
|
if len(con) == 3: # format: connector -- wire -- conector
|
||||||
|
|
||||||
for c in con:
|
for c in con:
|
||||||
@ -188,10 +178,5 @@ if 'connections' in input:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('Wrong number of connection parameters')
|
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)
|
h.output(filename='output', format=('png','svg'), view=False)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user