refactor: rename 'input' -> 'yaml_data'
'input' overloads a python built-in name. Refactor to avoid this.
This commit is contained in:
parent
f14a07fe95
commit
1f06c6017c
@ -450,17 +450,17 @@ class Connection:
|
|||||||
|
|
||||||
def parse(yaml_input, file_out=None, generate_bom=False):
|
def parse(yaml_input, file_out=None, generate_bom=False):
|
||||||
|
|
||||||
input = yaml.safe_load(yaml_input)
|
yaml_data = yaml.safe_load(yaml_input)
|
||||||
|
|
||||||
def expand(input):
|
def expand(yaml_data):
|
||||||
# input can be:
|
# yaml_data can be:
|
||||||
# - a singleton (normally str or int)
|
# - a singleton (normally str or int)
|
||||||
# - a list of str or int
|
# - a list of str or int
|
||||||
# if str is of the format '#-#', it is treated as a range (inclusive) and expanded
|
# if str is of the format '#-#', it is treated as a range (inclusive) and expanded
|
||||||
output = []
|
output = []
|
||||||
if not isinstance(input, list):
|
if not isinstance(yaml_data, list):
|
||||||
input = [input,]
|
yaml_data = [yaml_data,]
|
||||||
for e in input:
|
for e in yaml_data:
|
||||||
e = str(e)
|
e = str(e)
|
||||||
if '-' in e: # list of pins
|
if '-' in e: # list of pins
|
||||||
a, b = tuple(map(int, e.split('-')))
|
a, b = tuple(map(int, e.split('-')))
|
||||||
@ -482,7 +482,7 @@ def parse(yaml_input, file_out=None, generate_bom=False):
|
|||||||
|
|
||||||
def check_designators(what, where):
|
def check_designators(what, where):
|
||||||
for i, x in enumerate(what):
|
for i, x in enumerate(what):
|
||||||
if x not in input[where[i]]:
|
if x not in yaml_data[where[i]]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -492,10 +492,10 @@ def parse(yaml_input, file_out=None, generate_bom=False):
|
|||||||
sections = ['connectors','cables','ferrules','connections']
|
sections = ['connectors','cables','ferrules','connections']
|
||||||
types = [dict, dict, dict, list]
|
types = [dict, dict, dict, list]
|
||||||
for sec, ty in zip(sections, types):
|
for sec, ty in zip(sections, types):
|
||||||
if sec in input and type(input[sec]) == ty:
|
if sec in yaml_data and type(yaml_data[sec]) == ty:
|
||||||
if len(input[sec]) > 0:
|
if len(yaml_data[sec]) > 0:
|
||||||
if ty == dict:
|
if ty == dict:
|
||||||
for k, o in input[sec].items():
|
for k, o in yaml_data[sec].items():
|
||||||
if sec == 'connectors':
|
if sec == 'connectors':
|
||||||
h.add_connector(name=k, **o)
|
h.add_connector(name=k, **o)
|
||||||
elif sec == 'cables':
|
elif sec == 'cables':
|
||||||
@ -506,13 +506,13 @@ def parse(yaml_input, file_out=None, generate_bom=False):
|
|||||||
pass # section exists but is empty
|
pass # section exists but is empty
|
||||||
else: # section does not exist, create empty section
|
else: # section does not exist, create empty section
|
||||||
if ty == dict:
|
if ty == dict:
|
||||||
input[sec] = {}
|
yaml_data[sec] = {}
|
||||||
elif ty == list:
|
elif ty == list:
|
||||||
input[sec] = []
|
yaml_data[sec] = []
|
||||||
|
|
||||||
# add connections
|
# add connections
|
||||||
ferrule_counter = 0
|
ferrule_counter = 0
|
||||||
for con in input['connections']:
|
for con in yaml_data['connections']:
|
||||||
if len(con) == 3: # format: connector -- cable -- conector
|
if len(con) == 3: # format: connector -- cable -- conector
|
||||||
|
|
||||||
for c in con:
|
for c in con:
|
||||||
@ -601,7 +601,7 @@ def parse(yaml_input, file_out=None, generate_bom=False):
|
|||||||
cable_name = from_name
|
cable_name = from_name
|
||||||
cable_pins = from_pins
|
cable_pins = from_pins
|
||||||
|
|
||||||
ferrule_params = input['ferrules'][ferrule_name]
|
ferrule_params = yaml_data['ferrules'][ferrule_name]
|
||||||
for cable_pin in cable_pins:
|
for cable_pin in cable_pins:
|
||||||
ferrule_counter = ferrule_counter + 1
|
ferrule_counter = ferrule_counter + 1
|
||||||
ferrule_id = '_F{}'.format(ferrule_counter)
|
ferrule_id = '_F{}'.format(ferrule_counter)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user