-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
executable file
·71 lines (55 loc) · 1.7 KB
/
deploy.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
#!/usr/bin/env python3
""" Factorio mod deploy script """
import os
import sys
import shutil
import glob
import zipfile
import json
## Configuration Section
mod_name = "Landmarks"
deploy_mod = True
##Get version from info.json
version = ""
with open("info.json") as info:
version = json.load(info)["version"]
print ("Found version " + version + ".")
if (version == ""):
print ("No version found. Aborting")
sys.exit(-1)
directory = mod_name + "_" + version
if not os.path.exists(directory):
os.makedirs(directory)
print ("Directory " + directory + " created.")
else:
print ("Directory " + directory + " already exists. Aborting...")
sys.exit(-2)
os.chdir('src')
print(os.getcwd())
for file in glob.glob('**/*.lua', recursive=True):
print ("Copying " + file + "...")
sub_dirs = os.path.split(file)[0]
print(sub_dirs)
if len(sub_dirs) > 0:
os.makedirs('..' + os.sep + directory + os.sep + sub_dirs, exist_ok=True)
shutil.copy(file, '..' + os.sep + directory + os.sep + file)
os.chdir('..')
print ("Copying locales")
shutil.copytree("locale", directory + "/locale")
print ("Copying info.json")
shutil.copy("info.json", directory)
print ("Creating zipfile...")
zipname = directory + '.zip'
zipf = zipfile.ZipFile(directory + '.zip', 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(directory):
for file in files:
zipf.write(os.path.join(root, file))
zipf.close()
print ("Removing directory...")
shutil.rmtree(directory)
print ("Release " + version + " completed.")
if deploy_mod:
destination = '/home/jgay/.factorio/mods/' + zipname
if os.path.exists(destination):
os.remove(destination)
shutil.move(zipname, destination)