add migration code

This commit is contained in:
Dr.Lt.Data 2024-10-05 16:50:26 +09:00
parent adf3f8d094
commit 851742e5e7
3 changed files with 86 additions and 5 deletions

View File

@ -1,7 +1,37 @@
from .modules import manager_ext_server
from .modules import share_3rdparty
legacy_manager_core_path = None
manager_core_path = None
WEB_DIRECTORY = "js"
NODE_CLASS_MAPPINGS = {}
__all__ = ['NODE_CLASS_MAPPINGS']
def is_manager_core_exists():
global legacy_manager_core_path
global manager_core_path
import os
import folder_paths
comfy_path = os.path.dirname(folder_paths.__file__)
legacy_manager_core_path = os.path.join(comfy_path, 'custom_nodes', 'manager-core')
manager_core_path = legacy_manager_core_path
manager_core_path_file = os.path.join(comfy_path, 'manager_core_path.txt')
if os.path.exists(manager_core_path_file):
with open(manager_core_path_file, 'r') as f:
manager_core_path = os.path.join(f.read().strip(), 'manager-core')
return os.path.exists(manager_core_path) or os.path.exists(legacy_manager_core_path)
if not is_manager_core_exists():
from .modules import migration_server
migration_server.manager_core_path = manager_core_path
WEB_DIRECTORY = "migration_js"
NODE_CLASS_MAPPINGS = {}
else:
# Main code
from .modules import manager_ext_server
from .modules import share_3rdparty
WEB_DIRECTORY = "js"
NODE_CLASS_MAPPINGS = {}
__all__ = ['NODE_CLASS_MAPPINGS']

34
migration_js/migration.js Normal file
View File

@ -0,0 +1,34 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
app.registerExtension({
name: "Comfy.ManagerExtMenu",
init() {
$el("style", {
textContent: style,
parent: document.head,
});
},
async setup() {
let cmGroup = new (await import("../../scripts/ui/components/buttonGroup.js")).ComfyButtonGroup(
new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "puzzle",
action: async () => {
if(confirm('As some features of ComfyUI Manager have been integrated into ComfyUI, they have been separated into manager-core.\n\nComfyUI Manager only includes additional extension features that are not provided by manager-core.\n\nWill you install manager-core?')) {
app.ui.dialog.show('Installing manager-core...');
app.ui.dialog.element.style.zIndex = 10010;
await api.fetchApi("/manager/install_manager_core");
app.ui.dialog.show('The installation of manager-core will be completed after restarting.');
}
},
tooltip: "Need to install manager-core",
content: "Manager (Need To Install)",
classList: "comfyui-button comfyui-menu-mobile-collapse primary"
}).element
);
app.menu?.settingsGroup.element.before(cmGroup.element);
}
});

View File

@ -0,0 +1,17 @@
import git
from aiohttp import web
from server import PromptServer
manager_core_path = None
manager_core_url = "https://github.com/Comfy-Org/manager-core"
@PromptServer.instance.routes.get("/manager/install_manager_core")
def install_manager_core(request):
if manager_core_path is not None:
repo = git.Repo.clone_from(manager_core_url, manager_core_path)
repo.git.clear_cache()
repo.close()
else:
print(f"[ComfyUI Manager] Failed to install `manager-core`")
return web.Response(status=200)