generalized root directory version updating

This commit is contained in:
Lincoln Stein
2023-03-27 22:35:12 -04:00
parent 90f00db032
commit 2f424f29a0
3 changed files with 35 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import shlex
import sys
import traceback
from argparse import Namespace
from packaging import version
from pathlib import Path
from typing import Union
@ -1289,7 +1290,20 @@ def check_internet() -> bool:
# This routine performs any patch-ups needed after installation
def run_patches():
install_missing_config_files()
update_launchers()
version_file = Path(Globals.root,'.version')
if version_file.exists():
with open(version_file,'r') as f:
root_version = version.parse(f.readline() or 'v2.3.2')
else:
root_version = version.parse('v2.3.2')
app_version = version.parse(ldm.invoke.__version__)
if root_version < app_version:
try:
do_version_update(root_version, ldm.invoke.__version__)
with open(version_file,'w') as f:
f.write(ldm.invoke.__version__)
except:
print("** Update failed. Will try again on next launch")
def install_missing_config_files():
"""
@ -1306,19 +1320,26 @@ def install_missing_config_files():
if not dest.exists():
copyfile(src,dest)
def update_launchers():
def do_version_update(root_version: version.Version, app_version: Union[str, version.Version]):
"""
Make any updates to the launcher .sh and .bat scripts that may be needed
from release to release. This is not an elegant solution. Instead, the
launcher should be moved into the source tree and installed by pip.
launcher should be moved into the source tree and installed using pip.
"""
if sys.platform == "linux" \
and not Path(Globals.root,'.dialogrc').exists():
print('>> Downloading new version of launcher script and its config file')
from ldm.util import download_with_progress_bar
url_base = 'https://raw.githubusercontent.com/invoke-ai/InvokeAI/v2.3.3-rc1/installer/templates/'
download_with_progress_bar(url_base+'invoke.sh.in',Path(Globals.root,'invoke.sh'))
download_with_progress_bar(url_base+'dialogrc',Path(Globals.root,'.dialogrc'))
if root_version < version.Version('v2.3.3'):
if sys.platform == "linux":
print('>> Downloading new version of launcher script and its config file')
from ldm.util import download_with_progress_bar
url_base = f'https://raw.githubusercontent.com/invoke-ai/InvokeAI/release/v{str(app_version)}/installer/templates/'
dest = Path(Globals.root,'invoke.sh.in')
assert download_with_progress_bar(url_base+'invoke.sh.in',dest)
dest.replace(Path(Globals.root,'invoke.sh'))
os.chmod(Path(Globals.root,'invoke.sh'), 0o0755)
dest = Path(Globals.root,'dialogrc')
assert download_with_progress_bar(url_base+'dialogrc',dest)
dest.replace(Path(Globals.root,'.dialogrc'))
if __name__ == '__main__':
main()

View File

@ -329,7 +329,7 @@ def download_with_resume(url: str, dest: Path, access_token: str = None) -> Path
resp = requests.get(url, headers=header, stream=True) # new request with range
if exist_size > content_length:
print('* corrupt existing file found. re-downloading')
print(f'* corrupt existing file found (existing_size={exist_size}, content_length={content_length}). re-downloading')
os.remove(dest)
exist_size = 0
@ -341,7 +341,8 @@ def download_with_resume(url: str, dest: Path, access_token: str = None) -> Path
elif resp.status_code == 206 or exist_size > 0:
print(f"* {dest}: partial file found. Resuming...")
elif resp.status_code != 200:
print(f"** An error occurred during downloading {dest}: {resp.reason}")
print(f"** An error occurred while downloading {url}: {resp.reason}")
return None
else:
print(f"* {dest}: Downloading...")

View File

@ -58,6 +58,7 @@ dependencies = [
"pillow",
"prompt-toolkit",
"pudb",
"packaging",
"pypatchmatch",
"pyreadline3",
"pytorch-lightning==1.7.7",