pref: optimize print logging
This commit is contained in:
26
__init__.py
26
__init__.py
@@ -12,9 +12,7 @@ version = utils.get_current_version()
|
|||||||
utils.download_web_distribution(version)
|
utils.download_web_distribution(version)
|
||||||
|
|
||||||
|
|
||||||
import logging
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
import traceback
|
|
||||||
from .py import services
|
from .py import services
|
||||||
|
|
||||||
|
|
||||||
@@ -31,8 +29,7 @@ async def scan_download_tasks(request):
|
|||||||
return web.json_response({"success": True, "data": result})
|
return web.json_response({"success": True, "data": result})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Read download task list failed: {e}"
|
error_msg = f"Read download task list failed: {e}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -57,8 +54,7 @@ async def resume_download_task(request):
|
|||||||
return web.json_response({"success": True})
|
return web.json_response({"success": True})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Resume download task failed: {str(e)}"
|
error_msg = f"Resume download task failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +69,7 @@ async def delete_model_download_task(request):
|
|||||||
return web.json_response({"success": True})
|
return web.json_response({"success": True})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Delete download task failed: {str(e)}"
|
error_msg = f"Delete download task failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -108,8 +103,7 @@ async def create_model(request):
|
|||||||
return web.json_response({"success": True, "data": {"taskId": task_id}})
|
return web.json_response({"success": True, "data": {"taskId": task_id}})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Create model download task failed: {str(e)}"
|
error_msg = f"Create model download task failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -123,8 +117,7 @@ async def read_models(request):
|
|||||||
return web.json_response({"success": True, "data": result})
|
return web.json_response({"success": True, "data": result})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Read models failed: {str(e)}"
|
error_msg = f"Read models failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -143,8 +136,7 @@ async def read_model_info(request):
|
|||||||
return web.json_response({"success": True, "data": result})
|
return web.json_response({"success": True, "data": result})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Read model info failed: {str(e)}"
|
error_msg = f"Read model info failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -175,8 +167,7 @@ async def update_model(request):
|
|||||||
return web.json_response({"success": True})
|
return web.json_response({"success": True})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Update model failed: {str(e)}"
|
error_msg = f"Update model failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
@@ -197,8 +188,7 @@ async def delete_model(request):
|
|||||||
return web.json_response({"success": True})
|
return web.json_response({"success": True})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = f"Delete model failed: {str(e)}"
|
error_msg = f"Delete model failed: {str(e)}"
|
||||||
logging.error(error_msg)
|
utils.print_error(error_msg)
|
||||||
logging.debug(traceback.format_exc())
|
|
||||||
return web.json_response({"success": False, "error": error_msg})
|
return web.json_response({"success": False, "error": error_msg})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
extension_tag = "ComfyUI Model Manager"
|
||||||
|
|
||||||
extension_uri: str = None
|
extension_uri: str = None
|
||||||
model_base_paths: dict[str, list[str]] = {}
|
model_base_paths: dict[str, list[str]] = {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
import requests
|
import requests
|
||||||
import folder_paths
|
import folder_paths
|
||||||
import traceback
|
|
||||||
from typing import Callable, Awaitable, Any, Literal, Union, Optional
|
from typing import Callable, Awaitable, Any, Literal, Union, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from . import config
|
from . import config
|
||||||
@@ -225,7 +223,7 @@ async def download_model(task_id: str, request):
|
|||||||
task_status.error = str(e)
|
task_status.error = str(e)
|
||||||
await utils.send_json("update_download_task", task_status)
|
await utils.send_json("update_download_task", task_status)
|
||||||
task_status.error = None
|
task_status.error = None
|
||||||
logging.error(str(e))
|
utils.print_error(str(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status = download_thread_pool.submit(download_task, task_id)
|
status = download_thread_pool.submit(download_task, task_id)
|
||||||
@@ -238,7 +236,7 @@ async def download_model(task_id: str, request):
|
|||||||
task_status.error = str(e)
|
task_status.error = str(e)
|
||||||
await utils.send_json("update_download_task", task_status)
|
await utils.send_json("update_download_task", task_status)
|
||||||
task_status.error = None
|
task_status.error = None
|
||||||
logging.error(traceback.format_exc())
|
utils.print_error(str(e))
|
||||||
|
|
||||||
|
|
||||||
async def download_model_file(
|
async def download_model_file(
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import threading
|
import threading
|
||||||
import queue
|
import queue
|
||||||
import logging
|
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
class DownloadThreadPool:
|
class DownloadThreadPool:
|
||||||
@@ -50,7 +51,7 @@ class DownloadThreadPool:
|
|||||||
with self._lock:
|
with self._lock:
|
||||||
self.running_tasks.remove(task_id)
|
self.running_tasks.remove(task_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"worker run error: {str(e)}")
|
utils.print_error(f"worker run error: {str(e)}")
|
||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self.workers_count -= 1
|
self.workers_count -= 1
|
||||||
|
|||||||
24
py/utils.py
24
py/utils.py
@@ -5,6 +5,7 @@ import shutil
|
|||||||
import tarfile
|
import tarfile
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
|
import traceback
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
@@ -15,6 +16,15 @@ from typing import Any
|
|||||||
from . import config
|
from . import config
|
||||||
|
|
||||||
|
|
||||||
|
def print_info(msg, *args, **kwargs):
|
||||||
|
logging.info(f"[{config.extension_tag}] {msg}", *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def print_error(msg, *args, **kwargs):
|
||||||
|
logging.error(f"[{config.extension_tag}] {msg}", *args, **kwargs)
|
||||||
|
logging.debug(traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
def normalize_path(path: str):
|
def normalize_path(path: str):
|
||||||
normpath = os.path.normpath(path)
|
normpath = os.path.normpath(path)
|
||||||
return normpath.replace(os.path.sep, "/")
|
return normpath.replace(os.path.sep, "/")
|
||||||
@@ -52,8 +62,8 @@ def download_web_distribution(version: str):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info(f"current version {version}, web version {web_version}")
|
print_info(f"current version {version}, web version {web_version}")
|
||||||
logging.info("Downloading web distribution...")
|
print_info("Downloading web distribution...")
|
||||||
download_url = f"https://github.com/hayden-fr/ComfyUI-Model-Manager/releases/download/v{version}/dist.tar.gz"
|
download_url = f"https://github.com/hayden-fr/ComfyUI-Model-Manager/releases/download/v{version}/dist.tar.gz"
|
||||||
response = requests.get(download_url, stream=True)
|
response = requests.get(download_url, stream=True)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -66,7 +76,7 @@ def download_web_distribution(version: str):
|
|||||||
if os.path.exists(web_path):
|
if os.path.exists(web_path):
|
||||||
shutil.rmtree(web_path)
|
shutil.rmtree(web_path)
|
||||||
|
|
||||||
logging.info("Extracting web distribution...")
|
print_info("Extracting web distribution...")
|
||||||
with tarfile.open(temp_file, "r:gz") as tar:
|
with tarfile.open(temp_file, "r:gz") as tar:
|
||||||
members = [
|
members = [
|
||||||
member for member in tar.getmembers() if member.name.startswith("web/")
|
member for member in tar.getmembers() if member.name.startswith("web/")
|
||||||
@@ -74,13 +84,13 @@ def download_web_distribution(version: str):
|
|||||||
tar.extractall(path=config.extension_uri, members=members)
|
tar.extractall(path=config.extension_uri, members=members)
|
||||||
|
|
||||||
os.remove(temp_file)
|
os.remove(temp_file)
|
||||||
logging.info("Web distribution downloaded successfully.")
|
print_info("Web distribution downloaded successfully.")
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logging.error(f"Failed to download web distribution: {e}")
|
print_error(f"Failed to download web distribution: {e}")
|
||||||
except tarfile.TarError as e:
|
except tarfile.TarError as e:
|
||||||
logging.error(f"Failed to extract web distribution: {e}")
|
print_error(f"Failed to extract web distribution: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"An unexpected error occurred: {e}")
|
print_error(f"An unexpected error occurred: {e}")
|
||||||
|
|
||||||
|
|
||||||
def resolve_model_base_paths():
|
def resolve_model_base_paths():
|
||||||
|
|||||||
Reference in New Issue
Block a user