This repository has been archived by the owner on Nov 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.py
executable file
·67 lines (58 loc) · 2.05 KB
/
install.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
#!/usr/bin/env python
import os
import sys
import json
import fnmatch
import shutil
import platform
cwd = os.getcwd()
meta = json.load(open(os.path.join(cwd, "theme.json")))
def globPath(path, pattern):
result = []
for root, subdirs, files in os.walk(path):
for filename in files:
if fnmatch.fnmatch(filename, pattern):
result.append(os.path.join(root, filename))
return result
def handleFile(inpath, outpath, themdir):
parentdir = os.path.abspath(os.path.join(outpath, os.pardir))
if not os.path.isdir(parentdir):
os.makedirs(parentdir)
if os.path.isfile(inpath):
if not inpath.endswith(".tres"):
shutil.copy(inpath, parentdir)
return
else:
content = open(inpath).read()
content = content.replace("res://addons", themdir)
outfile = open(outpath, 'w')
outfile.write(content)
outfile.flush()
def install(path):
for theme in meta["themes"]:
print("Installing theme {} to {}".format(theme['name'], path))
if not os.path.isdir(path):
os.makedirs(path)
for p in globPath(theme['dir'], "*"):
op = os.path.abspath(os.path.join(
path, theme["name"], os.path.relpath(p, theme['dir'])))
handleFile(p, op, path)
print("Done!")
if __name__ == '__main__':
if len(sys.argv) <= 2:
osname = platform.system()
defaultdir = None
if osname == "Linux" or osname == "Darwin":
defaultdir = os.path.join(os.path.expanduser("~"), ".godot/theme")
elif osname == "Windows":
defaultdir = os.path.join(os.path.expanduser("~"), "AppData/Roaming/Godot/theme").replace("\\", "/")
if defaultdir:
install(defaultdir)
else:
print("Error: Unknown OS detected: {}.".format(osname))
else:
path = sys.argv[1]
if os.path.isdir(path):
install(path.replace("\\", "/"))
else:
print("Error: Directoy {} not found.".format(path))