This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
config.py
268 lines (205 loc) · 9.21 KB
/
config.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import sys
import json
import os
import re
import shutil
from colors import *
from helper import *
# Set your Android app ID
p_app_id = "com.your.id"
# Update this to customize the module
_config = {
"Analytics" : True,
"AdMob" : True,
"RemoteConfig" : False,
"Notification" : True,
"Storage" : False,
"Firestore" : True,
"Share" : True,
"Authentication" : True,
"AuthGoogle" : True,
"AuthFacebook" : False,
"AuthTwitter" : False
}
def can_build(env_plat, plat = None):
#return False
if plat == None:
#print("`GodotFireBase`"+RED+" master "+RESET+" branch not compatable with godot 2.X")
#print("Try using `GodotFireBase` "+GREEN+" 2.X "+RESET+" branch for Godot 2.X")
if isinstance(env_plat, basestring):
plat = env_plat
else:
print("GodotFireBase: "+RED+" Platform not set, Disabling GodotFireBase "+RESET)
print("GodotFireBase: "+RED+" To use `GodotFireBase` in Godot 2.X copy the `build.gradle.template` from Godot 3.X and place it in `platform/android/`"+RESET)
return False
if plat == "android":
print("GodotFireBase: " + GREEN + "Enabled" + RESET)
return True
else:
print("GodotFireBase: " + RED + "Disabled" + RESET)
return False
pass
def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
if not os.path.exists(dst): os.makedirs(dst)
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s): shutil.copytree(s, d, symlinks, ignore)
else: shutil.copyfile(s, d)
pass
def parse_file_data(file_data, regex_list, file_type = "Java"):
final_data = [];
for rr in regex_list:
re_start = rr[0]
re_stop = rr[1]
# print("Using Regex: " + re_start);
skip_line = False
blank_line = False;
for line in file_data:
if re_start.search(line) and not skip_line:
skip_line = True
continue
elif re_stop.search(line) and skip_line:
skip_line = False
continue
elif empty_line.match(line):
blank_line = True;
continue
if blank_line and len(final_data) > 0:
if final_data[-1] != "\n": final_data.append("\n");
blank_line = False;
if not skip_line: final_data.append(line);
file_data = final_data;
final_data = []
return file_data;
pass
def parse_java_file(p_file_src, p_file_dst, p_regex_list):
p_file_data = []
try:
with open(p_file_src, 'r') as file_in:
p_file_data = file_in.readlines()
except (OSError, IOError): return res
out_file = open(p_file_dst, 'w')
p_file_data = parse_file_data(p_file_data, p_regex_list, "JAVA")
out_file.write("".join(p_file_data))
out_file.close()
pass
def update_module(env):
src_dir = os.path.dirname(os.path.abspath(__file__)) + "/android_src/"
target_dir = os.path.dirname(os.path.abspath(__file__)) + "/android/"
if os.path.exists(target_dir):
shutil.rmtree(target_dir)
if not os.path.exists(target_dir):
os.makedirs(target_dir)
_config["Auth"] = _config["Authentication"]
if (_config["Storage"] or _config["Firestore"]) and not _config["Auth"]:
sys.stdout.write(RED)
print("Storage/Firestore needs FireBase Authentication, Skipping `GodotFireBase` module")
sys.stdout.write(RESET)
return False
data_to_check = \
["Analytics", "AdMob", "Auth", "Notification", "RemoteConfig",\
"Storage", "Firestore", "Share", "AuthFacebook", "AuthGoogle", "AuthTwitter"]
regex_list = []
for _file in FILES_LIST["Base"]: shutil.copyfile(src_dir+_file, target_dir+_file)
if not _config["Auth"]:
_config["AuthGoogle"] = False
_config["AuthFacebook"] = False
_config["AuthTwitter"] = False
dbg_msg = ""
for d in data_to_check:
if d == "AdMob":
if any(elem in env.module_list for elem in ["GodotAds"]):
_config[d] = False
elif d == "AuthGoogle":
if any(elem in env.module_list for elem in ["GodotGoogleService"]):
#_config[d] = False
pass
if not _config[d]:
regex_list.append(\
[re.compile(r'([\/]+'+d+'[\+]+)'), re.compile(r'([\/]+'+d+'[\-]+)')])
else:
dbg_msg += " %s," % d
if d != "Storage":
if d == "Auth":
if not os.path.exists(target_dir+"auth/"): os.makedirs(target_dir+"auth/")
for files in FILES_LIST[d]:
if d == "Auth" or (d.startswith("Auth")):
shutil.copyfile(src_dir+"auth/"+files, target_dir+"auth/"+files)
else: shutil.copyfile(src_dir+files, target_dir+files)
else: copytree(src_dir+d.lower(), target_dir+d.lower())
print("GodotFireBase: [" + dbg_msg[1:-1] + "]")
# Copy FireBase.java file into memory
parse_java_file(src_dir+"FireBase.java", target_dir+"FireBase.java", regex_list)
if _config["Auth"] and (not _config["AuthGoogle"] or not _config["AuthFacebook"] or not _config["AuthTwitter"]):
parse_java_file(src_dir+"auth/Auth.java", target_dir+"auth/Auth.java", regex_list)
# Parsing AndroidManifest
regex_list = []
for d in data_to_check:
if not _config[d]:
regex_list.append(\
[re.compile(r'(<\![\-]+ '+d+' [\-]+>)'), re.compile(r'(<\![\-]+ '+d+' [\-]+>)')])
out_file = open(target_dir+"AndroidManifestChunk.xml", 'w')
file_data = []
try:
with open(src_dir+"AndroidManifestChunk.xml", 'r') as file_in:
file_data = file_in.readlines()
except (OSError, IOError): return res
file_data = parse_file_data(file_data, regex_list, "XML")
out_file.write("".join(file_data))
out_file.close()
return True
def implement(api, support=False):
supportv4 = "{exclude group: 'com.android.support' exclude module: 'appcompat-v7' exclude module: 'support-v4'}"
return "implementation('"+api+"')" + (supportv4 if support else "")
pass
def configure(env):
global p_app_id
if env["platform"] == "android":
if (not update_module(env)):
print("Error updating module.")
return
if env.get("application_id", None) != None:
p_app_id = env["application_id"]
env.android_add_maven_repository("url 'https://maven.fabric.io/public'")
env.android_add_maven_repository("url 'https://maven.google.com'")
env.android_add_maven_repository(\
"url 'https://oss.sonatype.org/content/repositories/snapshots'")
env.android_add_gradle_classpath("com.google.gms:google-services:4.3.0")
env.android_add_gradle_plugin("com.google.gms.google-services")
env.android_add_dependency(implement("com.google.firebase:firebase-core:17.0.1"))
if _config["Auth"]:
env.android_add_dependency(implement("com.google.firebase:firebase-auth:18.1.0"))
if _config["AuthGoogle"]:
env.android_add_dependency(implement("com.google.android.gms:play-services-auth:+"))
pass
if _config["AuthFacebook"]:
env.android_add_dependency(implement("com.facebook.android:facebook-android-sdk:[4,5]", False))
if _config["AuthTwitter"]:
env.android_add_dependency(\
"implementation('com.twitter.sdk.android:twitter-core:1.6.6@aar') { transitive = true }")
env.android_add_dependency(\
"implementation('com.twitter.sdk.android:twitter:1.13.1@aar') { transitive = true }")
if _config["AdMob"]:
if any(elem in env.module_list for elem in ["GodotAds"]): pass
else:
env.android_add_dependency(implement("com.google.firebase:firebase-ads:18.1.1"))
if _config["RemoteConfig"]:
env.android_add_dependency(implement("com.google.firebase:firebase-config:18.0.0"))
env.android_add_dependency(implement("com.android.support:appcompat-v7:28.0.0"))
if _config["Notification"]:
env.android_add_dependency(implement("com.google.firebase:firebase-messaging:19.0.1"))
env.android_add_dependency(implement("com.firebase:firebase-jobdispatcher:0.8.5"))
if _config["Storage"]:
env.android_add_dependency(implement("com.google.firebase:firebase-storage:18.1.0"))
if _config["Firestore"]:
env.android_add_dependency(implement("com.google.firebase:firebase-firestore:20.1.0"))
env.android_add_dependency("implementation 'commons-codec:commons-codec:1.12'")
env.android_add_java_dir("android");
env.android_add_res_dir("res");
if "frogutils" in [os.path.split(path)[1] for path in env.android_java_dirs]: pass
else: env.android_add_java_dir("frogutils");
env.android_add_to_manifest("android/AndroidManifestChunk.xml");
env.android_add_to_permissions("android/AndroidPermissionsChunk.xml");
env.android_add_default_config("minSdkVersion 18")
env.android_add_default_config("applicationId '"+ p_app_id +"'")