files polishing

frdel committed Jul 31, 2025 at 10:39 UTC 2b23d2510d4a1d7094ae486381934d7fea9a22b5
2 files changed +19 -20
python/helpers/files.py
+14 -15
@@ -130,38 +130,37 @@ def read_prompt_file(_relative_path, _backup_dirs=None, _encoding="utf-8", **kwa
130 return content
131
132
133 -def read_file(_relative_path, _backup_dirs=None, _encoding="utf-8"):
134 - if _backup_dirs is None:
135 - _backup_dirs = []
133 +def read_file(relative_path:str, backup_dirs:list[str]|None=None, encoding="utf-8"):
134 + if backup_dirs is None:
135 + backup_dirs = []
136
137 # Try to get the absolute path for the file from the original directory or backup directories
138 - absolute_path = find_file_in_dirs(_relative_path, _backup_dirs)
138 + absolute_path = find_file_in_dirs(relative_path, backup_dirs)
139
140 # Read the file content
141 - with open(absolute_path, "r", encoding=_encoding) as f:
141 + with open(absolute_path, "r", encoding=encoding) as f:
142 return f.read()
143
144
145 -def read_file_bin(_relative_path, _backup_dirs=None):
146 - # init backup dirs
147 - if _backup_dirs is None:
148 - _backup_dirs = []
145 +def read_file_bin(relative_path:str, backup_dirs:list[str]|None=None):
146 + if backup_dirs is None:
147 + backup_dirs = []
148
150 - # get absolute path
151 - absolute_path = find_file_in_dirs(_relative_path, _backup_dirs)
149 + # Try to get the absolute path for the file from the original directory or backup directories
150 + absolute_path = find_file_in_dirs(relative_path, backup_dirs)
151
152 # read binary content
153 with open(absolute_path, "rb") as f:
154 return f.read()
155
156
158 -def read_file_base64(_relative_path, _backup_dirs=None):
157 +def read_file_base64(relative_path, backup_dirs:list[str]|None=None):
158 # init backup dirs
160 - if _backup_dirs is None:
161 - _backup_dirs = []
159 + if backup_dirs is None:
160 + backup_dirs = []
161
162 # get absolute path
164 - absolute_path = find_file_in_dirs(_relative_path, _backup_dirs)
163 + absolute_path = find_file_in_dirs(relative_path, backup_dirs)
164
165 # read binary content and encode to base64
166 with open(absolute_path, "rb") as f:
run_ui.py
+5 -5
@@ -157,13 +157,13 @@ async def serve_index():
157 "version": "unknown",
158 "commit_time": "unknown",
159 }
160 - return files.read_prompt_file(
161 - "./webui/index.html",
162 - _backup_dirs=[],
163 - _encoding="utf-8",
160 + index = files.read_file("webui/index.html")
161 + index = files.replace_placeholders_text(
162 + _content=index,
163 version_no=gitinfo["version"],
165 - version_time=gitinfo["commit_time"],
164 + version_time=gitinfo["commit_time"]
165 )
166 + return index
167
168
169 def run():