Spaces:
Runtime error
Runtime error
魏然
commited on
Commit
·
e80fd1f
1
Parent(s):
49755ec
魏然 首次上传于 2024/04/13
Browse files- __pycache__/task_plan.cpython-38.pyc +0 -0
- app.py +203 -0
- locales/en-US.json +21 -0
- locales/ja-JP.json +21 -0
- locales/ko-KR.json +21 -0
- locales/th-TH.json +21 -0
- locales/zh-CN.json +21 -0
- repo_pull.py +66 -0
- task_plan.py +7 -0
__pycache__/task_plan.cpython-38.pyc
ADDED
Binary file (512 Bytes). View file
|
|
app.py
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import gradio as gr
|
3 |
+
import json
|
4 |
+
from textwrap import dedent
|
5 |
+
from task_plan import task_plan_list
|
6 |
+
import subprocess
|
7 |
+
from datetime import datetime
|
8 |
+
|
9 |
+
|
10 |
+
def read_specific_line(file_path, line_number):
|
11 |
+
try:
|
12 |
+
with open(file_path, 'r') as file:
|
13 |
+
for current_line, line in enumerate(file, start=1):
|
14 |
+
if current_line == line_number:
|
15 |
+
return line.strip()
|
16 |
+
return None # 如果文件不足指定的行数,返回None
|
17 |
+
except FileNotFoundError:
|
18 |
+
return None # 如果文件不存在,返回None
|
19 |
+
|
20 |
+
|
21 |
+
def get_folder_paths(file_path):
|
22 |
+
source_folder = read_specific_line(file_path, 2)
|
23 |
+
target_folder = read_specific_line(file_path, 3)
|
24 |
+
|
25 |
+
if source_folder is None or target_folder is None:
|
26 |
+
return "错误信息:文件不存在。", None, None
|
27 |
+
elif source_folder == "" or target_folder == "":
|
28 |
+
return "错误信息:文件中的第2行或第3行为空。", None, None
|
29 |
+
else:
|
30 |
+
return None, source_folder, target_folder
|
31 |
+
|
32 |
+
|
33 |
+
def read_specific_line(file_path, line_number):
|
34 |
+
with open(file_path, "r") as file:
|
35 |
+
for i, line in enumerate(file, 1):
|
36 |
+
if i == line_number:
|
37 |
+
return line.strip()
|
38 |
+
|
39 |
+
|
40 |
+
def repo_pull(url):
|
41 |
+
# 从远程仓库拉取代码的操作
|
42 |
+
subprocess.check_output(["python3", "repo_pull.py", "--repo_url",
|
43 |
+
str(url).replace(".git", "").replace("git", "").replace("clone", "").replace(" ",
|
44 |
+
"")])
|
45 |
+
yield
|
46 |
+
|
47 |
+
|
48 |
+
# 将代码推送到远程仓库的操作
|
49 |
+
def repo_push(hf_repo_id, tmp1, tmp2, tmp3, tmp4, select_task_plan):
|
50 |
+
task_plan_index = list(task_plan_list.keys()).index(select_task_plan)
|
51 |
+
if task_plan_index >= 0 and task_plan_index <= 5:
|
52 |
+
if task_plan_index == 0:
|
53 |
+
# 克隆目标仓库到本地
|
54 |
+
subprocess.check_output(["python3", "repo_pull.py", "--repo_url",
|
55 |
+
str(hf_repo_id).replace(".git", "").replace("git", "").replace("clone",
|
56 |
+
"").replace(" ",
|
57 |
+
"")])
|
58 |
+
|
59 |
+
# # 打开文件并读取第2行数据
|
60 |
+
file_path = ".folderinfo"
|
61 |
+
# # 读取指定行数的数据
|
62 |
+
# source_folder = read_specific_line(file_path, 1)
|
63 |
+
# target_folder = read_specific_line(file_path, 2)
|
64 |
+
|
65 |
+
error, source_folder, target_folder = get_folder_paths(file_path)
|
66 |
+
|
67 |
+
if error:
|
68 |
+
print(error) # 这将打印出错误信息
|
69 |
+
else:
|
70 |
+
print(f"源文件夹: {source_folder}")
|
71 |
+
print(f"目标文件夹: {target_folder}")
|
72 |
+
|
73 |
+
# 获取当前日期和时间
|
74 |
+
current_datetime = datetime.now()
|
75 |
+
# 格式化日期和时间
|
76 |
+
|
77 |
+
formatted_datetime = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
|
78 |
+
commit_message = f"魏然 首次上传于 {formatted_datetime}"
|
79 |
+
# subprocess.check_output(
|
80 |
+
# f"cd {target_folder} && cp -rf ../{str(source_folder).replace('./', '')}/* . && git add -A . && git commit -m \"{commit_message}\"",
|
81 |
+
# shell=True)
|
82 |
+
|
83 |
+
|
84 |
+
elif task_plan_index == 1:
|
85 |
+
print("选中了 1")
|
86 |
+
elif task_plan_index == 2:
|
87 |
+
print("选中了 2")
|
88 |
+
elif task_plan_index == 3:
|
89 |
+
print("选中了 3")
|
90 |
+
elif task_plan_index == 4:
|
91 |
+
print("选中了 4")
|
92 |
+
else:
|
93 |
+
print("选中了 5")
|
94 |
+
else:
|
95 |
+
print("task_plan_index 不在范围内")
|
96 |
+
|
97 |
+
yield
|
98 |
+
|
99 |
+
|
100 |
+
# 更新进度
|
101 |
+
def load_set(wisemodel_link, hf_repo_id, tmp1, tmp2, tmp3, tmp4, select_task_plan, progress=gr.Progress()):
|
102 |
+
tasks = [repo_pull(wisemodel_link),
|
103 |
+
repo_push(hf_repo_id, tmp1, tmp2, tmp3, tmp4, select_task_plan)] # 将 repo_pull 和 repo_push 添加到任务列表中
|
104 |
+
total_tasks = len(tasks)
|
105 |
+
for i, task in enumerate(tasks, start=1):
|
106 |
+
progress(i / total_tasks, desc=f"{i} / {total_tasks} ")
|
107 |
+
for _ in task:
|
108 |
+
pass
|
109 |
+
return "下载完成!"
|
110 |
+
|
111 |
+
|
112 |
+
# 创建解析命令行参数的函数
|
113 |
+
def parse_args():
|
114 |
+
parser = argparse.ArgumentParser()
|
115 |
+
parser.add_argument("--language", type=str, default="zh-CN",
|
116 |
+
help="Language option, e.g., 'en-US' or 'zh-CN' or ja-JP or ko-KR or th-TH support now!")
|
117 |
+
return parser.parse_args()
|
118 |
+
|
119 |
+
|
120 |
+
# 加载语言对应的JSON文件
|
121 |
+
def load_language_json(language):
|
122 |
+
filename = f"locales/{language}.json"
|
123 |
+
try:
|
124 |
+
with open(filename, "r", encoding="utf-8") as file:
|
125 |
+
return json.load(file)
|
126 |
+
except FileNotFoundError:
|
127 |
+
print(f"Error: File '{filename}' not found.")
|
128 |
+
return {}
|
129 |
+
|
130 |
+
|
131 |
+
# 加载JSON以支持国际化
|
132 |
+
args = parse_args()
|
133 |
+
language_json = load_language_json(args.language)
|
134 |
+
|
135 |
+
# # 获取对应语言的文本信息
|
136 |
+
info = language_json.get("info", {})
|
137 |
+
_title = info.get("page_title", {})
|
138 |
+
_about = info.get("about", {})
|
139 |
+
_wisemodel_lable_title = info.get("wisemodel_lable_title", {})
|
140 |
+
_hf_repo_id_title = info.get("hf_repo_id_title", {})
|
141 |
+
_button = info.get("button", {})
|
142 |
+
_clear = info.get("clear", {})
|
143 |
+
_setting = info.get("setting", {})
|
144 |
+
_HuggingFace_Token_title = info.get("HuggingFace_Token_title", {})
|
145 |
+
_HuggingFace_Token_placeholder = info.get("HuggingFace_Token_placeholder", {})
|
146 |
+
_WiseModel_Token_title = info.get("WiseModel_Token_title", {})
|
147 |
+
_WiseModel_Token_placeholder = info.get("WiseModel_Token_placeholder", {})
|
148 |
+
_Logs = info.get("Logs", {})
|
149 |
+
_task_plan = info.get("task_plan", {})
|
150 |
+
_source_user_id = info.get("source_user_id", {})
|
151 |
+
_target_user_id = info.get("target_user_id", {})
|
152 |
+
_source_user_placeholder = info.get("source_user_placeholder", {})
|
153 |
+
_target_user_placeholder = info.get("target_user_placeholder", {})
|
154 |
+
#
|
155 |
+
with gr.Blocks(title=_title, theme=gr.themes.Soft(text_size="sm")) as demo:
|
156 |
+
with gr.Accordion("📒 " + _about, open=False):
|
157 |
+
_ = f""" 这个空间适用于将 WiseModel 仓库同步转移到 Hugging Face 仓库。\n
|
158 |
+
**请首先确保你是仓库的所有者或者拥有者同意你这样做!**\n
|
159 |
+
# 如何使用这个空间?\n
|
160 |
+
- 复制这个空间并提供 WiseModel token(可选)和你的 读/写 HF token(必填)\n
|
161 |
+
- 在Hugging Face上创建你的目标模型仓库。这一步需要手动完成,空间不会为你创建一个空的仓库。\n
|
162 |
+
- 在你自己的私有空间中填写以下信息。\n
|
163 |
+
- 点击提交按钮,然后观察日志中的输出进展。\n
|
164 |
+
- 重新创建修改自己的 README.md 文件(因为元数据与 HF 不兼容)
|
165 |
+
"""
|
166 |
+
gr.Markdown(dedent(_))
|
167 |
+
|
168 |
+
wisemodel_link = gr.Textbox(label=_wisemodel_lable_title)
|
169 |
+
hf_repo_id = gr.Textbox(
|
170 |
+
label=_hf_repo_id_title)
|
171 |
+
with gr.Accordion("🔧 " + _setting, open=False):
|
172 |
+
with gr.Column(scale=12):
|
173 |
+
select_task_plan = gr.Dropdown(choices=list(task_plan_list.keys()), allow_custom_value=True, value="",
|
174 |
+
label=_task_plan)
|
175 |
+
with gr.Row():
|
176 |
+
tmp1 = gr.Textbox(
|
177 |
+
label=_HuggingFace_Token_title,
|
178 |
+
placeholder=_HuggingFace_Token_placeholder,
|
179 |
+
type="password", # 设置为密码类型,不显示明文
|
180 |
+
)
|
181 |
+
tmp2 = gr.Textbox(
|
182 |
+
label=_WiseModel_Token_title,
|
183 |
+
placeholder=_WiseModel_Token_placeholder,
|
184 |
+
type="password", # 设置为密码类型,不显示明文
|
185 |
+
)
|
186 |
+
with gr.Row():
|
187 |
+
tmp3 = gr.Textbox(
|
188 |
+
label=_source_user_id,
|
189 |
+
placeholder=_source_user_placeholder,
|
190 |
+
)
|
191 |
+
tmp4 = gr.Textbox(
|
192 |
+
label=_target_user_id,
|
193 |
+
placeholder=_target_user_placeholder,
|
194 |
+
)
|
195 |
+
with gr.Row():
|
196 |
+
with gr.Column(scale=100):
|
197 |
+
button = gr.Button(_button, variant="primary")
|
198 |
+
with gr.Column(scale=1):
|
199 |
+
clear = gr.Button(_clear)
|
200 |
+
output = gr.Textbox(label=_Logs)
|
201 |
+
button.click(load_set, [wisemodel_link, hf_repo_id, tmp1, tmp2, tmp3, tmp4, select_task_plan], [output])
|
202 |
+
if __name__ == "__main__":
|
203 |
+
demo.launch(show_error=True, share=True, server_name="0.0.0.0", server_port=7860, debug=True)
|
locales/en-US.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"info": {
|
3 |
+
"page_title": "GitSync Master",
|
4 |
+
"about": "About",
|
5 |
+
"wisemodel_lable_title": "Paste your [Source] repository address here:",
|
6 |
+
"hf_repo_id_title": "Paste your [Target] repository address here:",
|
7 |
+
"button": "Clone",
|
8 |
+
"clear": "\uD83D\uDDD1\uFE0F Clear",
|
9 |
+
"setting": "More Settings",
|
10 |
+
"HuggingFace_Token_title": "[Source] Repository Token:",
|
11 |
+
"HuggingFace_Token_placeholder": "Enter your [Source] repository access token here, if you don't have one, create it by logging into the source repository!",
|
12 |
+
"WiseModel_Token_title": "[Target] Repository Token:",
|
13 |
+
"WiseModel_Token_placeholder": "Enter your [Target] repository access token here, if you don't have one, create it by logging into the target repository!",
|
14 |
+
"Logs": "Logs",
|
15 |
+
"task_plan": "Please select a task plan",
|
16 |
+
"source_user_placeholder": "Enter the source repository account here",
|
17 |
+
"target_user_placeholder": "Enter the target repository account here",
|
18 |
+
"source_user_id": "[Source] Repository Account:",
|
19 |
+
"target_user_id": "[Target] Repository Account:"
|
20 |
+
}
|
21 |
+
}
|
locales/ja-JP.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"info": {
|
3 |
+
"page_title": "GitSync Master",
|
4 |
+
"about": "約",
|
5 |
+
"wisemodel_lable_title": "ここにあなたの[ソース]リポジトリのアドレスを貼り付けてください:",
|
6 |
+
"hf_repo_id_title": "ここにあなたの[ターゲット]リポジトリのアドレスを貼り付けてください:",
|
7 |
+
"button": "クローン",
|
8 |
+
"clear": "\uD83D\uDDD1\uFE0F クリア",
|
9 |
+
"setting": "さらなる設定",
|
10 |
+
"HuggingFace_Token_title": "[ソース]リポジトリトークン:",
|
11 |
+
"HuggingFace_Token_placeholder": "[ソース]リポジトリのアクセストークンをここに入力してください。お持ちでない場合は、ソースリポジトリにログインして作成してください!",
|
12 |
+
"WiseModel_Token_title": "[ターゲット]リポジトリトークン:",
|
13 |
+
"WiseModel_Token_placeholder": "[ターゲット]リポジトリのアクセストークンをここに入力してください。お持ちでない場合は、ターゲットリポジトリにログインして作成してください!",
|
14 |
+
"Logs": "ログ",
|
15 |
+
"task_plan": "タスクプランを選択してください",
|
16 |
+
"source_user_placeholder": "ここにソースリポジトリアカウントを入力してください",
|
17 |
+
"target_user_placeholder": "ここにターゲットリポジトリアカウントを入力してください",
|
18 |
+
"source_user_id": "[ソース]リポジトリアカウント:",
|
19 |
+
"target_user_id": "[ターゲット]リポジトリアカウント:"
|
20 |
+
}
|
21 |
+
}
|
locales/ko-KR.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"info": {
|
3 |
+
"page_title": "GitSync Master",
|
4 |
+
"about": "소개",
|
5 |
+
"wisemodel_lable_title": "여기에 귀하의 [소스] 저장소 주소를 붙여 넣으십시오:",
|
6 |
+
"hf_repo_id_title": "여기에 귀하의 [대상] 저장소 주소를 붙여 넣으십시오:",
|
7 |
+
"button": "복제",
|
8 |
+
"clear": "\uD83D\uDDD1\uFE0F 지우기",
|
9 |
+
"setting": "추가 설정",
|
10 |
+
"HuggingFace_Token_title": "[소스] 저장소 토큰:",
|
11 |
+
"HuggingFace_Token_placeholder": "여기에 귀하의 [소스] 저장소 액세스 토큰을 입력하십시오. 토큰이 없는 경우 소스 저장소에 로그인하여 생성하십시오!",
|
12 |
+
"WiseModel_Token_title": "[대상] 저장소 토큰:",
|
13 |
+
"WiseModel_Token_placeholder": "여기에 귀하의 [대상] 저장소 액세스 토큰을 입력하십시오. 토큰이 없는 경우 대상 저장소에 로그인하여 생성하십시오!",
|
14 |
+
"Logs": "로그",
|
15 |
+
"task_plan": "작업 계획을 선택하십시오",
|
16 |
+
"source_user_placeholder": "소스 저장소 계정을 여기에 입력하십시오",
|
17 |
+
"target_user_placeholder": "대상 저장소 계정을 여기에 입력하십시오",
|
18 |
+
"source_user_id": "[소스] 저장소 계정:",
|
19 |
+
"target_user_id": "[대상] 저장소 계정:"
|
20 |
+
}
|
21 |
+
}
|
locales/th-TH.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"info": {
|
3 |
+
"page_title": "GitSync Master",
|
4 |
+
"about": "เกี่ยวกับ",
|
5 |
+
"wisemodel_lable_title": "วางที่อยู่เฉพาะของคุณ [Source] ที่นี่:",
|
6 |
+
"hf_repo_id_title": "วางที่อยู่เฉพาะของคุณ [Target] ที่นี่:",
|
7 |
+
"button": "โคลน",
|
8 |
+
"clear": "\uD83D\uDDD1\uFE0F ล้าง",
|
9 |
+
"setting": "การตั้งค่าเพิ่มเติม",
|
10 |
+
"HuggingFace_Token_title": "โทเค็นเข้าถึง[Source] ที่นี่:",
|
11 |
+
"HuggingFace_Token_placeholder": "ป้อนโทเค็นเข้าถึง [Source] ที่นี่ หากคุณไม่มี ให้สร้างโดยเข้าสู่ระบบที่เกี่ยวข้อง!",
|
12 |
+
"WiseModel_Token_title": "โทเค็นเข้าถึง[Target] ที่นี่:",
|
13 |
+
"WiseModel_Token_placeholder": "ป้อนโทเค็นเข้าถึง [Target] ที่นี่ หากคุณไม่มี ให้สร้างโดยเข้าสู่ระบบที่เกี่ยวข้อง!",
|
14 |
+
"Logs": "บันทึก",
|
15 |
+
"task_plan": "กรุณาเลือกแผนงานงาน",
|
16 |
+
"source_user_placeholder": "ป้อนบัญชีที่เกี่ยวข้องกับ Source ที่นี่",
|
17 |
+
"target_user_placeholder": "ป้อนบัญชีที่เกี่ยวข้องกับ Target ที่นี่",
|
18 |
+
"source_user_id": "บัญชี[Source] ที่นี่:",
|
19 |
+
"target_user_id": "บัญชี[Target] ที่นี่:"
|
20 |
+
}
|
21 |
+
}
|
locales/zh-CN.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"info": {
|
3 |
+
"page_title": "GitSync Master",
|
4 |
+
"about": "相关信息",
|
5 |
+
"wisemodel_lable_title": "此处粘贴你的(模型/数据集/代码)[源] 仓库地址:",
|
6 |
+
"hf_repo_id_title": "此处粘贴你的(模型/数据集/代码)[目标] 仓库地址:",
|
7 |
+
"button": "克隆",
|
8 |
+
"clear": "\uD83D\uDDD1\uFE0F 清空",
|
9 |
+
"setting": "更多设置",
|
10 |
+
"HuggingFace_Token_title": "[源] 仓库令牌:",
|
11 |
+
"HuggingFace_Token_placeholder": "此处输入 [源] 仓库访问令牌,如果没有自行登陆源仓库创建一个!",
|
12 |
+
"WiseModel_Token_title": "[目标] 仓库令牌:",
|
13 |
+
"WiseModel_Token_placeholder": "此处输入 [目标] 仓库访问令牌,如果没有自行登陆目标仓库创建一个!",
|
14 |
+
"Logs": "日志",
|
15 |
+
"task_plan": "请选择一个任务方案",
|
16 |
+
"source_user_placeholder": "在这里输入源仓库账号",
|
17 |
+
"target_user_placeholder": "在这里输入目标仓库账号",
|
18 |
+
"source_user_id": "[源]仓库账号:",
|
19 |
+
"target_user_id": "[目标]仓库账号:"
|
20 |
+
}
|
21 |
+
}
|
repo_pull.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
import sys
|
4 |
+
import hashlib
|
5 |
+
import random
|
6 |
+
import string
|
7 |
+
|
8 |
+
|
9 |
+
def get_file_count(repo_path):
|
10 |
+
# 使用git命令获取仓库中的文件数量
|
11 |
+
result = subprocess.run(['git', 'ls-files'], cwd=repo_path, capture_output=True, text=True)
|
12 |
+
files = result.stdout.split('\n')
|
13 |
+
# 过滤掉空字符串
|
14 |
+
files = list(filter(None, files))
|
15 |
+
return len(files)
|
16 |
+
|
17 |
+
|
18 |
+
def generate_random_string(length):
|
19 |
+
# 生成随机字符串
|
20 |
+
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length))
|
21 |
+
|
22 |
+
|
23 |
+
def clone_repository_without_progress(repo_url):
|
24 |
+
# 生成随机的目标路径
|
25 |
+
destination_path = "./" + generate_random_string(6)
|
26 |
+
|
27 |
+
# 克隆仓库
|
28 |
+
try:
|
29 |
+
subprocess.run(['git', 'clone', '--recursive', repo_url, destination_path], check=True)
|
30 |
+
print("Repository cloned successfully!")
|
31 |
+
except Exception as e:
|
32 |
+
print(f"An error occurred while cloning the repository: {e}")
|
33 |
+
return
|
34 |
+
|
35 |
+
# 获取文件总数
|
36 |
+
total_files = get_file_count(destination_path)
|
37 |
+
|
38 |
+
# 遍历仓库中的文件,不再显示进度条
|
39 |
+
for root, dirs, files in os.walk(destination_path):
|
40 |
+
for file in files:
|
41 |
+
pass
|
42 |
+
|
43 |
+
# 获取第一层文件夹名字
|
44 |
+
first_layer_folder = os.path.basename(destination_path)
|
45 |
+
# 使用哈希值作为新文件夹名
|
46 |
+
folder_hash = hashlib.md5(first_layer_folder.encode()).hexdigest()[:6]
|
47 |
+
new_folder_name = f"{folder_hash}"
|
48 |
+
new_folder_path = os.path.join(os.path.dirname(destination_path), new_folder_name)
|
49 |
+
# 重命名第一层文件夹
|
50 |
+
os.rename(destination_path, new_folder_path)
|
51 |
+
# 记录文件夹路径
|
52 |
+
with open('.folderinfo', 'a') as f:
|
53 |
+
f.write(new_folder_path + '\n')
|
54 |
+
|
55 |
+
|
56 |
+
if __name__ == "__main__":
|
57 |
+
if len(sys.argv) != 3:
|
58 |
+
print("Usage: python3 script.py --repo_url <repository_url>")
|
59 |
+
sys.exit(1)
|
60 |
+
|
61 |
+
if sys.argv[1] != "--repo_url":
|
62 |
+
print("Usage: python3 script.py --repo_url <repository_url>")
|
63 |
+
sys.exit(1)
|
64 |
+
|
65 |
+
repo_url = sys.argv[2]
|
66 |
+
clone_repository_without_progress(repo_url)
|
task_plan.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
task_plan_list = {'[源]huggingface.co 到 [目标]wisemodel.cn': 'HF2WM',
|
2 |
+
'[源]wisemodel.cn 到 [目标]huggingface.co': 'WM2HF',
|
3 |
+
'[源]github.com 到 [目标]huggingface.co': 'GIT2HF',
|
4 |
+
'[源]huggingface.co 到 [目标]github.com': 'HF2GITHUB',
|
5 |
+
'[源]github.com 到 [目标]gitee.cn': 'GITHUB2GITEE',
|
6 |
+
'[源]gitee.cn 到 [目标]github.com': 'GITEE2GITHUB',
|
7 |
+
}
|