Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,28 +6,18 @@ import subprocess
|
|
6 |
import os
|
7 |
import shutil
|
8 |
|
9 |
-
|
10 |
-
REPO_DIR = "SharkPools-Extensions"
|
11 |
-
TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js")
|
12 |
-
|
13 |
-
app = Flask(__name__, template_folder="templates", static_folder="static")
|
14 |
-
|
15 |
-
@app.route("/")
|
16 |
-
def index():
|
17 |
-
return render_template("index.html")
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
def clone_or_update_repo():
|
24 |
if not os.path.exists(REPO_DIR):
|
25 |
subprocess.run(["git", "clone", REPO_URL])
|
26 |
-
|
27 |
else:
|
28 |
subprocess.run(["git", "-C", REPO_DIR, "pull"])
|
29 |
|
30 |
-
# startup.js の文字列置換
|
31 |
if os.path.exists(TARGET_FILE):
|
32 |
with open(TARGET_FILE, "r", encoding="utf-8") as f:
|
33 |
content = f.read()
|
@@ -35,17 +25,30 @@ def clone_or_update_repo():
|
|
35 |
with open(TARGET_FILE, "w", encoding="utf-8") as f:
|
36 |
f.write(new_content)
|
37 |
|
38 |
-
# templates フォルダ作成と index.html コピー
|
39 |
os.makedirs("templates", exist_ok=True)
|
40 |
shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")
|
41 |
|
42 |
-
# static/pages を作成してコピー
|
43 |
dest_pages = os.path.join("static", "pages")
|
44 |
if os.path.exists(dest_pages):
|
45 |
-
shutil.rmtree(dest_pages)
|
46 |
os.makedirs("static", exist_ok=True)
|
47 |
shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
def run_scheduler():
|
50 |
schedule.every().day.at("00:00").do(clone_or_update_repo)
|
51 |
while True:
|
|
|
6 |
import os
|
7 |
import shutil
|
8 |
|
9 |
+
import stat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
def remove_readonly(func, path, excinfo):
|
12 |
+
os.chmod(path, stat.S_IWRITE)
|
13 |
+
func(path)
|
14 |
|
15 |
def clone_or_update_repo():
|
16 |
if not os.path.exists(REPO_DIR):
|
17 |
subprocess.run(["git", "clone", REPO_URL])
|
|
|
18 |
else:
|
19 |
subprocess.run(["git", "-C", REPO_DIR, "pull"])
|
20 |
|
|
|
21 |
if os.path.exists(TARGET_FILE):
|
22 |
with open(TARGET_FILE, "r", encoding="utf-8") as f:
|
23 |
content = f.read()
|
|
|
25 |
with open(TARGET_FILE, "w", encoding="utf-8") as f:
|
26 |
f.write(new_content)
|
27 |
|
|
|
28 |
os.makedirs("templates", exist_ok=True)
|
29 |
shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")
|
30 |
|
|
|
31 |
dest_pages = os.path.join("static", "pages")
|
32 |
if os.path.exists(dest_pages):
|
33 |
+
shutil.rmtree(dest_pages, onerror=remove_readonly)
|
34 |
os.makedirs("static", exist_ok=True)
|
35 |
shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)
|
36 |
|
37 |
+
|
38 |
+
REPO_URL = "https://github.com/SharkPool-SP/SharkPools-Extensions.git"
|
39 |
+
REPO_DIR = "SharkPools-Extensions"
|
40 |
+
TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js")
|
41 |
+
|
42 |
+
app = Flask(__name__, template_folder="templates", static_folder="static")
|
43 |
+
|
44 |
+
@app.route("/")
|
45 |
+
def index():
|
46 |
+
return render_template("index.html")
|
47 |
+
|
48 |
+
@app.route('/static/<path:filename>')
|
49 |
+
def serve_static(filename):
|
50 |
+
return send_from_directory(app.static_folder, filename)
|
51 |
+
|
52 |
def run_scheduler():
|
53 |
schedule.every().day.at("00:00").do(clone_or_update_repo)
|
54 |
while True:
|