forked from youngj/EnvayaSMS
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-client.py
executable file
·86 lines (68 loc) · 2.51 KB
/
build-client.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
from __future__ import (unicode_literals, absolute_import,
division, print_function)
import logging
import sys
import os
import subprocess
import shutil
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
CERTIFICATE = None
STOREPASSWD = ''
KEYPASSWD = ''
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def apply_to(fpath, func):
content = ''
with open(fpath, 'r') as f:
content = f.read()
content = func(content)
with open(fpath, 'w') as f:
f.write(content)
def build_client():
os.chdir('client')
if CERTIFICATE is not None:
build_fpath = os.path.join('app', 'build.gradle')
build_orig_fpath = os.path.join('app', 'build.gradle.orig')
shutil.copy2(build_fpath, build_orig_fpath)
apply_to(build_fpath,
lambda x: x.replace('// SIGNING',
'signingConfig signingConfigs.release')
.replace('CERTIFICATE', CERTIFICATE))
# build APK
subprocess.call('rm -f app/build/outputs/apk/*.apk', shell=True)
subprocess.call(['./gradlew', 'assembleRelease'])
if CERTIFICATE is not None:
# restore build.gradle if required
if os.path.isfile(build_orig_fpath):
shutil.move(build_orig_fpath, build_fpath)
# copy signed version to proper location
logger.info("copying final file")
target_fname = 'app-release.apk' if CERTIFICATE \
else 'app-release-unsigned.apk'
final_fname = 'fondasms-client{}.apk'.format(
'' if CERTIFICATE else '-unsigned')
shutil.copy2(os.path.join('app', 'build', 'outputs', 'apk', target_fname),
os.path.join(CURRENT_DIR, 'store', 'apks', final_fname))
# go back
os.chdir(CURRENT_DIR)
subprocess.call(['ls', '-alh', os.path.join('store', 'apks')])
if __name__ == '__main__':
if len(sys.argv) < 2:
logger.error("Must set certificate path (or --no-signing)")
sys.exit(1)
if os.path.isfile(sys.argv[1]):
CERTIFICATE = os.path.expanduser(sys.argv[1])
else:
CERTIFICATE = None
if CERTIFICATE is not None:
for key in ('KSTOREPWD', 'KEYPWD'):
if key not in os.environ:
logger.error("{} not found in environ. signing will fail."
.format(key))
sys.exit(1)
os.chdir(CURRENT_DIR)
logger.info("Building client")
build_client()