Restructured data to support block and node level links. Added hidden nodes and edges in blocks to improve link visualization. Introduced support for configuring dot file parameters with a config file.
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import json
|
|
import yaml
|
|
|
|
def load_data(filename):
|
|
# Check file extension
|
|
if not filename.lower().endswith(('.yaml', '.yml')):
|
|
raise ValueError(f"File '{filename}' is not a YAML file")
|
|
|
|
# Read file content
|
|
with open(filename, 'r') as f:
|
|
content = f.read()
|
|
|
|
# Try to load as YAML
|
|
try:
|
|
data = yaml.safe_load(content)
|
|
if not isinstance(data, dict):
|
|
raise ValueError("YAML content does not contain a dictionary")
|
|
return data
|
|
except yaml.YAMLError as e:
|
|
raise ValueError(f"Invalid YAML format in file '{filename}': {str(e)}")
|
|
|
|
def load_config(filename):
|
|
# Check file extension
|
|
if not filename.lower().endswith(('.yaml', '.yml')):
|
|
raise ValueError(f"File '{filename}' is not a YAML file")
|
|
|
|
# Read file content
|
|
try:
|
|
with open(filename, 'r') as f:
|
|
content = f.read()
|
|
except FileNotFoundError:
|
|
return {}
|
|
|
|
# Try to load as YAML
|
|
try:
|
|
config = yaml.safe_load(content)
|
|
if not isinstance(config, dict):
|
|
raise ValueError("YAML content does not contain a dictionary")
|
|
return config
|
|
except yaml.YAMLError as e:
|
|
raise ValueError(f"Invalid YAML format in file '{filename}': {str(e)}")
|
|
|
|
#def main():
|
|
# data = load_data(DATA)
|
|
# json_data = json.dumps(data, indent=2)
|
|
# print(json_data)
|
|
|
|
#if __name__ == "__main__":
|
|
# main()
|