Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,6 @@ def remove_readonly(func, path, excinfo):
|
|
32 |
os.chmod(path, stat.S_IWRITE)
|
33 |
func(path)
|
34 |
|
35 |
-
# リポジトリをクローンまたは更新し、ファイルを修正・コピーする関数
|
36 |
def clone_or_update_repo():
|
37 |
logging.info("リポジトリの更新を開始します。")
|
38 |
|
@@ -46,14 +45,12 @@ def clone_or_update_repo():
|
|
46 |
if result.stderr:
|
47 |
logging.error(result.stderr)
|
48 |
|
49 |
-
# ローカルのリポジトリファイルは変更せず、コピー先で置換を行う
|
50 |
src_target_file = os.path.join(REPO_DIR, "pages", "startup.js")
|
51 |
dest_pages = os.path.join("static", "pages")
|
52 |
|
53 |
if not os.path.exists(src_target_file):
|
54 |
logging.warning(f"{src_target_file} が存在しません。")
|
55 |
else:
|
56 |
-
# コピー先を一旦削除してからコピー
|
57 |
if os.path.exists(dest_pages):
|
58 |
shutil.rmtree(dest_pages, onerror=remove_readonly)
|
59 |
shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)
|
@@ -77,12 +74,27 @@ def clone_or_update_repo():
|
|
77 |
f.write(new_content)
|
78 |
logging.info("置換が完了しました。")
|
79 |
|
80 |
-
#
|
81 |
os.makedirs("templates", exist_ok=True)
|
82 |
shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")
|
83 |
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# スケジューラを実行する関数(1分ごと)
|
88 |
def run_scheduler():
|
|
|
32 |
os.chmod(path, stat.S_IWRITE)
|
33 |
func(path)
|
34 |
|
|
|
35 |
def clone_or_update_repo():
|
36 |
logging.info("リポジトリの更新を開始します。")
|
37 |
|
|
|
45 |
if result.stderr:
|
46 |
logging.error(result.stderr)
|
47 |
|
|
|
48 |
src_target_file = os.path.join(REPO_DIR, "pages", "startup.js")
|
49 |
dest_pages = os.path.join("static", "pages")
|
50 |
|
51 |
if not os.path.exists(src_target_file):
|
52 |
logging.warning(f"{src_target_file} が存在しません。")
|
53 |
else:
|
|
|
54 |
if os.path.exists(dest_pages):
|
55 |
shutil.rmtree(dest_pages, onerror=remove_readonly)
|
56 |
shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)
|
|
|
74 |
f.write(new_content)
|
75 |
logging.info("置換が完了しました。")
|
76 |
|
77 |
+
# index.html をコピー
|
78 |
os.makedirs("templates", exist_ok=True)
|
79 |
shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")
|
80 |
|
81 |
+
# ここで <base href="..."> を削除
|
82 |
+
index_path = os.path.join("templates", "index.html")
|
83 |
+
with open(index_path, "r", encoding="utf-8") as f:
|
84 |
+
html = f.read()
|
85 |
+
|
86 |
+
import re
|
87 |
+
# <base href="https://sharkpools-extensions.vercel.app/"> を削除
|
88 |
+
new_html = re.sub(r'<base\s+href="https://sharkpools-extensions\.vercel\.app/"\s*/?>', '', html, flags=re.IGNORECASE)
|
89 |
|
90 |
+
if html == new_html:
|
91 |
+
logging.warning("<base href=...> タグが見つかりませんでした。")
|
92 |
+
else:
|
93 |
+
with open(index_path, "w", encoding="utf-8") as f:
|
94 |
+
f.write(new_html)
|
95 |
+
logging.info("<base href=...> タグの削除が完了しました。")
|
96 |
+
|
97 |
+
logging.info("リポジトリの更新が完了しました。")
|
98 |
|
99 |
# スケジューラを実行する関数(1分ごと)
|
100 |
def run_scheduler():
|