in tools/records/convert2yaml.py [0:0]
def handle_file_input(args):
config = {}
# Fix the names first.
filename = make_tmp_file_with_renamed_fields(args.file)
with open(filename, "r+") as f:
lines = f.readlines()
num_lines = len(lines)
for idx in progressbar(range(num_lines), 40, mute=args.mute):
line = lines[idx]
if '#' == line[0] or '\n' == line[0] or ' ' == line[0]:
idx = idx + 1
continue
s = line.split(' ', maxsplit=3) # keep values all together
name = s[1]
type = s[2]
value = s[3]
track_info = (idx + 1, name) # in case we want to show any error. rec name is always handy.
# We ignore the prefix and work away from there.
if name.startswith("proxy.config."):
name = name[len("proxy.config."):]
elif name.startswith("local.config."):
name = name[len("local.config."):]
elif args.node and name.startswith("proxy.node."):
name = name[len("proxy."):]
# Build the object
add_object(config, name, value[:-1], type, track_info)
idx = idx + 1
ts = {}
ts['records'] = config
if args.schema:
err = validate_schema(ts, args.schema)
if err:
raise Exception("Schema failed.")
save_to_file(args.output, args.json, args.typerepr, args.no_backup, ts)
f.close()
# Clean up the temp file we've created with the renamed fields.
try:
os.remove(filename)
except OSError as e:
raise Exception(f"Error removing temporary file {e.filename} - {e.strerror}. YAML file was created")
return