mainPalio4.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. import time
  2. import traceback
  3. from flask import Flask, request
  4. import requests
  5. from PIL import ImageFile, Image
  6. import os
  7. import shutil
  8. import subprocess
  9. from zipfile import ZipFile
  10. ImageFile.SAFEBLOCK = 2048 * 2048
  11. app = Flask(__name__)
  12. app.base_project = "/apps/3ps/build_apk/PalioLite"
  13. # app.base_project = "/Users/easysoft/Documents/PalioLite"
  14. app.temp_folder = "/apps/3ps/build_apk/BuildApk"
  15. # app.temp_folder = "/Users/easysoft/BuildApk"
  16. app.apk_folder = "/var/www/html/palio.io/dashboardv2/uploads"
  17. # app.apk_folder = "/Users/easysoft/"
  18. app.verbose = True
  19. app.ssl = (
  20. '/etc/ssl/star.newuniverse.io/star.newuniverse.io.crt', '/etc/ssl/star.newuniverse.io/STAR_newuniverse_io.key')
  21. # app.ssl =('/etc/ssl/STAR_palio_io/STAR_palio_io.crt', '/etc/ssl/STAR_palio_io/STAR_palio_io.pem')
  22. # app.ssl = None
  23. app.keytool = '/usr/bin/keytool'
  24. app.base_project_name = os.path.basename(app.base_project)
  25. def vprint(*data):
  26. if app.verbose:
  27. print(*data)
  28. def create_folder(package_id):
  29. path = os.path.join(app.temp_folder, package_id)
  30. if not os.path.exists(path):
  31. os.mkdir(path)
  32. else:
  33. shutil.rmtree(path)
  34. os.mkdir(path)
  35. vprint(path)
  36. path_dest = os.path.join(path, app.base_project_name)
  37. if not os.path.exists(path_dest):
  38. shutil.copytree(app.base_project, path_dest)
  39. code_path = "app/src/main/java/"
  40. orig_code = "com/example/qmeralitesamplecode"
  41. path_package_id = package_id.replace(".", "/")
  42. c_code_path = os.path.join(path_dest, code_path, path_package_id)
  43. orig_code_path = os.path.join(path_dest, code_path, orig_code)
  44. if not os.path.exists(c_code_path):
  45. shutil.copytree(orig_code_path, c_code_path)
  46. shutil.rmtree(orig_code_path)
  47. return path_dest, c_code_path
  48. def change_acc(c_code_path, acc, enable_sms):
  49. main_activity = os.path.join(c_code_path, "MAB.java")
  50. with open(main_activity, "r") as f:
  51. file_source = f.read()
  52. replaced = file_source.replace("***REPLACE***WITH***YOUR***QMERA***ACCOUNT***", acc)
  53. if enable_sms == 1:
  54. replaced = replaced.replace("isEnabledSMS = false", "isEnabledSMS = true")
  55. with open(main_activity, "w") as f:
  56. f.write(replaced)
  57. def change_url(c_code_path, url):
  58. main_activity = os.path.join(c_code_path, "MAB.java")
  59. with open(main_activity, "r") as f:
  60. file_source = f.read()
  61. replaced = file_source.replace("https://www.google.com", url)
  62. with open(main_activity, "w") as f:
  63. f.write(replaced)
  64. def change_name(path_dest, name, enable_sms):
  65. manifest = os.path.join(path_dest, "app/src/main/AndroidManifest.xml")
  66. string_res = os.path.join(path_dest, "app/src/main/res/values/strings.xml")
  67. with open(manifest, "r") as f:
  68. lines = f.readlines()
  69. # file_source = f.read()
  70. with open(manifest, "w") as f:
  71. for line in lines:
  72. if "NexilisLite" in line:
  73. line = line.replace("NexilisLite", name)
  74. if enable_sms == 0:
  75. if "SMS" not in line:
  76. f.write(line)
  77. else:
  78. f.write(line)
  79. with open(string_res, "r") as f:
  80. file_source = f.read()
  81. replaced = file_source.replace("Nexilis Sport", name)
  82. with open(string_res, "w") as f:
  83. f.write(replaced)
  84. def change_font(path_dest, font, package):
  85. if font == 1:
  86. path_package_id = package.replace(".", "/")
  87. code_path = "app/src/main/java/"
  88. code_path = os.path.join(path_dest, code_path, path_package_id)
  89. res_path = "app/src/main/res/"
  90. res_path = os.path.join(path_dest, res_path)
  91. javas = [os.path.join(dp, f) for dp, dn, filenames in os.walk(code_path) for f in filenames]
  92. res = [os.path.join(dp, f) for dp, dn, filenames in os.walk(res_path) for f in filenames if "xml" in f]
  93. button_apps_code_path = os.path.join(path_dest, "palio-button-app/src/main/java")
  94. button_apps_res_path = os.path.join(path_dest, "palio-button-app/src/main/res-pba/")
  95. lib_javas = [os.path.join(dp, f) for dp, dn, filenames in os.walk(button_apps_code_path) for f in filenames]
  96. lib_res = [os.path.join(dp, f) for dp, dn, filenames in os.walk(button_apps_res_path) for f in filenames if
  97. "xml" in f]
  98. for j in javas:
  99. print(j)
  100. if "ForumFragment.java" in j:
  101. with open(j, "r") as f:
  102. file_source = f.read()
  103. replaced = file_source.replace("pb_poppins", "roboto")
  104. with open(j, "w") as f:
  105. f.write(replaced)
  106. for j in res:
  107. print(j)
  108. with open(j, "r") as f:
  109. file_source = f.read()
  110. replaced = file_source.replace("pb_poppins", "roboto")
  111. with open(j, "w") as f:
  112. f.write(replaced)
  113. for j in lib_javas:
  114. print(j)
  115. with open(j, "r") as f:
  116. file_source = f.read()
  117. replaced = file_source.replace("pb_poppins", "roboto")
  118. with open(j, "w") as f:
  119. f.write(replaced)
  120. for j in lib_res:
  121. print(j)
  122. with open(j, "r") as f:
  123. file_source = f.read()
  124. replaced = file_source.replace("pb_poppins", "roboto")
  125. with open(j, "w") as f:
  126. f.write(replaced)
  127. def change_package(path_dest, package):
  128. build_gradle = os.path.join(path_dest, 'app/build.gradle')
  129. with open(build_gradle, "r") as f:
  130. file_source = f.read()
  131. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  132. with open(build_gradle, "w") as f:
  133. f.write(replaced)
  134. proguard = os.path.join(path_dest, 'app/proguard-rules.pro')
  135. with open(proguard, "r") as f:
  136. file_source = f.read()
  137. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  138. with open(proguard, "w") as f:
  139. f.write(replaced)
  140. manifest = os.path.join(path_dest, "app/src/main/AndroidManifest.xml")
  141. with open(manifest, "r") as f:
  142. file_source = f.read()
  143. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  144. with open(manifest, "w") as f:
  145. f.write(replaced)
  146. path_package_id = package.replace(".", "/")
  147. code_path = "app/src/main/java/"
  148. code_path = os.path.join(path_dest, code_path, path_package_id)
  149. res_path = "app/src/main/res/"
  150. res_path = os.path.join(path_dest, res_path)
  151. javas = [os.path.join(dp, f) for dp, dn, filenames in os.walk(code_path) for f in filenames]
  152. res = [os.path.join(dp, f) for dp, dn, filenames in os.walk(res_path) for f in filenames if "xml" in f]
  153. for j in javas:
  154. print(j)
  155. with open(j, "r") as f:
  156. file_source = f.read()
  157. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  158. with open(j, "w") as f:
  159. f.write(replaced)
  160. for j in res:
  161. print(j)
  162. with open(j, "r") as f:
  163. file_source = f.read()
  164. replaced = file_source.replace("com.example.qmeralitesamplecode", package)
  165. with open(j, "w") as f:
  166. f.write(replaced)
  167. if package.__contains__('digipos') or package.__contains__('digisales'):
  168. settings_gradle = os.path.join(path_dest, "settings.gradle")
  169. with open(settings_gradle, "r") as f:
  170. lines = f.readlines()
  171. with open(settings_gradle, "w") as f:
  172. counter = 0
  173. for line in lines:
  174. if counter == 0:
  175. if "forallapps" in line:
  176. counter = 5
  177. else:
  178. f.write(line)
  179. else:
  180. counter = counter - 1
  181. mab_path = os.path.join(path_dest, code_path, "MAB.java")
  182. with open(mab_path, "r") as f:
  183. lines = f.readlines()
  184. with open(mab_path, "w") as f:
  185. counter1 = 0
  186. counter2 = 0
  187. for line in lines:
  188. if "fordigisales1" in line:
  189. counter1 = 128
  190. elif "fordigisales2" in line:
  191. counter2 = 27
  192. elif counter1 > 0:
  193. counter1 = counter1 - 1
  194. elif counter2 > 0:
  195. counter2 = counter2 - 1
  196. else:
  197. f.write(line)
  198. notif_center = os.path.join(path_dest, code_path, "notificationCenterTab/NotificationCenterFragment.java")
  199. with open(notif_center, "r") as f:
  200. lines = f.readlines()
  201. with open(notif_center, "w") as f:
  202. counter = 0
  203. for line in lines:
  204. if counter == 0:
  205. if "fordigisales" in line:
  206. counter = 14
  207. else:
  208. f.write(line)
  209. else:
  210. counter = counter - 1
  211. else:
  212. settings_gradle = os.path.join(path_dest, "settings.gradle")
  213. with open(settings_gradle, "r") as f:
  214. lines = f.readlines()
  215. with open(settings_gradle, "w") as f:
  216. counter = 0
  217. for line in lines:
  218. if counter == 0:
  219. if "fordigisales" in line:
  220. counter = 5
  221. else:
  222. f.write(line)
  223. else:
  224. counter = counter - 1
  225. colorValue = os.path.join(res_path, "values/colors.xml")
  226. with open(colorValue, "r") as c:
  227. lines = c.readlines()
  228. with open(colorValue, "w") as c:
  229. for lineColor in lines:
  230. if "fordigisales" in lineColor:
  231. continue
  232. else:
  233. c.write(lineColor)
  234. if package == "com.nexilis.persija" or package == "io.newuniverse.GoToMalls" or package == "io.qmera.mylab":
  235. string_res = os.path.join(path_dest, "app/src/main/res/values/strings.xml")
  236. string_en_res = os.path.join(path_dest, "app/src/main/res/values-en/strings.xml")
  237. string_id_res = os.path.join(path_dest, "app/src/main/res/values-in/strings.xml")
  238. with open(string_res, "r") as f:
  239. file_source = f.read()
  240. replaced = file_source.replace("Nexilis", "Qmera")
  241. with open(string_res, "w") as f:
  242. f.write(replaced)
  243. with open(string_en_res, "r") as f:
  244. file_source = f.read()
  245. replaced = file_source.replace("Nexilis", "Qmera")
  246. with open(string_en_res, "w") as f:
  247. f.write(replaced)
  248. with open(string_id_res, "r") as f:
  249. file_source = f.read()
  250. replaced = file_source.replace("Nexilis", "Qmera")
  251. with open(string_id_res, "w") as f:
  252. f.write(replaced)
  253. old_img_powered = "app/src/main/res/drawable/pb_powered_button.png"
  254. old_img_powered = os.path.join(path_dest, old_img_powered)
  255. old_new_img_powered = "app/src/main/res/drawable/pb_powered_button_temp.png"
  256. old_new_img_powered = os.path.join(path_dest, old_new_img_powered)
  257. shutil.move(old_img_powered, old_new_img_powered)
  258. img_powered = "app/src/main/res/drawable/pb_powered_button1.png"
  259. img_powered = os.path.join(path_dest, img_powered)
  260. new_img_powered = "app/src/main/res/drawable/pb_powered_button.png"
  261. new_img_powered = os.path.join(path_dest, new_img_powered)
  262. shutil.move(img_powered, new_img_powered)
  263. def change_logo(path_dest, logo, logo_float=None):
  264. img_path = "app/src/main/res/drawable/ic_launcher.png"
  265. img_path = os.path.join(path_dest, img_path)
  266. img_notif = "app/src/main/res/drawable/pb_ball.png"
  267. img_notif = os.path.join(path_dest, img_notif)
  268. img_path_float = "app/src/main/res/drawable/pb_button.png"
  269. img_path_float = os.path.join(path_dest, img_path_float)
  270. if isinstance(logo, str):
  271. logo = requests.get('https://newuniverse.io/dashboardv2/uploads/logo/{}'.format(logo))
  272. with open(img_path, "wb") as f:
  273. f.write(logo.content)
  274. with open(img_path, "rb") as f:
  275. logo = Image.open(f)
  276. logo = logo.resize((512, 512))
  277. if logo_float:
  278. logo_float = requests.get('https://newuniverse.io/dashboardv2/uploads/logofloat/{}'.format(logo_float))
  279. with open(img_path_float, "wb") as f:
  280. f.write(logo_float.content)
  281. with open(img_path_float, "rb") as f:
  282. logo_float = Image.open(f)
  283. logo_float = logo_float.resize((150, 150))
  284. else:
  285. logo = Image.open(logo)
  286. logo = logo.resize((512, 512))
  287. if logo_float:
  288. logo_float = Image.open(logo_float)
  289. logo_float = logo_float.resize((150, 150))
  290. logo.save(img_path, "PNG")
  291. if logo_float:
  292. logo_float.save(img_path_float, "PNG")
  293. logo_float.save(img_notif, "PNG")
  294. def change_tab(path_dest, tabs, tab_icon, package, tab3_mode, tab_amount):
  295. default_tab_icon = ["tab{}.png".format(x) for x in tabs]
  296. for i, icon in enumerate(default_tab_icon):
  297. if not tab_icon[i]:
  298. continue
  299. img_path = "app/src/main/res/drawable"
  300. img_path = os.path.join(path_dest, img_path, icon)
  301. if isinstance(tab_icon[i], str):
  302. logo = requests.get('https://newuniverse.io/dashboardv2/uploads/tab_icon/{}'.format(tab_icon[i]))
  303. with open(img_path, "wb") as f:
  304. f.write(logo.content)
  305. with open(img_path, "rb") as f:
  306. logo = Image.open(f)
  307. logo = logo.resize((150, 150))
  308. logo.save(img_path, "PNG")
  309. else:
  310. logo = Image.open(tab_icon[i])
  311. logo = logo.resize((150, 150))
  312. logo.save(img_path, "PNG")
  313. path_package_id = package.replace(".", "/")
  314. code_path = "app/src/main/java/"
  315. sobj_code_path = os.path.join(path_dest, code_path, path_package_id, "SObj.java")
  316. print(sobj_code_path)
  317. with open(sobj_code_path, "r") as f:
  318. file_source = f.read()
  319. replaced = file_source.replace("1,2,3,4", ",".join(tabs))
  320. with open(sobj_code_path, "w") as f:
  321. f.write(replaced)
  322. main_code_path = os.path.join(path_dest, code_path, path_package_id, "MAB.java")
  323. with open(main_code_path, "r") as f:
  324. file_source = f.read()
  325. replaced = file_source.replace('tab3 = "0"', 'tab3 = "{}"'.format(tab3_mode))
  326. with open(main_code_path, "w") as f:
  327. f.write(replaced)
  328. prefs_code_path = os.path.join(path_dest, code_path, path_package_id, "util/PrefsUtil.java")
  329. with open(prefs_code_path, "r") as f:
  330. file_source = f.read()
  331. replaced = file_source.replace('DEFAULT_TAB_AMOUNT = "4"', 'DEFAULT_TAB_AMOUNT = "{}"'.format(tab_amount))
  332. with open(prefs_code_path, "w") as f:
  333. f.write(replaced)
  334. def change_fb(path_dest, fb_order, package, fb_icon):
  335. fb_order_list = [int(x) for x in fb_order.split(",")]
  336. default_fb_icon = ["pb_button_chat.png", "pb_button_call.png", "pb_button_cc.png", "pb_button_stream.png",
  337. "nexilis_fb_04.png"]
  338. for x,i in enumerate(fb_order_list):
  339. if not fb_icon[x]:
  340. continue
  341. img_path = "app/src/main/res/drawable-nodpi"
  342. if i-1 in range(-len(default_fb_icon), len(default_fb_icon)):
  343. img_path = os.path.join(path_dest, img_path, default_fb_icon[i-1])
  344. if isinstance(fb_icon[x], str):
  345. logo = requests.get('https://newuniverse.io/dashboardv2/uploads/fb_icon/{}'.format(fb_icon[x]))
  346. with open(img_path, "wb") as f:
  347. f.write(logo.content)
  348. with open(img_path, "rb") as f:
  349. logo = Image.open(f)
  350. logo = logo.resize((150, 150))
  351. logo.save(img_path, "PNG")
  352. else:
  353. logo = Image.open(fb_icon[x])
  354. logo = logo.resize((150, 150))
  355. logo.save(img_path, "PNG")
  356. path_package_id = package.replace(".", "/")
  357. code_path = "app/src/main/java/"
  358. main_code_path = os.path.join(path_dest, code_path, path_package_id, "MAB.java")
  359. with open(main_code_path, "r") as f:
  360. file_source = f.read()
  361. replaced = file_source.replace('dockedPlacement = "1,2,3,4,5"', 'dockedPlacement = "{}"'.format(fb_order))
  362. with open(main_code_path, "w") as f:
  363. f.write(replaced)
  364. def change_background(path_dest, background):
  365. # if isinstance(background, str):
  366. # background = background.split(",")
  367. # for i,b in enumerate(background):
  368. # n = i+1
  369. # img_path = "app/src/main/res/drawable-nodpi/pb_lbackground_{}.png".format(n)
  370. # img_path = os.path.join(path_dest, img_path)
  371. # logo = requests.get('https://newuniverse.io/dashboardv2/uploads/background/{}'.format(b))
  372. # with open(img_path, "wb") as f:
  373. # f.write(logo.content)
  374. # with open(img_path, "rb") as f:
  375. # logo = Image.open(f)
  376. # logo = logo.resize((600, 1250))
  377. # logo.save(img_path, "PNG")
  378. # else:
  379. # img_path = "app/src/main/res/drawable-nodpi/pb_lbackground_1.png"
  380. # logo = Image.open(background)
  381. # logo = logo.resize((600, 1250))
  382. # logo.save(img_path, "PNG")
  383. pass
  384. def change_access(path_dest, access_model, package):
  385. access = ["CPAAS_MODE_FLOATING", "CPAAS_MODE_DOCKED", "CPAAS_MODE_BURGER"]
  386. path_package_id = package.replace(".", "/")
  387. code_path = "app/src/main/java/"
  388. code_path = os.path.join(path_dest, code_path, path_package_id, "util", "PrefsUtil.java")
  389. print(code_path)
  390. with open(code_path, "r") as f:
  391. file_source = f.read()
  392. replaced = file_source.replace("= CPAAS_MODE_DOCKED", "= {}".format(access[access_model]))
  393. with open(code_path, "w") as f:
  394. f.write(replaced)
  395. def change_certificate(path_dest, key, keyfile, keytool):
  396. keyfile_name = "{}.keystore".format(key["alias"])
  397. keyfile_path = os.path.join(path_dest, keyfile_name)
  398. if keyfile:
  399. keyfile.save(keyfile_path)
  400. else:
  401. vprint("keytool run")
  402. os.chdir(path_dest)
  403. vprint("current working directory: ", os.getcwd())
  404. dname = "CN={}, OU={}, O={}, L={}, S={}, C={}".format(key["common_name"], key["organization_unit"],
  405. key["organization_name"], key["locality_name"],
  406. key["state_name"], key["country"])
  407. cmd = [keytool, "-genkey", "-v", "-keystore", keyfile_path, "-alias", key["alias"], "-keyalg", "RSA",
  408. "-keysize", "2048",
  409. "-validity", "10000", "-dname", dname, "-storepass", key["store_password"], "-keypass",
  410. key["key_password"]]
  411. vprint(cmd)
  412. subprocess.run(cmd)
  413. vprint("keytool end")
  414. build_gradle = os.path.join(path_dest, 'app/build.gradle')
  415. with open(build_gradle, "r") as f:
  416. file_source = f.read()
  417. replaced = file_source.replace("allyourbase", key["store_password"])
  418. replaced = replaced.replace("arebelongto", key["key_password"])
  419. replaced = replaced.replace("key-qmeralite", key["alias"])
  420. with open(build_gradle, "w") as f:
  421. f.write(replaced)
  422. def change_huawei_file(path_dest, huawei_file, package_id):
  423. huaweifile_name = "agconnect-services.json"
  424. huaweifile_path = os.path.join(path_dest, "app/{}".format(huaweifile_name))
  425. if huawei_file:
  426. huawei_file.save(huaweifile_path)
  427. path_package_id = package_id.replace(".", "/")
  428. code_path = "app/src/main/java/"
  429. main_code_path = os.path.join(path_dest, code_path, path_package_id, "MAB.java")
  430. with open(main_code_path, "r") as f:
  431. file_source = f.read()
  432. replaced = file_source.replace('isHMSEnabled = false', 'isHMSEnabled = true')
  433. with open(main_code_path, "w") as f:
  434. f.write(replaced)
  435. def change_fms_file(path_dest, fms_enable, package_id):
  436. if fms_enable == 0:
  437. path_package_id = package_id.replace(".", "/")
  438. code_path = "app/src/main/java/"
  439. main_code_path = os.path.join(path_dest, code_path, path_package_id, "MAB.java")
  440. with open(main_code_path, "r") as f:
  441. file_source = f.read()
  442. replaced = file_source.replace('isFMSEnabled = true', 'isFMSEnabled = false')
  443. with open(main_code_path, "w") as f:
  444. f.write(replaced)
  445. def run_build(path_dest):
  446. gradlew = os.path.join(path_dest, "gradlew")
  447. error = ""
  448. ret = subprocess.run([gradlew, 'assembleRelease'], capture_output=True)
  449. if ret.returncode == 0:
  450. ret = subprocess.run([gradlew, 'bundleRelease'], capture_output=True)
  451. if ret.returncode != 0:
  452. error = "{}\n".format(ret.stderr.decode())
  453. vprint(error)
  454. else:
  455. error = "{}\n".format(ret.stderr.decode())
  456. vprint(error)
  457. return ret.returncode, error
  458. def deliver_apk(path_dest, package_id, key, key_exists):
  459. apk_dir = os.path.join(path_dest, 'app/build/outputs/apk/release/app-release.apk')
  460. aab_dir = os.path.join(path_dest, 'app/build/outputs/bundle/release/app-release.aab')
  461. keystore_name = '{}.keystore'.format(key["alias"])
  462. keystore_dir = os.path.join(path_dest, keystore_name)
  463. timenow = time.time()
  464. apk_name = "{}{}.apk".format(package_id, timenow)
  465. aab_name = "{}{}.aab".format(package_id, timenow)
  466. zip_name = "{}{}.zip".format(package_id, timenow)
  467. new_apk_dir = os.path.join(app.apk_folder, apk_name)
  468. new_aab_dir = os.path.join(app.apk_folder, aab_name)
  469. new_dir = os.path.join(app.apk_folder, zip_name)
  470. vprint(apk_dir)
  471. shutil.move(apk_dir, new_apk_dir)
  472. try:
  473. shutil.move(aab_dir, new_aab_dir)
  474. with ZipFile(new_dir, 'w') as zip_file:
  475. zip_file.write(new_apk_dir, os.path.basename(new_apk_dir))
  476. zip_file.write(new_aab_dir, os.path.basename(new_aab_dir))
  477. if not key_exists:
  478. zip_file.write(keystore_dir, os.path.basename(keystore_dir))
  479. os.remove(new_apk_dir)
  480. os.remove(new_aab_dir)
  481. project_path = os.path.join(app.temp_folder, package_id)
  482. shutil.rmtree(project_path)
  483. return {"status": "0", "name": zip_name}
  484. except Exception as e:
  485. return {"status": "4", "message": "Deliver APK & AAB failed\n{}".format(e)}
  486. def change_version(path_dest, version_code, version_name):
  487. build_gradle = os.path.join(path_dest, 'app/build.gradle')
  488. with open(build_gradle, "r") as f:
  489. file_source = f.read()
  490. replaced = file_source.replace("versionCode 3", "versionCode {}".format(version_code))
  491. replaced = replaced.replace('versionName "3.0"', 'versionName "{}"'.format(version_name))
  492. with open(build_gradle, "w") as f:
  493. f.write(replaced)
  494. @app.route('/', methods=["GET", "POST"])
  495. def build_apk():
  496. vprint('==============================================================')
  497. if request.method == 'POST':
  498. logo = None
  499. logo_float = None
  500. app_name = "NexilisLite"
  501. package_id = "com.app.nexilis"
  502. acc = None
  503. url = None
  504. keystore = None
  505. huawei_file = None
  506. fms_enable = 1
  507. key_exists = False
  508. # tabs = ["1", "2", "3", "4"]
  509. fb_order = "1,2,3,4,5"
  510. tabs = []
  511. tab3_mode = "0"
  512. tab_amount = 6
  513. tab_icon = [None, None, None, None, None, None]
  514. fb_icon = [None, None, None, None, None]
  515. background = None
  516. version_code = "1"
  517. version_name = "1.0.0"
  518. font = 0
  519. enable_sms = 0
  520. key = {"alias": "nexilislite", "store_password": "allyourbase", "key_password": "allyourbase",
  521. "common_name": "all", "organization_unit": "your",
  522. "organization_name": "base", "locality_name": "are", "state_name": "belong", "country": "to"}
  523. try:
  524. if 'logo' in request.files:
  525. logo = request.files['logo']
  526. vprint(type(logo))
  527. elif 'logo' in request.form:
  528. logo = request.form['logo']
  529. vprint(type(logo))
  530. if 'logofloat' in request.files:
  531. logo_float = request.files['logofloat']
  532. vprint(type(logo_float))
  533. elif 'logofloat' in request.form:
  534. logo_float = request.form['logofloat']
  535. vprint(type(logo_float))
  536. if 'app_name' in request.files:
  537. app_name = request.files['app_name']
  538. vprint(app_name)
  539. elif 'app_name' in request.form:
  540. app_name = request.form['app_name']
  541. vprint(app_name)
  542. if 'package_id' in request.files:
  543. package_id = request.files['package_id']
  544. vprint(package_id)
  545. elif 'package_id' in request.form:
  546. package_id = request.form['package_id']
  547. vprint(package_id)
  548. if 'acc' in request.files:
  549. acc = request.files['acc']
  550. vprint(acc)
  551. elif 'acc' in request.form:
  552. acc = request.form['acc']
  553. vprint(acc)
  554. if 'url' in request.files:
  555. url = request.files['url']
  556. vprint(url)
  557. elif 'url' in request.form:
  558. url = request.form['url']
  559. vprint(url)
  560. if 'keystore' in request.files:
  561. keystore = request.files['keystore']
  562. key_exists = True
  563. elif 'keystore' in request.form:
  564. keystore = request.form['keystore']
  565. key_exists = True
  566. if 'huawei_file' in request.files:
  567. huawei_file = request.files['huawei_file']
  568. elif 'huawei_file' in request.form:
  569. huawei_file = request.form['huawei_file']
  570. if 'fms_enable' in request.form:
  571. fms_enable = int(request.form['fms_enable'])
  572. if 'alias' in request.form:
  573. if request.form['alias']:
  574. key["alias"] = request.form['alias']
  575. if 'store_password' in request.form:
  576. if request.form['store_password']:
  577. key["store_password"] = request.form['store_password']
  578. if 'key_password' in request.form:
  579. if request.form['key_password']:
  580. key["key_password"] = request.form['key_password']
  581. if keystore:
  582. if 'common_name' in request.form:
  583. if request.form['common_name']:
  584. key["common_name"] = request.form['common_name']
  585. if 'organization_unit' in request.form:
  586. if request.form['organization_unit']:
  587. key["organization_unit"] = request.form['organization_unit']
  588. if 'organization_name' in request.form:
  589. if request.form['organization_name']:
  590. key["organization_name"] = request.form['organization_name']
  591. if 'locality_name' in request.form:
  592. if request.form['locality_name']:
  593. key["locality_name"] = request.form['locality_name']
  594. if 'state_name' in request.form:
  595. if request.form['state_name']:
  596. key["state_name"] = request.form['state_name']
  597. if 'country' in request.form:
  598. if request.form['country']:
  599. key["country"] = request.form['country']
  600. tabs.append(request.form["tab1"])
  601. tabs.append(request.form["tab2"])
  602. if request.form['tab3']:
  603. tabs.append(request.form["tab3"])
  604. if request.form['tab4']:
  605. tabs.append(request.form["tab4"])
  606. if 'tab1_icon' in request.files:
  607. tab_icon[0] = request.files['tab1_icon']
  608. elif 'tab1_icon' in request.form:
  609. tab_icon[0] = request.form['tab1_icon']
  610. if 'tab2_icon' in request.files:
  611. tab_icon[1] = request.files['tab2_icon']
  612. elif 'tab2_icon' in request.form:
  613. tab_icon[1] = request.form['tab2_icon']
  614. if 'tab3_icon' in request.files:
  615. tab_icon[2] = request.files['tab3_icon']
  616. elif 'tab3_icon' in request.form:
  617. tab_icon[2] = request.form['tab3_icon']
  618. if 'tab4_icon' in request.files:
  619. tab_icon[3] = request.files['tab4_icon']
  620. elif 'tab4_icon' in request.form:
  621. tab_icon[3] = request.form['tab4_icon']
  622. if 'fb1_icon' in request.files:
  623. fb_icon[0] = request.files['fb1_icon']
  624. elif 'fb1_icon' in request.form:
  625. fb_icon[0] = request.form['fb1_icon']
  626. if 'fb2_icon' in request.files:
  627. fb_icon[1] = request.files['fb2_icon']
  628. elif 'fb2_icon' in request.form:
  629. fb_icon[1] = request.form['fb2_icon']
  630. if 'fb3_icon' in request.files:
  631. fb_icon[2] = request.files['fb3_icon']
  632. elif 'fb3_icon' in request.form:
  633. fb_icon[2] = request.form['fb3_icon']
  634. if 'fb4_icon' in request.files:
  635. fb_icon[3] = request.files['fb4_icon']
  636. elif 'fb4_icon' in request.form:
  637. fb_icon[3] = request.form['fb4_icon']
  638. if 'fb5_icon' in request.files:
  639. fb_icon[4] = request.files['fb5_icon']
  640. elif 'fb5_icon' in request.form:
  641. fb_icon[4] = request.form['fb5_icon']
  642. if 'fb_icon' in request.form:
  643. fb_icon = request.form['fb_icon'].split(",")
  644. if 'fb_order' in request.form:
  645. fb_order = request.form['fb_order']
  646. vprint("fb_icon: {}".format(fb_icon))
  647. access_model = int(request.form['access_model'])
  648. if 'tab3_mode' in request.form:
  649. tab3_mode = request.form['tab3_mode']
  650. if 'tab_amount' in request.form:
  651. tab_amount = int(request.form['tab_amount'])
  652. if 'font' in request.form:
  653. font = int(request.form['font'])
  654. if 'background' in request.files:
  655. background = request.files['background']
  656. elif 'background' in request.form:
  657. background = request.form['background']
  658. if 'version_code' in request.form:
  659. version_code = request.form['version_code']
  660. if 'version_name' in request.form:
  661. version_name = request.form['version_name']
  662. else:
  663. version_name = "1.0.{}".format(version_code)
  664. if 'enable_sms' in request.form:
  665. enable_sms = int(request.form['enable_sms'])
  666. except BaseException as e:
  667. vprint(traceback.format_exc())
  668. return {"status": "1", "message": "Parameter mismatch\n{}\n".format(str(e))}
  669. try:
  670. path_dest, c_code_path = create_folder(package_id)
  671. vprint("path_dest: " + path_dest)
  672. vprint("c_code_path: " + c_code_path)
  673. if acc:
  674. change_acc(c_code_path, acc, enable_sms)
  675. if url:
  676. change_url(c_code_path, url)
  677. change_name(path_dest, app_name, enable_sms)
  678. change_certificate(path_dest, key, keystore, app.keytool)
  679. change_package(path_dest, package_id)
  680. change_version(path_dest, version_code, version_name)
  681. change_font(path_dest, font, package_id)
  682. if logo:
  683. change_logo(path_dest, logo, logo_float)
  684. if background:
  685. change_background(path_dest, background)
  686. change_fb(path_dest, fb_order, package_id, fb_icon)
  687. change_access(path_dest, access_model, package_id)
  688. change_tab(path_dest, tabs, tab_icon, package_id, tab3_mode, tab_amount)
  689. change_huawei_file(path_dest, huawei_file, package_id)
  690. change_fms_file(path_dest, fms_enable, package_id)
  691. except BaseException as e:
  692. vprint(traceback.format_exc())
  693. return {"status": "2", "message": "Process failure\n{}\n".format(str(e))}
  694. os.chdir(path_dest)
  695. return_code, error = run_build(path_dest)
  696. if return_code == 0:
  697. return deliver_apk(path_dest, package_id, key, key_exists)
  698. return {"status": "3", "message": "Build failed\n{}".format(str(error))}
  699. else:
  700. if 'e' in request.args:
  701. return request.args['e']
  702. return "Hello World!"
  703. if __name__ == '__main__':
  704. app.run(host='0.0.0.0', port=8072, debug=app.verbose, ssl_context=app.ssl)