From abcab9bce572acce573a0d48ce8767a4b036ba84 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Tue, 4 Oct 2022 14:48:16 +0530 Subject: [PATCH] Preserve an error log if the installation failed; Include the starting timestamp in the log --- installer/installer/helpers.py | 14 ++++++++++++-- installer/installer/main.py | 4 ++++ installer/installer/tasks/fetch_project_repo.py | 3 +-- .../installer/tasks/fetch_stable_diffusion_repo.py | 3 +-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/installer/installer/helpers.py b/installer/installer/helpers.py index 7313fce6..b64897d0 100644 --- a/installer/installer/helpers.py +++ b/installer/installer/helpers.py @@ -1,5 +1,7 @@ import subprocess import sys +import shutil +import time from installer import app @@ -27,8 +29,9 @@ def log(msg): app.log_file.write(bytes(msg + "\n", 'utf-8')) app.log_file.flush() -def show_install_error(error_msg): - log(f''' +def fail_with_install_error(error_msg): + try: + log(f''' Error: {error_msg}. Sorry about that, please try to: 1. Run this installer again. @@ -36,3 +39,10 @@ Error: {error_msg}. Sorry about that, please try to: 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues Thanks!''') + + ts = int(time.time()) + shutil.copy(app.LOG_FILE_NAME, f'error-{ts}.log') + except: + pass + + exit(1) diff --git a/installer/installer/main.py b/installer/installer/main.py index b92feb31..7aaed91e 100644 --- a/installer/installer/main.py +++ b/installer/installer/main.py @@ -1,8 +1,10 @@ import os import sys +from datetime import datetime sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +from installer import helpers from installer.tasks import ( fetch_project_repo, apply_project_update, @@ -15,6 +17,8 @@ tasks = [ fetch_stable_diffusion_repo, ] +helpers.log(f'Starting Stable Diffusion UI at {datetime.now().strftime("%d/%m/%Y %H:%M:%S")}') + def run_tasks(): for task in tasks: task.run() diff --git a/installer/installer/tasks/fetch_project_repo.py b/installer/installer/tasks/fetch_project_repo.py index cb51f703..46e27560 100644 --- a/installer/installer/tasks/fetch_project_repo.py +++ b/installer/installer/tasks/fetch_project_repo.py @@ -20,7 +20,6 @@ def run(): if helpers.run(f'git clone {app.PROJECT_REPO_URL} "{app.project_repo_dir_path}"'): helpers.log("Downloaded Stable Diffusion UI") else: - helpers.show_install_error(error_msg="Could not download Stable Diffusion UI") - exit(1) + helpers.fail_with_install_error(error_msg="Could not download Stable Diffusion UI") helpers.run(f'git -c advice.detachedHead=false checkout "{branch_name}"', run_in_folder=app.project_repo_dir_path) diff --git a/installer/installer/tasks/fetch_stable_diffusion_repo.py b/installer/installer/tasks/fetch_stable_diffusion_repo.py index 5125798e..be9e2eab 100644 --- a/installer/installer/tasks/fetch_stable_diffusion_repo.py +++ b/installer/installer/tasks/fetch_stable_diffusion_repo.py @@ -32,8 +32,7 @@ def fetch_repo(): if helpers.run(f'git clone {app.STABLE_DIFFUSION_REPO_URL} "{app.stable_diffusion_repo_dir_path}"'): helpers.log("Downloaded Stable Diffusion") else: - helpers.show_install_error(error_msg="Could not download Stable Diffusion") - exit(1) + helpers.fail_with_install_error(error_msg="Could not download Stable Diffusion") helpers.run(f'git -c advice.detachedHead=false checkout "{commit_id}"', run_in_folder=app.stable_diffusion_repo_dir_path)