forked from adysec/nuclei_poc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-clone_repos.py
48 lines (43 loc) · 1.52 KB
/
1-clone_repos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
repo_file = "repo.csv"
clone_dir = "clone-templates"
# 确保克隆目录存在
try:
os.makedirs(clone_dir, exist_ok=True)
except OSError as e:
print(f"创建目录 {clone_dir} 时出错: {e}")
exit(1)
# 读取并处理仓库文件中的URL
try:
with open(repo_file, 'r') as file:
urls = list(set(line.strip() for line in file if line.strip()))
except FileNotFoundError:
print(f"文件 {repo_file} 未找到。")
exit(1)
except Exception as e:
print(f"读取文件 {repo_file} 时出错: {e}")
exit(1)
for url in urls:
parts = url.split('/')
if len(parts) >= 2:
owner, repo_name = parts[-2], parts[-1]
target_dir = os.path.join(clone_dir, f"{owner}/{repo_name}".lower())
else:
print(f"无效的URL格式: {url}")
continue
if os.path.isdir(target_dir):
print(f"更新 {repo_name} 在 {target_dir}")
try:
result = os.system(f"git -C {target_dir} pull")
if result != 0:
print(f"更新仓库 {repo_name} 在 {target_dir} 时出错")
except Exception as e:
print(f"更新仓库 {repo_name} 在 {target_dir} 时出错: {e}")
else:
print(f"克隆 {repo_name} 到 {target_dir}")
try:
result = os.system(f"git clone {url} {target_dir}")
if result != 0:
print(f"克隆仓库 {repo_name} 到 {target_dir} 时出错")
except Exception as e:
print(f"克隆仓库 {repo_name} 到 {target_dir} 时出错: {e}")