from .utils import here, run_command, comfy_mode from aiohttp import web from .log import mklog import sys endlog = mklog("mtb endpoint") # - ACTIONS import requirements def ACTIONS_installDependency(dependency_names=None): if dependency_names is None: return {"error": "No dependency name provided"} endlog.debug(f"Received Install Dependency request for {dependency_names}") reqs = [] if comfy_mode == "embeded": reqs = list(requirements.parse((here / "reqs_portable.txt").read_text())) else: reqs = list(requirements.parse((here / "reqs.txt").read_text())) print([x.specs for x in reqs]) print( "\n".join([f"{x.line} {''.join(x.specs[0] if x.specs else '')}" for x in reqs]) ) for dependency_name in dependency_names: for req in reqs: if req.name == dependency_name: endlog.debug(f"Dependency {dependency_name} installed") break return {"success": True} def ACTIONS_getStyles(style_name=None): from .nodes.conditions import StylesLoader styles = StylesLoader.options match_list = ["name"] if styles: filtered_styles = { key: value for key, value in styles.items() if not key.startswith("__") and key not in match_list } if style_name: return filtered_styles.get(style_name, {"error": "Style not found"}) return filtered_styles return {"error": "No styles found"} async def do_action(request) -> web.Response: endlog.debug("Init action request") request_data = await request.json() name = request_data.get("name") args = request_data.get("args") endlog.debug(f"Received action request: {name} {args}") method_name = f"ACTIONS_{name}" method = globals().get(method_name) if callable(method): result = method(args) if args else method() endlog.debug(f"Action result: {result}") return web.json_response({"result": result}) available_methods = [ attr[len("ACTIONS_") :] for attr in globals() if attr.startswith("ACTIONS_") ] return web.json_response( {"error": "Invalid method name.", "available_methods": available_methods} ) # - HTML UTILS def dependencies_button(name, dependencies): deps = ",".join([f"'{x}'" for x in dependencies]) return f""" """ def render_table(table_dict, sort=True, title=None): table_dict = sorted( table_dict.items(), key=lambda item: item[0] ) # Sort the dictionary by keys table_rows = "" for name, item in table_dict: if isinstance(item, dict): if "dependencies" in item: table_rows += f"
Name | Description |
---|