forked from L0laapk3/FactorioMaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateLib.py
82 lines (54 loc) · 2.11 KB
/
updateLib.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
70
71
72
73
74
75
76
77
78
79
80
81
82
from shutil import rmtree, copytree
import os
from urllib.parse import urlparse
from urllib.request import urlretrieve, build_opener, install_opener
from tempfile import gettempdir
urlList = (
"https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-src.min.js",
"https://cdn.jsdelivr.net/npm/[email protected]/Control.FullScreen.css",
"https://cdn.jsdelivr.net/npm/[email protected]/Control.FullScreen.min.js",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js",
"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
"https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js",
"https://cdn.jsdelivr.net/gh/L0laapk3/Leaflet.OpacityControls@2/Control.Opacity.css",
"https://cdn.jsdelivr.net/gh/L0laapk3/Leaflet.OpacityControls@2/Control.Opacity.js",
"https://cdn.jsdelivr.net/npm/[email protected]/dist/naturalsort.min.js",
"https://factorio.com/static/img/favicon.ico",
)
CURRENTVERSION = 3
def update(Force=True):
targetPath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "web/lib")
if not Force:
try:
with open(os.path.join(targetPath, "VERSION"), "r") as f:
if f.readline() == str(CURRENTVERSION):
return False
except FileNotFoundError:
pass
tempPath = os.path.join(gettempdir(), "FactorioMapsTmpLib")
try:
rmtree(tempPath)
except (FileNotFoundError, NotADirectoryError):
pass
os.makedirs(tempPath, exist_ok=True)
opener = build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 U GUYS SUCK WHY ARE YOU BLOCKING Python-urllib')]
install_opener(opener)
for url in urlList:
print(f"downloading {url}")
urlretrieve(url, os.path.join(tempPath, os.path.basename(urlparse(url).path)))
try:
rmtree(targetPath)
except (FileNotFoundError, NotADirectoryError):
pass
copytree(tempPath, targetPath)
with open(os.path.join(targetPath, "VERSION"), "w") as f:
f.write(str(CURRENTVERSION))
try:
rmtree(tempPath)
except (FileNotFoundError, NotADirectoryError):
pass
return True
if __name__ == '__main__':
update(True)