Skip to content

Commit 18f1af3

Browse files
committed
add a parameter to build.py
allow to pass a filename to --intent-filter the content of this file will be read and intested en the activity section of the AndroidManifest.xml number of pep8 fixes too
1 parent da7045e commit 18f1af3

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/build.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
environment = jinja2.Environment(loader=jinja2.FileSystemLoader(
5757
join(curdir, 'templates')))
5858

59+
5960
def render(template, dest, **kwargs):
6061
'''
6162
Using jinja2, render `template` to the filename `dest`, supplying the keyword
@@ -69,13 +70,15 @@ def render(template, dest, **kwargs):
6970
f.write(text.encode('utf-8'))
7071
f.close()
7172

73+
7274
def compile_dir(dfn):
7375
'''
7476
Compile *.py in directory `dfn` to *.pyo
7577
'''
7678

7779
# -OO = strip docstrings
78-
subprocess.call([PYTHON,'-OO','-m','compileall','-f', dfn])
80+
subprocess.call([PYTHON, '-OO', '-m', 'compileall', '-f', dfn])
81+
7982

8083
def is_blacklist(name):
8184
for pattern in BLACKLIST_PATTERNS:
@@ -86,6 +89,7 @@ def is_blacklist(name):
8689
if fnmatch(name, pattern):
8790
return True
8891

92+
8993
def listfiles(d):
9094
basedir = d
9195
subdirlist = []
@@ -99,6 +103,7 @@ def listfiles(d):
99103
for fn in listfiles(subdir):
100104
yield fn
101105

106+
102107
def make_pythonzip():
103108
'''
104109
Search for all the python related files, and construct the pythonXX.zip
@@ -184,6 +189,7 @@ def select(fn):
184189
tf.add(fn, afn)
185190
tf.close()
186191

192+
187193
def make_package(args):
188194
version_code = 0
189195
manifest_extra = '<uses-feature android:glEsVersion="0x00020000" />'
@@ -218,27 +224,33 @@ def make_package(args):
218224
else:
219225
public_version = None
220226

227+
if args.intent_filters:
228+
intent_filters = open(args.intent_filters).read()
229+
else:
230+
intent_filters = ''
231+
221232
# Render the various templates into control files.
222233
render(
223234
'AndroidManifest.tmpl.xml',
224235
'AndroidManifest.xml',
225-
args = args,
226-
url_scheme = url_scheme,
227-
manifest_extra = manifest_extra,
236+
args=args,
237+
url_scheme=url_scheme,
238+
intent_filters=intent_filters,
239+
manifest_extra=manifest_extra,
228240
)
229241

230242
render(
231243
build_tpl,
232244
'build.xml',
233-
args = args,
234-
versioned_name = versioned_name)
245+
args=args,
246+
versioned_name=versioned_name)
235247

236248
render(
237249
'strings.xml',
238250
'res/values/strings.xml',
239-
public_version = public_version,
240-
private_version = private_version,
241-
url_scheme = url_scheme,
251+
public_version=public_version,
252+
private_version=private_version,
253+
url_scheme=url_scheme,
242254
args=args)
243255

244256
# Update the project to a recent version.
@@ -263,12 +275,12 @@ def make_package(args):
263275

264276
# Package up the private and public data.
265277
if args.private:
266-
make_tar('assets/private.mp3', [ 'private', args.private ])
278+
make_tar('assets/private.mp3', ['private', args.private])
267279
else:
268-
make_tar('assets/private.mp3', [ 'private' ])
280+
make_tar('assets/private.mp3', ['private'])
269281

270282
if args.dir:
271-
make_tar('assets/public.mp3', [ args.dir ], args.ignore_path)
283+
make_tar('assets/public.mp3', [args.dir], args.ignore_path)
272284

273285
# Copy over the icon and presplash files.
274286
shutil.copy(args.icon or default_icon, 'res/drawable/icon.png')
@@ -308,6 +320,7 @@ def make_package(args):
308320
ap.add_argument('--presplash', dest='presplash', help='A jpeg file to use as a screen while the application is loading.')
309321
ap.add_argument('--install-location', dest='install_location', default='auto', help='The default install location. Should be "auto", "preferExternal" or "internalOnly".')
310322
ap.add_argument('--compile-pyo', dest='compile_pyo', action='store_true', help='Compile all .py files to .pyo, and only distribute the compiled bytecode.')
323+
ap.add_argument('--intent_filters', dest='intent_filters', help='Add intent-filters xml rules to AndroidManifest.xml')
311324
ap.add_argument('--blacklist', dest='blacklist',
312325
default=join(curdir, 'blacklist.txt'),
313326
help='Use a blacklist file to match unwanted file in the final APK')
@@ -319,10 +332,10 @@ def make_package(args):
319332
ap.error('One of --dir, --private, or --launcher must be supplied.')
320333

321334
if args.permissions is None:
322-
args.permissions = [ ]
335+
args.permissions = []
323336

324337
if args.ignore_path is None:
325-
args.ignore_path = [ ]
338+
args.ignore_path = []
326339

327340
if args.compile_pyo:
328341
if PYTHON is None:
@@ -336,4 +349,3 @@ def make_package(args):
336349
BLACKLIST_PATTERNS += patterns
337350

338351
make_package(args)
339-

src/templates/AndroidManifest.tmpl.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
</intent-filter>
3333
{% endif %}
3434

35+
{%if args.intent_filters %}
36+
{{ intent_filters }}
37+
{% endif %}
3538
</activity>
3639

3740
{% if args.launcher %}

0 commit comments

Comments
 (0)