This commit is contained in:
kevin96666
2024-03-01 13:03:08 +01:00
parent 67be668d46
commit 3eac2d0a7b
3 changed files with 71 additions and 13 deletions
+58 -1
View File
@@ -1,4 +1,7 @@
import argparse
import os
import sys
import json
# Hack to pass extra args to main.py
def parse_args_override(self, args=None, namespace=None):
@@ -11,4 +14,58 @@ parser = argparse.ArgumentParser()
parser.add_argument("--sdfx-config-file", type=str, default=None, help="Path for sdfx config file")
args = parser.parse_args()
#args.sdfx_config_file
sdfx_config_file_name = 'sdfx.config.json'
#=== Best effort to find sdfx_config_file_path ===
def find_sdfx_config_path():
if args.sdfx_config_file is not None:
if os.path.exists(args.sdfx_config_file):
return args.sdfx_config_file
path = os.path.abspath(os.path.dirname(__file__))
config_path_found = None
try:
for _ in range(6):
config_path = os.path.join(path, sdfx_config_file_name)
if os.path.exists(config_path):
config_path_found = config_path
path = os.path.dirname(path)
except Exception as e:
print(f"Error File access : {e}")
if config_path_found is not None:
return config_path_found
raise FileNotFoundError()
def load_boot_config():
try:
sdfx_config_file = find_sdfx_config_path()
with open(sdfx_config_file, 'r') as json_file:
data = json.load(json_file)
#=== load port from config file ===
port = data.get('args', {}).get('port', None)
if isinstance(port, int):
sys.argv.append("--port=" + str(port))
#=== load listen from config file ===
listen = data.get('args', {}).get('listen', None)
if isinstance(listen, str):
sys.argv.append("--listen=" + listen)
#=== load disable-xformers from config file ===
dx = data.get('args', {}).get('disable-xformers', None)
if isinstance(dx, bool) and dx == True:
sys.argv.append("--disable-xformers")
#=== load preview-method from config file ===
pm = data.get('args', {}).get('preview-method', None)
if isinstance(pm, str):
sys.argv.append("--preview-method=" + pm)
#=== load enable-cors-header from config file ===
ch = data.get('args', {}).get('enable-cors-header', None)
if isinstance(ch, bool) and ch == True:
sys.argv.append("--enable-cors-header")
except json.JSONDecodeError as e:
print(f"[SDFXBridgeForComfyUI] FATAL -> {sdfx_config_file_name} is not valid, it will not be loaded !")
except FileNotFoundError:
print(f"[SDFXBridgeForComfyUI] FATAL -> {sdfx_config_file_name} not found and not specified")
except Exception as e:
print(f"[SDFXBridgeForComfyUI] FATAL -> : {e}")
load_boot_config()
+1 -1
View File
@@ -2,8 +2,8 @@
"args": {
"disable-xformers": false,
"preview-method": "taesd",
"listen": true,
"enable-cors-header": true,
"listen": "127.0.0.1",
"port": 8188
},
+12 -11
View File
@@ -1,7 +1,11 @@
import os
import argparse
import json
import folder_paths
from .prestartup_script import args
parser = argparse.ArgumentParser()
parser.add_argument("--sdfx-config-file", type=str, default=None, help="Path for sdfx config file")
args = parser.parse_args()
sdfx_config_file_name = 'sdfx.config.json'
@@ -37,16 +41,13 @@ def get_sdfx_absolute_path(path):
sdfx_config_path = find_sdfx_config_path()
except FileNotFoundError:
sdfx_config_path = os.path.abspath(os.path.dirname(__file__))
return os.path.join(sdfx_config_path, path)
parent_path = os.path.dirname(sdfx_config_path)
return os.path.join(parent_path, path)
isPathFound = True
try:
gallery_path = get_sdfx_absolute_path('data/media/gallery')
workflows_path = get_sdfx_absolute_path('data/media/worflows')
templates_path = get_sdfx_absolute_path('data/media/gallery')
except FileNotFoundError:
isPathFound = False
gallery_path = get_sdfx_absolute_path('data/media/gallery')
workflows_path = get_sdfx_absolute_path('data/media/workflows')
templates_path = get_sdfx_absolute_path('data/media/templates')
#=== add all sdfx path to comfy folder_paths ===
def load_sdfx_extra_path_config():
@@ -108,10 +109,10 @@ def load_sdfx_extra_path_config():
print(f"[SDFXBridgeForComfyUI] FATAL -> : {e}")
def get_gallery_path():
return None if not isPathFound else gallery_path
return gallery_path
def get_workflows_path():
return None if not isPathFound else workflows_path
return workflows_path
def get_templates_path():
return None if not isPathFound else templates_path
return templates_path