|
4 | 4 | import sys |
5 | 5 | import traceback |
6 | 6 | from argparse import Namespace |
| 7 | +from packaging import version |
7 | 8 | from pathlib import Path |
8 | 9 | from typing import Union |
9 | 10 |
|
|
25 | 26 | from .globals import Globals, global_config_dir |
26 | 27 | from .image_util import make_grid |
27 | 28 | from .log import write_log |
| 29 | +from .model_manager import ModelManager |
28 | 30 | from .pngwriter import PngWriter, retrieve_metadata, write_metadata |
29 | 31 | from .readline import Completer, get_completer |
30 | 32 | from ..util import url_attachment_name |
@@ -64,6 +66,9 @@ def main(): |
64 | 66 | Globals.sequential_guidance = args.sequential_guidance |
65 | 67 | Globals.ckpt_convert = True # always true as of 2.3.4 for LoRA support |
66 | 68 |
|
| 69 | + # run any post-install patches needed |
| 70 | + run_patches() |
| 71 | + |
67 | 72 | print(f">> Internet connectivity is {Globals.internet_available}") |
68 | 73 |
|
69 | 74 | if not args.conf: |
@@ -108,6 +113,9 @@ def main(): |
108 | 113 | if opt.lora_path: |
109 | 114 | Globals.lora_models_dir = opt.lora_path |
110 | 115 |
|
| 116 | + # migrate legacy models |
| 117 | + ModelManager.migrate_models() |
| 118 | + |
111 | 119 | # load the infile as a list of lines |
112 | 120 | if opt.infile: |
113 | 121 | try: |
@@ -1291,6 +1299,62 @@ def retrieve_last_used_model()->str: |
1291 | 1299 | with open(model_file_path,'r') as f: |
1292 | 1300 | return f.readline() |
1293 | 1301 |
|
| 1302 | +# This routine performs any patch-ups needed after installation |
| 1303 | +def run_patches(): |
| 1304 | + install_missing_config_files() |
| 1305 | + version_file = Path(Globals.root,'.version') |
| 1306 | + if version_file.exists(): |
| 1307 | + with open(version_file,'r') as f: |
| 1308 | + root_version = version.parse(f.readline() or 'v2.3.2') |
| 1309 | + else: |
| 1310 | + root_version = version.parse('v2.3.2') |
| 1311 | + app_version = version.parse(ldm.invoke.__version__) |
| 1312 | + if root_version < app_version: |
| 1313 | + try: |
| 1314 | + do_version_update(root_version, ldm.invoke.__version__) |
| 1315 | + with open(version_file,'w') as f: |
| 1316 | + f.write(ldm.invoke.__version__) |
| 1317 | + except: |
| 1318 | + print("** Update failed. Will try again on next launch") |
| 1319 | + |
| 1320 | +def install_missing_config_files(): |
| 1321 | + """ |
| 1322 | + install ckpt configuration files that may have been added to the |
| 1323 | + distro after original root directory configuration |
| 1324 | + """ |
| 1325 | + import invokeai.configs as conf |
| 1326 | + from shutil import copyfile |
| 1327 | + |
| 1328 | + root_configs = Path(global_config_dir(), 'stable-diffusion') |
| 1329 | + repo_configs = Path(conf.__path__[0], 'stable-diffusion') |
| 1330 | + for src in repo_configs.iterdir(): |
| 1331 | + dest = root_configs / src.name |
| 1332 | + if not dest.exists(): |
| 1333 | + copyfile(src,dest) |
| 1334 | + |
| 1335 | +def do_version_update(root_version: version.Version, app_version: Union[str, version.Version]): |
| 1336 | + """ |
| 1337 | + Make any updates to the launcher .sh and .bat scripts that may be needed |
| 1338 | + from release to release. This is not an elegant solution. Instead, the |
| 1339 | + launcher should be moved into the source tree and installed using pip. |
| 1340 | + """ |
| 1341 | + if root_version < version.Version('v2.3.4'): |
| 1342 | + dest = Path(Globals.root,'loras') |
| 1343 | + dest.mkdir(exist_ok=True) |
| 1344 | + if root_version < version.Version('v2.3.3'): |
| 1345 | + if sys.platform == "linux": |
| 1346 | + print('>> Downloading new version of launcher script and its config file') |
| 1347 | + from ldm.util import download_with_progress_bar |
| 1348 | + url_base = f'https://raw.githubusercontent.com/invoke-ai/InvokeAI/v{str(app_version)}/installer/templates/' |
| 1349 | + |
| 1350 | + dest = Path(Globals.root,'invoke.sh.in') |
| 1351 | + assert download_with_progress_bar(url_base+'invoke.sh.in',dest) |
| 1352 | + dest.replace(Path(Globals.root,'invoke.sh')) |
| 1353 | + os.chmod(Path(Globals.root,'invoke.sh'), 0o0755) |
| 1354 | + |
| 1355 | + dest = Path(Globals.root,'dialogrc') |
| 1356 | + assert download_with_progress_bar(url_base+'dialogrc',dest) |
| 1357 | + dest.replace(Path(Globals.root,'.dialogrc')) |
1294 | 1358 |
|
1295 | 1359 | if __name__ == '__main__': |
1296 | 1360 | main() |
|
0 commit comments