Commit f65d0dc0 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub

Merge pull request #12689 from AUTOMATIC1111/patch-config-status

Patch config status handle corrupted files
parents 4a2bf65f 2c10fda3
...@@ -8,14 +8,12 @@ import time ...@@ -8,14 +8,12 @@ import time
import tqdm import tqdm
from datetime import datetime from datetime import datetime
from collections import OrderedDict
import git import git
from modules import shared, extensions, errors from modules import shared, extensions, errors
from modules.paths_internal import script_path, config_states_dir from modules.paths_internal import script_path, config_states_dir
all_config_states = {}
all_config_states = OrderedDict()
def list_config_states(): def list_config_states():
...@@ -28,10 +26,14 @@ def list_config_states(): ...@@ -28,10 +26,14 @@ def list_config_states():
for filename in os.listdir(config_states_dir): for filename in os.listdir(config_states_dir):
if filename.endswith(".json"): if filename.endswith(".json"):
path = os.path.join(config_states_dir, filename) path = os.path.join(config_states_dir, filename)
try:
with open(path, "r", encoding="utf-8") as f: with open(path, "r", encoding="utf-8") as f:
j = json.load(f) j = json.load(f)
assert "created_at" in j, '"created_at" does not exist'
j["filepath"] = path j["filepath"] = path
config_states.append(j) config_states.append(j)
except Exception as e:
print(f'[ERROR]: Config states {path}, {e}')
config_states = sorted(config_states, key=lambda cs: cs["created_at"], reverse=True) config_states = sorted(config_states, key=lambda cs: cs["created_at"], reverse=True)
......
...@@ -65,7 +65,7 @@ def save_config_state(name): ...@@ -65,7 +65,7 @@ def save_config_state(name):
filename = os.path.join(config_states_dir, f"{timestamp}_{name}.json") filename = os.path.join(config_states_dir, f"{timestamp}_{name}.json")
print(f"Saving backup of webui/extension state to {filename}.") print(f"Saving backup of webui/extension state to {filename}.")
with open(filename, "w", encoding="utf-8") as f: with open(filename, "w", encoding="utf-8") as f:
json.dump(current_config_state, f) json.dump(current_config_state, f, indent=4)
config_states.list_config_states() config_states.list_config_states()
new_value = next(iter(config_states.all_config_states.keys()), "Current") new_value = next(iter(config_states.all_config_states.keys()), "Current")
new_choices = ["Current"] + list(config_states.all_config_states.keys()) new_choices = ["Current"] + list(config_states.all_config_states.keys())
...@@ -200,8 +200,7 @@ def update_config_states_table(state_name): ...@@ -200,8 +200,7 @@ def update_config_states_table(state_name):
created_date = time.asctime(time.gmtime(config_state["created_at"])) created_date = time.asctime(time.gmtime(config_state["created_at"]))
filepath = config_state.get("filepath", "<unknown>") filepath = config_state.get("filepath", "<unknown>")
code = f"""<!-- {time.time()} -->""" try:
webui_remote = config_state["webui"]["remote"] or "" webui_remote = config_state["webui"]["remote"] or ""
webui_branch = config_state["webui"]["branch"] webui_branch = config_state["webui"]["branch"]
webui_commit_hash = config_state["webui"]["commit_hash"] or "<unknown>" webui_commit_hash = config_state["webui"]["commit_hash"] or "<unknown>"
...@@ -227,12 +226,12 @@ def update_config_states_table(state_name): ...@@ -227,12 +226,12 @@ def update_config_states_table(state_name):
if current_webui["commit_hash"] != webui_commit_hash: if current_webui["commit_hash"] != webui_commit_hash:
style_commit = STYLE_PRIMARY style_commit = STYLE_PRIMARY
code += f"""<h2>Config Backup: {config_name}</h2> code = f"""<!-- {time.time()} -->
<div><b>Filepath:</b> {filepath}</div> <h2>Config Backup: {config_name}</h2>
<div><b>Created at:</b> {created_date}</div>""" <div><b>Filepath:</b> {filepath}</div>
<div><b>Created at:</b> {created_date}</div>
code += f"""<h2>WebUI State</h2> <h2>WebUI State</h2>
<table id="config_state_webui"> <table id="config_state_webui">
<thead> <thead>
<tr> <tr>
<th>URL</th> <th>URL</th>
...@@ -243,17 +242,23 @@ def update_config_states_table(state_name): ...@@ -243,17 +242,23 @@ def update_config_states_table(state_name):
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td><label{style_remote}>{remote}</label></td> <td>
<td><label{style_branch}>{webui_branch}</label></td> <label{style_remote}>{remote}</label>
<td><label{style_commit}>{commit_link}</label></td> </td>
<td><label{style_commit}>{date_link}</label></td> <td>
<label{style_branch}>{webui_branch}</label>
</td>
<td>
<label{style_commit}>{commit_link}</label>
</td>
<td>
<label{style_commit}>{date_link}</label>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
""" <h2>Extension State</h2>
<table id="config_state_extensions">
code += """<h2>Extension State</h2>
<table id="config_state_extensions">
<thead> <thead>
<tr> <tr>
<th>Extension</th> <th>Extension</th>
...@@ -264,7 +269,7 @@ def update_config_states_table(state_name): ...@@ -264,7 +269,7 @@ def update_config_states_table(state_name):
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
""" """
ext_map = {ext.name: ext for ext in extensions.extensions} ext_map = {ext.name: ext for ext in extensions.extensions}
...@@ -299,20 +304,25 @@ def update_config_states_table(state_name): ...@@ -299,20 +304,25 @@ def update_config_states_table(state_name):
if current_ext.commit_hash != ext_commit_hash: if current_ext.commit_hash != ext_commit_hash:
style_commit = STYLE_PRIMARY style_commit = STYLE_PRIMARY
code += f""" code += f""" <tr>
<tr>
<td><label{style_enabled}><input class="gr-check-radio gr-checkbox" type="checkbox" disabled="true" {'checked="checked"' if ext_enabled else ''}>{html.escape(ext_name)}</label></td> <td><label{style_enabled}><input class="gr-check-radio gr-checkbox" type="checkbox" disabled="true" {'checked="checked"' if ext_enabled else ''}>{html.escape(ext_name)}</label></td>
<td><label{style_remote}>{remote}</label></td> <td><label{style_remote}>{remote}</label></td>
<td><label{style_branch}>{ext_branch}</label></td> <td><label{style_branch}>{ext_branch}</label></td>
<td><label{style_commit}>{commit_link}</label></td> <td><label{style_commit}>{commit_link}</label></td>
<td><label{style_commit}>{date_link}</label></td> <td><label{style_commit}>{date_link}</label></td>
</tr> </tr>
""" """
code += """ code += """ </tbody>
</tbody> </table>"""
</table>
""" except Exception as e:
print(f"[ERROR]: Config states {filepath}, {e}")
code = f"""<!-- {time.time()} -->
<h2>Config Backup: {config_name}</h2>
<div><b>Filepath:</b> {filepath}</div>
<div><b>Created at:</b> {created_date}</div>
<h2>This file is corrupted</h2>"""
return code return code
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment