-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_clone.py
64 lines (56 loc) · 1.81 KB
/
auto_clone.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import sys
import json
def read_json(in_path):
# in_list = list()
out_list = list()
with open(in_path, 'r') as f:
tmp_list = f.readlines()
for line in tmp_list:
line = line.strip('\n')
line_json = json.loads(line)
out_list.append(line_json)
return out_list
def get_repo_name(link):
link = link.replace('.git', '')
name = link.strip('/').split('/')[-1]
return name
if __name__ == '__main__':
if len(sys.argv) != 3:
print("wrong input")
print('Usage: python3 ./auto_clone.py <https_link_path> <out_dir>')
exit(1)
in_path = sys.argv[1]
out_dir = sys.argv[2]
out_log = out_dir + '/clone-log'
faild_log = out_dir + '/clong-faild-log'
in_list = read_json(in_path)
os.chdir(out_dir)
for item in in_list:
os.chdir(out_dir)
repo_link = item['github link']
commit_id = item['commit id']
repo_name = get_repo_name(repo_link)
cmd = 'git clone --recursive ' + repo_link
with open(out_log, 'a') as f:
f.write('Exec: ' + cmd + '\n')
re = os.system(cmd)
if not re:
with open(out_log, 'a') as f:
f.write('Success\n')
else:
item['faild_stage'] = 'clone'
with open(faild_log, 'a') as f:
f.write(item + '\n')
os.chdir(out_dir + '/' + repo_name)
cmd = 'git checkout ' + str(commit_id)
with open(out_log, 'a') as f:
f.write('Exec: ' + cmd + '\n')
re = os.system(cmd)
if not re:
with open(out_log, 'a') as f:
f.write('Success\n')
else:
item['faild_stage'] = 'checkout'
with open(faild_log, 'a') as f:
f.write(item + '\n')