-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_environment.py
69 lines (60 loc) · 1.82 KB
/
build_environment.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
65
66
67
68
69
import requests
import os
import sys
import shutil
need_files_idx = 0
cache = set()
garbage = set()
need_files = set()
current_dir = "../"+os.getcwd().split("/")[-1].split("\\")[-1]
def fetch_need_files(file_path):
global need_files
if file_path in need_files:
print(file_path +" has already been processed")
return
try:
if not os.path.exists(file_path):
return
need_files.add(file_path)
with open(file_path, "r") as f:
for line in f.readlines():
s = line.strip()
if len(s) == 0:
continue
single_file_path = "../" + s
fetch_single_file(single_file_path)
except Exception as err:
print(err)
def fetch_single_file(single_file_path):
global need_files_idx
global garbage
if single_file_path in cache:
print(single_file_path + " has already been fetched")
return
try:
splits = single_file_path.split('/')
dir_name = splits[1]
fetch_need_files("../"+dir_name+"/need_files.txt")
file_name = splits[-1]
flag = False
if file_name == "need_files.txt":
need_files_idx = need_files_idx + 1
file_name = file_name + str(need_files_idx)
flag = True
dst_path = current_dir + "/"+ file_name
shutil.copyfile(single_file_path, dst_path)
if flag:
garbage.add(dst_path)
fetch_need_files(dst_path)
cache.add(single_file_path)
except Exception as err:
print(err)
if __name__ =='__main__':
if len(sys.argv) >= 2:
base_url = sys.argv[1]
try:
fetch_need_files(current_dir + "/need_files.txt")
for f in garbage:
os.remove(f)
except Exception as err:
print(err)