mainIOS.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. import time
  2. from flask import Flask, request
  3. import requests
  4. from PIL import ImageFile, Image
  5. import os
  6. import shutil
  7. import subprocess
  8. from zipfile import ZipFile
  9. ImageFile.SAFEBLOCK = 2048 * 2048
  10. app = Flask(__name__)
  11. app.base_project = "/Users/akhmadalqindiirsyam/Documents/WorkFolder/AppBuilder/appbuilder-ios/AppBuilder"
  12. app.nexilis_lite = "/Users/akhmadalqindiirsyam/Documents/WorkFolder/AppBuilder/appbuilder-ios/NexilisLite"
  13. app.temp_folder = "/Users/akhmadalqindiirsyam/Documents/WorkFolder/BuildIos"
  14. app.app_folder = "/Users/akhmadalqindiirsyam/Documents/WorkFolder"
  15. app.asset_folder = "/Users/akhmadalqindiirsyam/Documents/WorkFolder/BuildIosAssets"
  16. app.verbose = True
  17. app.ssl = None
  18. app.keytool = '/usr/bin/keytool'
  19. app.username = "akhmadalqindiirsyam"
  20. # app.ios_platform_ids = ["bb8f256703e8fbe84da414cee20cb4d0eca3388d"]
  21. app.ios_platform_ids = []
  22. app.app_name = "AppBuilder"
  23. app.package_id = "io.newuniverse.AppBuilder"
  24. app.version_code = "1"
  25. app.version_name = "1.0.0"
  26. app.base_project_name = os.path.basename(app.base_project)
  27. def vprint(*data):
  28. if app.verbose:
  29. print(*data)
  30. def create_folder(package_id,app_name):
  31. path = os.path.join(app.temp_folder, package_id)
  32. if not os.path.exists(path):
  33. os.mkdir(path)
  34. else:
  35. shutil.rmtree(path)
  36. os.mkdir(path)
  37. vprint(path)
  38. lib_dest = os.path.join(path, "NexilisLite")
  39. if not os.path.exists(lib_dest):
  40. shutil.copytree(app.nexilis_lite, lib_dest)
  41. path_dest = os.path.join(path, app.base_project_name)
  42. if not os.path.exists(path_dest):
  43. shutil.copytree(app.base_project, path_dest)
  44. c_code_path = os.path.join(path_dest,app_name)
  45. orig_code_path = os.path.join(path_dest,"AppBuilder")
  46. if not os.path.exists(c_code_path):
  47. shutil.copytree(orig_code_path, c_code_path)
  48. shutil.rmtree(orig_code_path)
  49. return path_dest, c_code_path, lib_dest
  50. def change_acc(c_code_path, acc):
  51. main_activity = os.path.join(c_code_path, "AppDelegate.swift")
  52. with open(main_activity, "r") as f:
  53. file_source = f.read()
  54. replaced = file_source.replace("***REPLACE***WITH***YOUR***ACCOUNT***", acc)
  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, "ViewController.swift")
  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, app_name, package_id):
  65. xcproj = os.path.join(path_dest, "{}.xcodeproj".format(app_name))
  66. xcwork = os.path.join(path_dest, "{}.xcworkspace".format(app_name))
  67. shutil.move(os.path.join(path_dest, "AppBuilder.xcodeproj"), xcproj)
  68. # shutil.move(os.path.join(path_dest, "AppBuilder.xcworkspace"), xcwork)
  69. xcshareddata = os.path.join(xcproj, "xcshareddata/xcschemes", "{}.xcscheme".format(app_name))
  70. shutil.move(os.path.join(xcproj, "xcshareddata/xcschemes", "AppBuilder.xcscheme"), xcshareddata)
  71. podfile = os.path.join(path_dest, "Podfile")
  72. with open(podfile, "r") as f:
  73. file_source = f.read()
  74. replaced = file_source.replace("AppBuilder", app_name)
  75. with open(podfile, "w") as f:
  76. f.write(replaced)
  77. info_plist = os.path.join(path_dest,app_name,"Info.plist")
  78. with open(info_plist, "r") as f:
  79. file_source = f.read()
  80. replaced = file_source.replace("AppBuilder", app_name)
  81. with open(info_plist, "w") as f:
  82. f.write(replaced)
  83. main_stry = os.path.join(path_dest, app_name, "Base.lproj/Main.storyboard")
  84. with open(main_stry, "r") as f:
  85. file_source = f.read()
  86. replaced = file_source.replace("AppBuilder", app_name)
  87. with open(main_stry, "w") as f:
  88. f.write(replaced)
  89. project = os.path.join(xcproj, "project.pbxproj")
  90. package_rep = "io.newuniverse.{}".format(app_name)
  91. with open(project, "r") as f:
  92. file_source = f.read()
  93. replaced = file_source.replace("AppBuilder", app_name)
  94. replaced = replaced.replace(package_rep, package_id)
  95. with open(project, "w") as f:
  96. f.write(replaced)
  97. with open(xcshareddata, "r") as f:
  98. file_source = f.read()
  99. replaced = file_source.replace("AppBuilder", app_name)
  100. with open(xcshareddata, "w") as f:
  101. f.write(replaced)
  102. xcuserdata = os.path.join(xcproj, "xcuserdata/{}.xcuserdatad/xcschemes/xcschememanagement.plist".format(app.username))
  103. try:
  104. with open(xcuserdata, "r") as f:
  105. file_source = f.read()
  106. replaced = file_source.replace("AppBuilder", app_name)
  107. with open(xcuserdata, "w") as f:
  108. f.write(replaced)
  109. except FileNotFoundError:
  110. pass
  111. os.chdir(path_dest)
  112. subprocess.run(["pod", "install"])
  113. contentsw = os.path.join(xcwork, "contents.xcworkspacedata")
  114. with open(contentsw, "r") as f:
  115. file_source = f.read()
  116. replaced = file_source.replace("AppBuilder", app_name)
  117. with open(contentsw, "w") as f:
  118. f.write(replaced)
  119. def change_certificate(path_dest, key, keystore, keytool):
  120. pass
  121. def change_package(path_dest, package_id):
  122. pass
  123. def change_version(path_dest, app_name, version_code, version_name):
  124. project = os.path.join(path_dest, '{}.xcodeproj'.format(app_name), 'project.pbxproj')
  125. with open(project, "r") as f:
  126. file_source = f.read()
  127. replaced = file_source.replace("CURRENT_PROJECT_VERSION = 1;", "CURRENT_PROJECT_VERSION = {};".format(version_code))
  128. replaced = replaced.replace('MARKETING_VERSION = 1.0.0;', 'MARKETING_VERSION = {};'.format(version_name))
  129. with open(project, "w") as f:
  130. f.write(replaced)
  131. def change_font(c_code_path, font):
  132. prefs_path = os.path.join(c_code_path, "AppDelegate.swift")
  133. with open(prefs_path, "r") as f:
  134. file_source = f.read()
  135. replaced = file_source.replace("FONT_SELECT = 0", "FONT_SELECT = {}".format(font))
  136. with open(prefs_path, "w") as f:
  137. f.write(replaced)
  138. pass
  139. def change_logo(c_code_path, lib_dest, logo, logo_float=None):
  140. app_icon_set = [29,40,57,58,60,80,87,114,120,180,1024]
  141. app_icon_dir = os.path.join(c_code_path, 'Assets.xcassets/AppIcon.appiconset')
  142. app_float_dir = os.path.join(lib_dest, 'NexilisLite/Resource/Assets.xcassets/pb_button.imageset')
  143. app_launch_dir = os.path.join(c_code_path, 'Assets.xcassets/pb_icon.imageset')
  144. if isinstance(logo, str):
  145. # try:
  146. # logo_url = requests.get('https://newuniverse.io/dashboardv2/uploads/logo/{}'.format(logo))
  147. # for size in app_icon_set:
  148. # img_path = os.path.join(app_icon_dir, "{}.png".format(size))
  149. # with open(img_path, "wb") as f:
  150. # f.write(logo_url.content)
  151. # with open(img_path, "rb") as f:
  152. # l = Image.open(f)
  153. # l = l.resize((size, size))
  154. # l.save(img_path, "PNG")
  155. # except:
  156. try:
  157. logo_path = os.path.join(app.asset_folder, "logo", "{}".format(logo))
  158. for size in app_icon_set:
  159. img_path = os.path.join(app_icon_dir, "{}.png".format(size))
  160. with open(logo_path, "rb") as f:
  161. l = Image.open(f)
  162. l = l.resize((size, size))
  163. l.save(img_path, "PNG")
  164. except:
  165. print("error logo: {}".format(logo))
  166. return
  167. if logo_float:
  168. # try:
  169. # logo_float_url = requests.get('https://newuniverse.io/dashboardv2/uploads/logofloat/{}'.format(logo_float))
  170. # img_path = os.path.join(app_float_dir, "pb_ball.png")
  171. # with open(img_path, "wb") as f:
  172. # f.write(logo_float_url.content)
  173. # with open(img_path, "rb") as f:
  174. # l = Image.open(f)
  175. # l = l.resize((512, 512))
  176. # l.save(img_path, "PNG")
  177. # except:
  178. try:
  179. logo_launch_path = os.path.join(app.asset_folder, "logofloat", "{}".format(logo_float))
  180. img_path = os.path.join(app_launch_dir, "nexilis_icon.png".format(size))
  181. with open(logo_launch_path, "rb") as f:
  182. l = Image.open(f)
  183. l = l.resize((size, size))
  184. l.save(img_path, "PNG")
  185. except:
  186. print("error logolaunch: {}".format(logo_float))
  187. return
  188. try:
  189. logo_float_path = os.path.join(app.asset_folder, "logofloat", "{}".format(logo_float))
  190. img_path = os.path.join(app_float_dir, "pb_button.png".format(size))
  191. with open(logo_float_path, "rb") as f:
  192. l = Image.open(f)
  193. l = l.resize((size, size))
  194. l.save(img_path, "PNG")
  195. except:
  196. print("error logofloat: {}".format(logo_float))
  197. return
  198. else:
  199. logo = Image.open(logo)
  200. for size in app_icon_set:
  201. img_path = os.path.join(app_icon_dir, "{}.png".format(size))
  202. logo_resized = logo.resize((size,size))
  203. logo_resized.save(img_path, "PNG")
  204. if logo_float:
  205. logo_float = Image.open(logo_float)
  206. img_path = os.path.join(app_float_dir, "nexilis_icon.png")
  207. logo_float_resized = logo_float.resize((512,512))
  208. logo_float_resized.save(img_path, "PNG")
  209. def change_background(c_code_path, background):
  210. # assets_dir = os.path.join(c_code_path, "Assets.xcassets")
  211. # img_src_path_1 = os.path.join(assets_dir, "pb_lbackground_1.imageset")
  212. # if isinstance(background, str):
  213. # background = background.split(",")
  214. # for i, b in enumerate(background):
  215. # n = i + 1
  216. # print(b)
  217. # img_src_path = os.path.join(assets_dir, "pb_lbackground_{}.imageset".format(n))
  218. # print(img_src_path)
  219. # if n != 1:
  220. # shutil.copytree(img_src_path_1,img_src_path)
  221. # os.remove(os.path.join(img_src_path,"pb_lbackground_1.png"))
  222. # contents_json = os.path.join(img_src_path, "Contents.json")
  223. # with open(contents_json, "r") as f:
  224. # file_source = f.read()
  225. # replaced = file_source.replace("lbackground_1", "lbackground_{}".format(n))
  226. # with open(contents_json, "w") as f:
  227. # f.write(replaced)
  228. # img_path = os.path.join(img_src_path, "pb_lbackground_{}.png".format(n))
  229. # # try:
  230. # # background_url = requests.get('https://newuniverse.io/dashboardv2/uploads/background/{}'.format(b))
  231. # # with open(img_path, "wb") as f:
  232. # # f.write(background_url.content)
  233. # # with open(img_path, "rb") as f:
  234. # # l = Image.open(f)
  235. # # l = l.resize((600, 1250))
  236. # # l.save(img_path, "PNG")
  237. # # except:
  238. # try:
  239. # background_path = os.path.join(app.asset_folder, "background", "{}".format(b))
  240. # with open(background_path, "rb") as f:
  241. # l = Image.open(f)
  242. # l = l.resize((600, 1250))
  243. # l.save(img_path, "PNG")
  244. # except:
  245. # print("error background: {}".format(b))
  246. # return
  247. # second_tab = os.path.join(c_code_path, "SecondTabViewController.swift")
  248. # fourth_tab = os.path.join(c_code_path, "FourthTabViewController.swift")
  249. # with open(second_tab, "r") as f:
  250. # file_source = f.read()
  251. # replaced = file_source.replace("1..<2", "1..<{}".format(len(background) + 1))
  252. # with open(second_tab, "w") as f:
  253. # f.write(replaced)
  254. # with open(fourth_tab, "r") as f:
  255. # file_source = f.read()
  256. # replaced = file_source.replace("1..<2", "1..<{}".format(len(background) + 1))
  257. # with open(fourth_tab, "w") as f:
  258. # f.write(replaced)
  259. # else:
  260. # img_path = os.path.join(img_src_path_1, "pb_lbackground_1.png")
  261. # logo = Image.open(background)
  262. # logo = logo.resize((600, 1250))
  263. # logo.save(img_path, "PNG")
  264. pass
  265. def change_fb(lib_dest, fb_icon):
  266. default_fb_icon = ["pb_button_chat", "pb_button_call", "pb_button_cc", "pb_button_post", "pb_button_stream"]
  267. for i in range(5):
  268. if not fb_icon[i]:
  269. continue
  270. img_path = "NexilisLite/Resource/Assets.xcassets"
  271. img_path = os.path.join(lib_dest, img_path, "{}.imageset".format(default_fb_icon[i]), "{}.png".format(default_fb_icon[i]))
  272. if isinstance(fb_icon[i], str):
  273. # try:
  274. # fb_icon_url = requests.get('https://newuniverse.io/dashboardv2/uploads/fb_icon/{}'.format(fb_icon[i]))
  275. # with open(img_path, "wb") as f:
  276. # f.write(fb_icon_url.content)
  277. # with open(img_path, "rb") as f:
  278. # l = Image.open(f)
  279. # l = l.resize((150, 150))
  280. # l.save(img_path, "PNG")
  281. # except:
  282. try:
  283. fb_icon_path = os.path.join(app.asset_folder, "fb_icon", "{}".format(fb_icon[i]))
  284. with open(fb_icon_path, "rb") as f:
  285. l = Image.open(f)
  286. l = l.resize((150, 150))
  287. l.save(img_path, "PNG")
  288. except:
  289. print("error tab icon {}: {}".format(i,fb_icon[i]))
  290. else:
  291. logo = Image.open(fb_icon[i])
  292. logo = logo.resize((150, 150))
  293. logo.save(img_path, "PNG")
  294. def change_access(c_code_path, access_model):
  295. access = ["CPAAS_MODE_FLOATING", "CPAAS_MODE_DOCKED", "CPAAS_MODE_BURGER"]
  296. code_path = os.path.join(c_code_path, "PrefsUtil.swift")
  297. print(code_path)
  298. with open(code_path, "r") as f:
  299. file_source = f.read()
  300. acc = "CPAAS_MODE_MIX" if access_model > 2 else access[access_model]
  301. replaced = file_source.replace("= CPAAS_MODE_DOCKED", "= {}".format(acc))
  302. with open(code_path, "w") as f:
  303. f.write(replaced)
  304. pass
  305. def change_tab(c_code_path, tabs, tab_icon, tab3_mode):
  306. default_tab_icon = ["tab_1", "tab_2", "tab_3", "tab_4"]
  307. for i in range(4):
  308. if not tab_icon[i]:
  309. continue
  310. img_path = os.path.join(c_code_path, "Assets.xcassets",
  311. "{}_icon.imageset".format(default_tab_icon[i]),
  312. "{}_nexilis.png".format(default_tab_icon[i]))
  313. if isinstance(tab_icon[i], str):
  314. # try:
  315. # tab_icon_url = requests.get('https://newuniverse.io/dashboardv2/uploads/tab_icon/{}'.format(tab_icon[i]))
  316. # with open(img_path, "wb") as f:
  317. # f.write(tab_icon_url.content)
  318. # with open(img_path, "rb") as f:
  319. # l = Image.open(f)
  320. # l = l.resize((150, 150))
  321. # l.save(img_path, "PNG")
  322. # except:
  323. try:
  324. tab_icon_path = os.path.join(app.asset_folder, "tab_icon", "{}".format(tab_icon[i]))
  325. with open(tab_icon_path, "rb") as f:
  326. l = Image.open(f)
  327. l = l.resize((150, 150))
  328. l.save(img_path, "PNG")
  329. except:
  330. print("error tab_icon {}: {}".format(i,tab_icon[i]))
  331. return
  332. else:
  333. logo = Image.open(tab_icon[i])
  334. logo = logo.resize((150, 150))
  335. logo.save(img_path, "PNG")
  336. prefs_util = os.path.join(c_code_path, "PrefsUtil.swift")
  337. with open(prefs_util, "r") as f:
  338. file_source = f.read()
  339. replaced = file_source.replace("1,2,3,4", ",".join(tabs))
  340. with open(prefs_util, "w") as f:
  341. f.write(replaced)
  342. main_code_path = os.path.join(c_code_path, "ViewController.swift")
  343. with open(main_code_path, "r") as f:
  344. file_source = f.read()
  345. replaced = file_source.replace('tab3 = "0"', 'tab3 = "{}"'.format(tab3_mode))
  346. with open(main_code_path, "w") as f:
  347. f.write(replaced)
  348. def run_build(path_dest, app_name):
  349. workspace = os.path.join(path_dest, "{}.xcworkspace".format(app_name))
  350. build_args = ["xcodebuild", "clean", "build", "-scheme", app_name, "-workspace", workspace]
  351. install_args = ["xcodebuild", "clean", "install", "-scheme", app_name, "-workspace", workspace]
  352. ret = -1
  353. if(len(app.ios_platform_ids) > 0):
  354. for id in app.ios_platform_ids:
  355. build_args_run = install_args
  356. build_args_run.append("-destination")
  357. build_args_run.append('platform=iOS,id={}'.format(id))
  358. print(build_args_run)
  359. ret = subprocess.run(build_args_run)
  360. if ret.returncode != 0:
  361. break
  362. return ret.returncode
  363. else:
  364. ret = subprocess.run(build_args)
  365. if ret.returncode == 0:
  366. # ret = subprocess.run(["xcodebuild", "-workspace", workspace, "-scheme", app_name,
  367. # "-archivePath", os.path.join(path_dest, "out", "{}.xcarchive".format(app_name)),
  368. # "archive"])
  369. return ret.returncode
  370. return ret.returncode
  371. def deliver_app(path_dest, app_name, package_id, key, key_exists):
  372. archive_dir = os.path.join(path_dest, 'out', "{}.archive".format(app_name))
  373. timenow = time.time()
  374. archive_name = "{}{}.xarchive".format(package_id, timenow)
  375. zip_name = "{}{}.zip".format(package_id, timenow)
  376. new_arc_dir = os.path.join(app.app_folder, archive_name)
  377. new_dir = os.path.join(app.app_folder, zip_name)
  378. vprint(archive_dir)
  379. try:
  380. shutil.move(archive_dir, new_arc_dir)
  381. with ZipFile(new_dir, 'w') as zip_file:
  382. zip_file.write(new_arc_dir, os.path.basename(new_arc_dir))
  383. # os.remove(new_arc_dir)
  384. project_path = os.path.join(app.temp_folder, package_id)
  385. # shutil.rmtree(project_path)
  386. return {"name": zip_name}
  387. except Exception as e:
  388. return str(e)
  389. @app.route('/', methods=["GET", "POST"])
  390. def build_apk():
  391. vprint('==============================================================')
  392. if request.method == 'POST':
  393. logo = None
  394. logo_float = None
  395. app_name = app.app_name
  396. package_id = app.package_id
  397. acc = None
  398. url = None
  399. keystore = None
  400. key_exists = False
  401. # tabs = ["1", "2", "3", "4"]
  402. tabs = []
  403. tab3_mode = "0"
  404. tab_icon = [None, None, None, None]
  405. fb_icon = [None, None, None, None, None]
  406. background = None
  407. version_code = app.version_code
  408. version_name = app.version_name
  409. font = 0
  410. key = {"alias": "nexilislite", "store_password": "allyourbase", "key_password": "arebelongto", "common_name": "all", "organization_unit": "your",
  411. "organization_name": "base", "locality_name": "are", "state_name": "belong", "country": "to"}
  412. if 'logo' in request.files:
  413. logo = request.files['logo']
  414. vprint(type(logo))
  415. elif 'logo' in request.form:
  416. logo = request.form['logo']
  417. vprint(type(logo))
  418. if 'logofloat' in request.files:
  419. logo_float = request.files['logofloat']
  420. vprint(type(logo_float))
  421. elif 'logofloat' in request.form:
  422. logo_float = request.form['logofloat']
  423. vprint(type(logo_float))
  424. if 'app_name' in request.files:
  425. app_name = request.files['app_name']
  426. vprint(app_name)
  427. elif 'app_name' in request.form:
  428. app_name = request.form['app_name']
  429. vprint(app_name)
  430. if 'package_id' in request.files:
  431. package_id = request.files['package_id']
  432. vprint(package_id)
  433. elif 'package_id' in request.form:
  434. package_id = request.form['package_id']
  435. vprint(package_id)
  436. if 'acc' in request.files:
  437. acc = request.files['acc']
  438. vprint(acc)
  439. elif 'acc' in request.form:
  440. acc = request.form['acc']
  441. vprint(acc)
  442. if 'url' in request.files:
  443. url = request.files['url']
  444. vprint(url)
  445. elif 'url' in request.form:
  446. url = request.form['url']
  447. vprint(url)
  448. if 'keystore' in request.files:
  449. keystore = request.files['keystore']
  450. key_exists = True
  451. elif 'keystore' in request.form:
  452. keystore = request.form['keystore']
  453. key_exists = True
  454. if 'alias' in request.form:
  455. if request.form['alias']:
  456. key["alias"] = request.form['alias']
  457. if 'store_password' in request.form:
  458. if request.form['store_password']:
  459. key["store_password"] = request.form['store_password']
  460. if 'key_password' in request.form:
  461. if request.form['key_password']:
  462. key["key_password"] = request.form['key_password']
  463. if keystore:
  464. if 'common_name' in request.form:
  465. if request.form['common_name']:
  466. key["common_name"] = request.form['common_name']
  467. if 'organization_unit' in request.form:
  468. if request.form['organization_unit']:
  469. key["organization_unit"] = request.form['organization_unit']
  470. if 'organization_name' in request.form:
  471. if request.form['organization_name']:
  472. key["organization_name"] = request.form['organization_name']
  473. if 'locality_name' in request.form:
  474. if request.form['locality_name']:
  475. key["locality_name"] = request.form['locality_name']
  476. if 'state_name' in request.form:
  477. if request.form['state_name']:
  478. key["state_name"] = request.form['state_name']
  479. if 'country' in request.form:
  480. if request.form['country']:
  481. key["country"] = request.form['country']
  482. tabs.append(request.form["tab1"])
  483. tabs.append(request.form["tab2"])
  484. if request.form['tab3']:
  485. tabs.append(request.form["tab3"])
  486. if request.form['tab4']:
  487. tabs.append(request.form["tab4"])
  488. if 'tab1_icon' in request.files:
  489. tab_icon[0] = request.files['tab1_icon']
  490. elif 'tab1_icon' in request.form:
  491. tab_icon[0] = request.form['tab1_icon']
  492. if 'tab2_icon' in request.files:
  493. tab_icon[1] = request.files['tab2_icon']
  494. elif 'tab2_icon' in request.form:
  495. tab_icon[1] = request.form['tab2_icon']
  496. if 'tab3_icon' in request.files:
  497. tab_icon[2] = request.files['tab3_icon']
  498. elif 'tab3_icon' in request.form:
  499. tab_icon[2] = request.form['tab3_icon']
  500. if 'tab4_icon' in request.files:
  501. tab_icon[3] = request.files['tab4_icon']
  502. elif 'tab4_icon' in request.form:
  503. tab_icon[3] = request.form['tab4_icon']
  504. if 'fb1_icon' in request.files:
  505. fb_icon[0] = request.files['fb1_icon']
  506. elif 'fb1_icon' in request.form:
  507. fb_icon[0] = request.form['fb1_icon']
  508. if 'fb2_icon' in request.files:
  509. fb_icon[1] = request.files['fb2_icon']
  510. elif 'fb2_icon' in request.form:
  511. fb_icon[1] = request.form['fb2_icon']
  512. if 'fb3_icon' in request.files:
  513. fb_icon[2] = request.files['fb3_icon']
  514. elif 'fb3_icon' in request.form:
  515. fb_icon[2] = request.form['fb3_icon']
  516. if 'fb4_icon' in request.files:
  517. fb_icon[3] = request.files['fb4_icon']
  518. elif 'fb4_icon' in request.form:
  519. fb_icon[3] = request.form['fb4_icon']
  520. if 'fb5_icon' in request.files:
  521. fb_icon[4] = request.files['fb5_icon']
  522. elif 'fb5_icon' in request.form:
  523. fb_icon[4] = request.form['fb5_icon']
  524. vprint("fb_icon: {}".format(fb_icon))
  525. access_model = int(request.form['access_model'])
  526. if 'tab3_mode' in request.form:
  527. tab3_mode = request.form['tab3_mode']
  528. if 'tab_amount' in request.form:
  529. tab_amount = int(request.form['tab_amount'])
  530. if 'font' in request.form:
  531. font = int(request.form['font'])
  532. if 'background' in request.files:
  533. background = request.files['background']
  534. elif 'background' in request.form:
  535. background = request.form['background']
  536. if 'version_code' in request.form:
  537. version_code = request.form['version_code']
  538. if 'version_name' in request.form:
  539. version_name = request.form['version_name']
  540. else:
  541. version_name = "1.0.{}".format(version_code)
  542. derived_data = os.path.join(app.app_folder, 'Library/Developer/Xcode/DerivedData')
  543. if os.path.exists(derived_data):
  544. shutil.rmtree(derived_data,ignore_errors=True)
  545. path_dest, c_code_path, lib_dest = create_folder(package_id, app_name)
  546. vprint("path_dest: " + path_dest)
  547. vprint("c_code_path: " + c_code_path)
  548. if app_name != "AppBuilder":
  549. change_name(path_dest, app_name, package_id)
  550. if acc:
  551. change_acc(c_code_path, acc)
  552. if url:
  553. change_url(c_code_path, url)
  554. # change_certificate(path_dest, key, keystore, app.keytool)
  555. # change_package(path_dest, package_id)
  556. change_version(path_dest, app_name, version_code, version_name)
  557. change_font(c_code_path, font)
  558. if logo:
  559. change_logo(c_code_path, lib_dest, logo, logo_float)
  560. if background:
  561. change_background(c_code_path, background)
  562. change_fb(lib_dest, fb_icon)
  563. change_access(c_code_path, access_model)
  564. change_tab(c_code_path, tabs, tab_icon, tab3_mode)
  565. os.chdir(path_dest)
  566. return_code = run_build(path_dest,app_name)
  567. # if (return_code == 0):
  568. # return deliver_app(path_dest, app_name, package_id, key, key_exists)
  569. return {'return_code': return_code}
  570. else:
  571. if 'e' in request.args:
  572. return request.args['e']
  573. return "Hello World!"
  574. if __name__ == '__main__':
  575. app.run(host='0.0.0.0', port=8093, debug=app.verbose, ssl_context=app.ssl)