-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone_sources.py
More file actions
55 lines (40 loc) · 1.41 KB
/
clone_sources.py
File metadata and controls
55 lines (40 loc) · 1.41 KB
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
49
50
51
52
53
54
55
#!/bin/python3
import os
import sys
import time
from datetime import datetime
srcs = 'curseforge/source_urls.txt'
if not os.path.exists(srcs):
print('No sources')
sys.exit(1)
pairs = []
with open(srcs, 'r') as file:
for line in file:
slug = line.split(',')[0]
url = line[len(slug)+1:]
pairs.append((slug, url))
base_dir = os.getcwd()
def get_prefix(slug:str):
for c in slug:
if c.isalpha():
return c.lower()
return '0'
with open('curseforge/failed_sources.txt', 'w') as file:
for slug, url in pairs:
print(f'Downloading {slug} from {url.strip()}')
slug_dir = os.path.join(base_dir, f'curseforge/bucket/{get_prefix(slug)}/{slug}')
git_dir = os.path.join(slug_dir, f'{slug}/')
#if not os.path.exists(out_dir):
# os.mkdir(slug)
os.makedirs(os.path.dirname(git_dir), exist_ok=True)
#os.chdir(out_dir)
os.system(f'git clone --recursive --mirror "{url.strip()}" "{git_dir}"')
file_count = len(os.listdir(git_dir))
print('Number of files:', file_count)
date = datetime.now().strftime('%y%m%d')
os.system(f'7z a "{slug_dir}/{date}{slug}.7z" "{git_dir}" -y')
os.system(f'7z a "{slug_dir}/{slug}.tar" "{git_dir}" -ttar -y -sdel')
if file_count < 1:
file.write(f'{slug},{url}\n')
#input()
#os.chdir(base_dir)