From ff8f1f3555fca3e1aa013fdd08f22a5f9e50beac Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 14 Mar 2024 10:54:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=87=E4=BB=BD=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 run.py diff --git a/run.py b/run.py new file mode 100644 index 0000000..88d624a --- /dev/null +++ b/run.py @@ -0,0 +1,35 @@ +import os + +url = "http://192.168.137.66:3000/taynpg/" +backup_name = "gitea_backup" + +current_path = os.getcwd() +print("Current:" + current_path) +parent_path = os.path.dirname(current_path) +print("Parent:" + parent_path) +config_path = os.path.join(current_path, "repo_list.txt") + +if not os.path.exists(config_path): + print("repo_list.txt not found.") + exit() + +backup_path = os.path.join(parent_path, backup_name) +print("Backup Path:" + backup_path) + +if not os.path.exists(backup_path): + os.makedirs(backup_path) + +with open(config_path, "r", encoding="utf-8") as f: + content = f.readlines() + +for repo in content: + repo_name = repo.replace("\n", "") + purpose_dir = os.path.join(backup_path, repo_name) + if not os.path.exists(purpose_dir): + os.makedirs(purpose_dir) + cmd = "git clone " + url + repo_name + ".git" + cmd = cmd + " \"" + purpose_dir + "\"" + else: + cmd = "cd /d \"" + purpose_dir + "\" && git pull" + print(cmd) + os.system(cmd)