-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.py
More file actions
213 lines (175 loc) · 7.43 KB
/
export.py
File metadata and controls
213 lines (175 loc) · 7.43 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import os
import subprocess
import zipfile
import shutil
godot_path = 'godot.exe'
butler_path = 'butler.exe'
butler_game = 'melpeslier/florist-king'
# # Found under the Steam sdk > tools > ContentBuilder > builder
# steamcmd_path = 'steamcmd.exe'
# # Content folder you created under sdk > tools > ContentBuilder
# steam_content_path_win = ''
# steam_content_path_linux = ''
# # Steam app vdf file
# steam_app_script = ''
# steam_credentials_path = 'steam_credentials.txt'
build_path = '../../Godot Export/Game Name/'
game_name = 'game_name'
exe_name_windows = game_name + '.exe'
exe_name_linux = game_name + '.x86_64'
project_file = 'project.godot'
# Add all the templates you want here
# windows_template_steam = "Windows STEAM"
windows_template_itch = "Windows ITCH"
# linux_template_steam = "Linux STEAM"
linux_template_itch = "Linux ITCH"
templates = [windows_template_itch, linux_template_itch]
def parse_build_nb_from_file(file):
# If you have a better way of parsing the file, tell me!
with open(file, 'r', encoding='UTF-8') as f:
for line in f:
if 'config/version' in line:
number = line.strip().split("config/version=", 1)[1]
number = number.replace('"', '')
return number
def export_template(template, build_path, build_number):
# My template are named "Platform STORE"
platform = template.split(' ')[0]
store = template.split(' ')[1]
exe_name = ""
match platform:
case "Windows":
exe_name = exe_name_windows
case "Linux":
exe_name = exe_name_linux
build_path_template = os.path.join(build_path, template.replace(' ', '_'))
if not os.path.isdir(build_path_template):
os.makedirs(build_path_template)
print(" |---> Template folder created: " + build_path_template)
else:
print(" |---> Template folder already exists: " + build_path_template)
cmd = [godot_path, "--export-release", template, os.path.join(build_path_template, exe_name)]
print(" |---> Executing command: ", cmd)
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, encoding='utf-8') as sp:
pass
print(" |---> Exporting template finished: ", template)
# List files to zip
files_to_zip = []
for file in os.listdir(build_path_template):
# I'm removing .so and .dll files for Itch build as I don't need the steam lib
if store == "ITCH" and platform == "Linux":
if file.endswith((".so")): continue
if store == "ITCH" and platform == "Windows":
if file.endswith((".dll")): continue
# file_path = os.path.join(build_path_template, file)
files_to_zip.append(file)
zip_file = os.path.join(build_path, game_name+'_'+platform+'_'+store+'_'+build_number+'.zip')
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as myzip:
for file in files_to_zip:
# File to zip, filename in zip, compression type
myzip.write(os.path.join(build_path_template, file), file)
print(" |---> Zip created: ", zip_file)
return zip_file
def upload_itch(zip_files, build_number):
for zip in zip_files:
print("|---> Uploading: " + zip)
channel = 'Windows'
# Check what channel it is
if 'Linux' in zip:
channel = 'linux'
if 'Windows' in zip:
channel = 'windows'
cmd = [butler_path, 'push', zip, butler_game+':'+channel, '--userversion', build_number]
print(" |---> Executing command: ", cmd)
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, encoding='utf-8') as sp:
for line in sp.stdout:
print(line.strip())
def upload_steam(zip_files, steam_credentials):
for zip in zip_files:
print("|---> Uploading: " + zip)
# Check what channel it is
# Move zip to content folder
if 'Linux' in zip:
shutil.copy(zip, steam_content_path_linux)
# Extract zip as we can't upload a zip to steam
# We can make that better by copying the files instead of the zip.. this is a quick fix
with zipfile.ZipFile(zip,"r") as zip_ref:
zip_ref.extractall(steam_content_path_linux)
#Go through files to delete the zip
for file in os.listdir(steam_content_path_linux):
if file.endswith((".zip")):
print("|---> Deleting: " + file)
os.remove(os.path.join(steam_content_path_linux, file))
if 'Windows' in zip:
shutil.copy(zip, steam_content_path_win)
with zipfile.ZipFile(zip,"r") as zip_ref:
zip_ref.extractall(steam_content_path_win)
for file in os.listdir(steam_content_path_win):
if file.endswith((".zip")):
print("|---> Deleting: " + file)
os.remove(os.path.join(steam_content_path_win, file))
# Execute steam cmd
cmd = [steamcmd_path, '+login', steam_credentials[0], steam_credentials[1], '+run_app_build_http', steam_app_script, '+quit']
print(" |---> Executing command: ", cmd)
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, encoding='utf-8') as sp:
for line in sp.stdout:
print(line.strip())
# Delete zips after upload
for file in os.listdir(steam_content_path_win):
print("|---> Deleting: " + file)
os.remove(os.path.join(steam_content_path_win, file))
for file in os.listdir(steam_content_path_linux):
print("|---> Deleting: " + file)
os.remove(os.path.join(steam_content_path_linux, file))
def read_steam_credentials():
credentials = []
with open(steam_credentials_path, 'r', encoding='UTF-8') as f:
for line in f:
credentials.append(line.strip())
return credentials
def main():
print("########## Export starting ##########")
build_number = parse_build_nb_from_file(project_file)
build_path_full = os.path.join(build_path, build_number)
print("|---> Creating export build folder: " + build_path_full)
if not os.path.isdir(build_path_full):
os.makedirs(build_path_full)
print(" |---> Export folder created: " + build_path_full)
else:
print(" |---> Export folder already exists: " + build_path_full)
zip_files = []
for template in templates:
print("|---> Exporting template: " + template)
zip_created = export_template(template, build_path_full, build_number)
zip_files.append(zip_created)
print("Upload to itch? y/n")
while(True):
x = input()
if x=='y':
break
elif x=='n':
exit(0)
print("########## Upload starting ##########")
zip_files_itch = []
for file in zip_files:
if "ITCH" in file:
zip_files_itch.append(file)
upload_itch(zip_files_itch, build_number)
# Only upload to itch
exit(0)
print("Upload to steam? y/n")
while(True):
x = input()
if x=='y':
break
elif x=='n':
exit(0)
print("########## Upload starting ##########")
zip_files_steam = []
for file in zip_files:
if "STEAM" in file:
zip_files_steam.append(file)
steam_credentials = read_steam_credentials()
upload_steam(zip_files_steam, build_number, steam_credentials)
if __name__ == '__main__':
main()