-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add custom node migration * Merge fixes * Update manager commit * Remove error toastr
- Loading branch information
1 parent
03d12d4
commit e3d6fa2
Showing
9 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import log from 'electron-log/main'; | ||
import path from 'path'; | ||
import { getAppResourcesPath } from '../install/resourcePaths'; | ||
import { ProcessCallbacks, VirtualEnvironment } from '../virtualEnvironment'; | ||
import { fileSync } from 'tmp'; | ||
|
||
export class CmCli { | ||
private cliPath: string; | ||
private virtualEnvironment: VirtualEnvironment; | ||
|
||
constructor(virtualEnvironment: VirtualEnvironment) { | ||
this.virtualEnvironment = virtualEnvironment; | ||
this.cliPath = path.join(getAppResourcesPath(), 'ComfyUI', 'custom_nodes', 'ComfyUI-Manager', 'cm-cli.py'); | ||
} | ||
|
||
private async _runCommandAsync( | ||
args: string[], | ||
callbacks?: ProcessCallbacks, | ||
env?: Record<string, string>, | ||
cwd?: string | ||
): Promise<{ exitCode: number | null }> { | ||
const cmd = [this.cliPath, ...args]; | ||
return await this.virtualEnvironment.runPythonCommandAsync(cmd, callbacks, env, cwd); | ||
} | ||
|
||
public async runCommandAsync( | ||
args: string[], | ||
callbacks?: ProcessCallbacks, | ||
env: Record<string, string> = {}, | ||
checkExit: boolean = true, | ||
cwd?: string | ||
) { | ||
let output = ''; | ||
let error = ''; | ||
const { exitCode } = await this._runCommandAsync( | ||
args, | ||
{ | ||
onStdout: (message) => { | ||
output += message; | ||
callbacks?.onStdout?.(message); | ||
}, | ||
onStderr: (message) => { | ||
console.warn('[warn]', message); | ||
error += message; | ||
callbacks?.onStderr?.(message); | ||
}, | ||
}, | ||
{ | ||
COMFYUI_PATH: this.virtualEnvironment.venvRootPath, | ||
...env, | ||
}, | ||
cwd | ||
); | ||
|
||
if (checkExit && exitCode !== 0) { | ||
throw new Error(`Error calling cm-cli: \nExit code: ${exitCode}\nOutput:${output}\n\nError:${error}`); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
public async restoreCustomNodes(fromComfyDir: string, callbacks: ProcessCallbacks) { | ||
const tmpFile = fileSync({ postfix: '.json' }); | ||
try { | ||
log.debug('Using temp file: ' + tmpFile.name); | ||
await this.saveSnapshot(fromComfyDir, tmpFile.name, callbacks); | ||
await this.restoreSnapshot(tmpFile.name, callbacks); | ||
} finally { | ||
tmpFile?.removeCallback(); | ||
} | ||
} | ||
|
||
public async saveSnapshot(fromComfyDir: string, outFile: string, callbacks: ProcessCallbacks): Promise<void> { | ||
const output = await this.runCommandAsync( | ||
['save-snapshot', '--output', outFile, '--no-full-snapshot'], | ||
callbacks, | ||
{ | ||
COMFYUI_PATH: fromComfyDir, | ||
PYTHONPATH: fromComfyDir, | ||
}, | ||
true, | ||
fromComfyDir | ||
); | ||
log.info(output); | ||
} | ||
|
||
public async restoreSnapshot(snapshotFile: string, callbacks: ProcessCallbacks) { | ||
log.info('Restoring snapshot ' + snapshotFile); | ||
const output = await this.runCommandAsync(['restore-snapshot', snapshotFile], callbacks); | ||
log.info(output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters