MCPcopy Create free account
hub / github.com/DanielPFlorian/ComfyUI-WorkflowGenerator / __init__

Method __init__

generators/node_validator.py:44–119  ·  view source on GitHub ↗

Initialize NodeBase with node database and optionally embedding model. Args: cfg: Configuration object with node_base settings

(self, cfg: Any)

Source from the content-addressed store, hash-verified

42 """
43
44 def __init__(self, cfg: Any):
45 """
46 Initialize NodeBase with node database and optionally embedding model.
47
48 Args:
49 cfg: Configuration object with node_base settings
50 """
51 logging.info("Initializing NodeBase...")
52
53 node_list_path = cfg.node_base.node_list_path
54 logging.debug(f"Loading node list from: {node_list_path}")
55 try:
56 with open(node_list_path) as f:
57 self.node_list = json.load(f)
58 logging.info(f"Loaded {len(self.node_list)} node types")
59 except Exception as e:
60 logging.error(f"Failed to load node list: {e}")
61 raise
62
63 node_info_db_path = cfg.node_base.node_info_db_path
64 logging.debug(f"Loading node info database from: {node_info_db_path}")
65 try:
66 self.node_info_db = TinyDB(node_info_db_path)
67 node_info_count = len(self.node_info_db.all())
68 logging.info(f"Loaded {node_info_count} node info entries")
69 except (TypeError, ValueError) as e:
70 # Handle case where file is in old format (plain JSON array instead of TinyDB format)
71 logging.warning("Node info database appears to be in old format, attempting to convert...")
72 try:
73 with open(node_info_db_path, encoding="utf-8") as f:
74 old_data = json.load(f)
75
76 if isinstance(old_data, list):
77 db = TinyDB(node_info_db_path)
78 db.truncate()
79 db.insert_multiple(old_data)
80 db.close()
81 logging.info(f"Converted {len(old_data)} entries from old format to TinyDB format")
82
83 self.node_info_db = TinyDB(node_info_db_path)
84 node_info_count = len(self.node_info_db.all())
85 logging.info(f"Loaded {node_info_count} node info entries")
86 else:
87 raise ValueError(f"Unexpected data format in {node_info_db_path}")
88 except Exception as conv_e:
89 logging.error(f"Failed to convert node info database: {conv_e}")
90 logging.error("Please run 'UpdateNodeCatalog' node to regenerate the catalog files")
91 raise ValueError(
92 f"Node info database format is invalid. Please run 'UpdateNodeCatalog' node to regenerate it.\n"
93 f"Original error: {e}\n"
94 f"Conversion error: {conv_e}"
95 ) from conv_e
96 except Exception as e:
97 logging.error(f"Failed to load node info database: {e}")
98 raise
99
100 self.cache_node_meta_info = {}
101

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected