Repository navigation
Expand file tree
/
Copy pathgetlibs_final.py
More file actions
104 lines (82 loc) · 2.81 KB
/
Copy pathgetlibs_final.py
File metadata and controls
104 lines (82 loc) · 2.81 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python3
# $1 is ~/getlibs2/getlibs3/test --- test folder that contains few files
# $2 is ~/getlibs2/getlibs3/ --- directory current directory
# $3 is 0
import sys
import os
import urllib.request
from urllib.request import urlretrieve
import urllib.error
from urllib.error import URLError
import shutil
from zipfile import ZipFile
if len(sys.argv) != 4:
print('Usage:')
print(" sys.argv[0] GIT_DIR INST_ABSOLUTE_TARGET OVERWRITE_CSS")
sys.exit(1)
else:
GIT_DIR = sys.argv[1]
libs = sys.argv[2]
LIB_DIR = libs + '/lib'
FORCE_CSS = sys.argv[3]
print("Downloading libs to web directory 'LIB_DIR' ")
CSSLIST = []
WEB = LIB_DIR
os.mkdir(WEB)
if os.access(WEB, os.W_OK) is not True:
print("Cannot write to WEB !")
sys.exit(1)
websites = []
filepath = "url.txt"
file = open(filepath)
pat = file.readlines()
for url in pat:
raw = url.strip()
websites.append(raw)
os.chdir(WEB)
errors = []
for website in websites:
if os.path.isfile(website.split('/')[-1]) is not True:
try:
wname = website.split('/')[-1]
res = urllib.request.urlretrieve(website, wname)
res
print(res)
except urllib.error.HTTPError as e:
print('raise HTTPError')
print(e.code)
errors.append(website)
except urllib.error.URLError as e:
print('raise URLError')
errors.append(website)
shutil.copy2(GIT_DIR + '/www-lib/treeviewer.js', os.getcwd())
shutil.copy2(GIT_DIR + '/www-lib/leaflet-phylogenscale.js', os.getcwd())
shutil.copy2(GIT_DIR + '/www-lib/leaflet-scrollbar.js', os.getcwd())
CSSLIST.append(GIT_DIR + '/www-lib/treeviewer.js')
CSSLIST.append(GIT_DIR + '/www-lib/leaflet-scrollbar.js')
for cssitm in CSSLIST:
cssfile = cssitm.split('/')[0]
if FORCE_CSS == 1:
shutil.rmtree(cssfile)
if os.path.isfile(cssfile) is not True:
shutil.copy2(cssitm, os.getcwd())
else:
sys.exit(1)
if os.path.isfile("jquery-1.11.3.min.js") is not True:
urllib.request.urlretrieve("http://code.jquery.com/jquery-1.11.3.min.js", 'jquery-1.11.3.min.js')
os.symlink("jquery-1.11.3.min.js", 'jquery.min.js')
if os.path.isfile("leaflet.js") is not True:
try:
urllib.request.urlretrieve("http://cdn.leafletjs.com/leaflet/v1.0.0-rc.2/leaflet.zip", 'leaflet.zip')
if os.path.isfile("leaflet.zip") is not True:
sys.exit(1)
else:
with ZipFile("leaflet.zip", 'r') as zipObj:
zipObj.extractall()
os.remove("leaflet.zip")
except urllib.error.HTTPError as e:
sys.exit(1)
for file in errors:
print("Download unsuccessful from " + file)
if len(errors) != 0:
sys.exit(1)