Skip to content

Commit

Permalink
feat: comfy snapshot restore
Browse files Browse the repository at this point in the history
refactor: move apply_snapshot to snapshot command from install

update README.md
  • Loading branch information
ltdrdata committed May 3, 2024
1 parent 2ecbe2b commit b8dbbe8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ will simply update the comfy.yaml file to reflect the local setup
* **(WIP)** Currently, only the installation of ComfyUI and custom nodes is being applied.


### Backup Snapshot [WIP]
### Snapshot [WIP]

To backup ComfyUI Environment:
To save ComfyUI Environment:

`comfy backup --output=<.yaml path>`
`comfy snapshot save --output=<.yaml path>`

This command is used to perform a full backup of the currently installed ComfyUI Environment.
To retore ComfyUI Environment:

`comfy snapshot restore --input=<.yaml path>`

This command is used to perform a full backup/restore of the currently installed ComfyUI Environment.
**(WIP)** Currently, only the ComfyUI and Custom node information are backed up.


### Specifying execution path

* You can specify the path of ComfyUI where the command will be applied through path indicators as follows:
Expand Down
5 changes: 2 additions & 3 deletions comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def install(
)

if snapshot is not None:
checker.check()
install_inner.apply_snapshot(checker, snapshot)
snapshot_command.apply_snapshot(snapshot)

print(f"ComfyUI is installed at: {comfy_path}")

Expand Down Expand Up @@ -199,7 +198,7 @@ def update(target: str = typer.Argument("comfy", help="[all|comfy]")):
def validate_comfyui(_env_checker):
if _env_checker.comfy_repo is None:
print(
f"[bold red]If ComfyUI is not installed, this feature cannot be used.[/bold red]"
"[bold red]If ComfyUI is not installed, this feature cannot be used.[/bold red]"
)
raise typer.Exit(code=1)

Expand Down
18 changes: 0 additions & 18 deletions comfy_cli/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import subprocess
from rich import print
import sys
import typer
from comfy_cli.command import custom_nodes
from comfy_cli.workspace_manager import WorkspaceManager


Expand Down Expand Up @@ -114,19 +112,3 @@ def execute(
os.chdir(repo_dir)

print("")


def apply_snapshot(checker, filepath):
if not os.path.exists(filepath):
print(f"[bold red]File not found: {filepath}[/bold red]")
raise typer.Exit(code=1)

if checker.get_comfyui_manager_path() is not None and os.path.exists(
checker.get_comfyui_manager_path()
):
print(
f"[bold red]If ComfyUI-Manager is not installed, the snapshot feature cannot be used.[/bold red]"
)
raise typer.Exit(code=1)

custom_nodes.command.restore_snapshot(filepath)
34 changes: 33 additions & 1 deletion comfy_cli/command/snapshot/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from comfy_cli import tracking, ui
from comfy_cli.workspace_manager import WorkspaceManager
from comfy_cli.command import custom_nodes
from rich import print
import uuid
import yaml

Expand All @@ -12,7 +13,7 @@
app = typer.Typer()


@app.command(help="Save current snapshot")
@app.command(help="Save current snapshot to .yaml file")
@tracking.track_command()
def save(
output: Annotated[
Expand Down Expand Up @@ -49,3 +50,34 @@ def save(
yaml.dump(info, yaml_file, allow_unicode=True)

print(f"Snapshot file is saved as `{output_path}`")


@app.command(help="Restore from snapshot file")
@tracking.track_command()
def restore(
input: Annotated[
str,
"--input",
typer.Option(show_default=False, help="Specify the input file path. (.yaml)"),
],
):
input_path = os.path.abspath(input)
apply_snapshot(input_path)

#TODO: restore other properties


def apply_snapshot(filepath):
if not os.path.exists(filepath):
print(f"[bold red]File not found: {filepath}[/bold red]")
raise typer.Exit(code=1)

if workspace_manager.get_comfyui_manager_path() is None or not os.path.exists(
workspace_manager.get_comfyui_manager_path()
):
print(
"[bold red]If ComfyUI-Manager is not installed, the snapshot feature cannot be used.[/bold red]"
)
raise typer.Exit(code=1)

custom_nodes.command.restore_snapshot(filepath)

0 comments on commit b8dbbe8

Please sign in to comment.