|
8 | 8 |
|
9 | 9 | from __future__ import print_function |
10 | 10 |
|
11 | | - |
12 | 11 | def check_python_dependencies(): |
13 | 12 | # Check if the Python requirements are installed. This appears |
14 | 13 | # before the imports because otherwise they're imported elsewhere. |
@@ -76,6 +75,7 @@ def check_python_dependencies(): |
76 | 75 |
|
77 | 76 | import argparse |
78 | 77 | import sh |
| 78 | +import imp |
79 | 79 | from appdirs import user_data_dir |
80 | 80 | import logging |
81 | 81 |
|
@@ -293,12 +293,17 @@ def __init__(self): |
293 | 293 | help=('Dependencies of your app, should be recipe names or ' |
294 | 294 | 'Python modules'), |
295 | 295 | default='') |
296 | | - |
| 296 | + |
297 | 297 | generic_parser.add_argument( |
298 | 298 | '--bootstrap', |
299 | 299 | help='The bootstrap to build with. Leave unset to choose automatically.', |
300 | 300 | default=None) |
301 | 301 |
|
| 302 | + generic_parser.add_argument( |
| 303 | + '--hook', |
| 304 | + help='Filename to a module that contain python-for-android hooks', |
| 305 | + default=None) |
| 306 | + |
302 | 307 | add_boolean_option( |
303 | 308 | generic_parser, ["force-build"], |
304 | 309 | default=False, |
@@ -488,6 +493,18 @@ def add_parser(subparsers, *args, **kwargs): |
488 | 493 | # Each subparser corresponds to a method |
489 | 494 | getattr(self, args.subparser_name.replace('-', '_'))(args) |
490 | 495 |
|
| 496 | + def hook(self, name): |
| 497 | + if not self.args.hook: |
| 498 | + return |
| 499 | + if not hasattr(self, "hook_module"): |
| 500 | + # first time, try to load the hook module |
| 501 | + self.hook_module = imp.load_source("pythonforandroid.hook", self.args.hook) |
| 502 | + if hasattr(self.hook_module, name): |
| 503 | + info("Hook: execute {}".format(name)) |
| 504 | + getattr(self.hook_module, name)(self) |
| 505 | + else: |
| 506 | + info("Hook: ignore {}".format(name)) |
| 507 | + |
491 | 508 | @property |
492 | 509 | def default_storage_dir(self): |
493 | 510 | udd = user_data_dir('python-for-android') |
@@ -691,8 +708,12 @@ def apk(self, args): |
691 | 708 |
|
692 | 709 | build = imp.load_source('build', join(dist.dist_dir, 'build.py')) |
693 | 710 | with current_directory(dist.dist_dir): |
| 711 | + self.hook("before_apk_build") |
694 | 712 | build_args = build.parse_args(args.unknown_args) |
| 713 | + self.hook("after_apk_build") |
| 714 | + self.hook("before_apk_assemble") |
695 | 715 | output = shprint(sh.ant, args.build_mode, _tail=20, _critical=True, _env=env) |
| 716 | + self.hook("after_apk_assemble") |
696 | 717 |
|
697 | 718 | info_main('# Copying APK to current directory') |
698 | 719 |
|
@@ -807,7 +828,7 @@ def _adb(self, commands): |
807 | 828 | for line in output: |
808 | 829 | sys.stdout.write(line) |
809 | 830 | sys.stdout.flush() |
810 | | - |
| 831 | + |
811 | 832 |
|
812 | 833 | def build_status(self, args): |
813 | 834 |
|
|
0 commit comments