Merge pull request #60 from inclement/p4a
Add ability to choose python-for-android directory
This commit is contained in:
commit
c6c0acd78c
3 changed files with 62 additions and 5 deletions
|
@ -100,6 +100,10 @@ class Buildozer(object):
|
|||
self.config.read(filename)
|
||||
self.check_configuration_tokens()
|
||||
|
||||
# Check all section/tokens for env vars, and replace the
|
||||
# config value if a suitable env var exists.
|
||||
set_config_from_envs(self.config)
|
||||
|
||||
try:
|
||||
self.log_level = int(self.config.getdefault(
|
||||
'buildozer', 'log_level', '1'))
|
||||
|
@ -919,6 +923,9 @@ class Buildozer(object):
|
|||
# monkey-patch method for ConfigParser
|
||||
# get a key as a list of string, seperated from the comma
|
||||
|
||||
# check if an env var exists that should replace the file config
|
||||
set_config_token_from_env(section, token, self.config)
|
||||
|
||||
# if a section:token is defined, let's use the content as a list.
|
||||
l_section = '{}:{}'.format(section, token)
|
||||
if self.config.has_section(l_section):
|
||||
|
@ -939,7 +946,12 @@ class Buildozer(object):
|
|||
|
||||
def _get_config_default(self, section, token, default=None):
|
||||
# monkey-patch method for ConfigParser
|
||||
# get an appropriate env var if it exists, else
|
||||
# get a key in a section, or the default
|
||||
|
||||
# check if an env var exists that should replace the file config
|
||||
set_config_token_from_env(section, token, self.config)
|
||||
|
||||
if not self.config.has_section(section):
|
||||
return default
|
||||
if not self.config.has_option(section, token):
|
||||
|
@ -949,6 +961,10 @@ class Buildozer(object):
|
|||
def _get_config_bool(self, section, token, default=False):
|
||||
# monkey-patch method for ConfigParser
|
||||
# get a key in a section, or the default
|
||||
|
||||
# check if an env var exists that should replace the file config
|
||||
set_config_token_from_env(section, token, self.config)
|
||||
|
||||
if not self.config.has_section(section):
|
||||
return default
|
||||
if not self.config.has_option(section, token):
|
||||
|
@ -1211,3 +1227,33 @@ def run_remote():
|
|||
pass
|
||||
except BuildozerException as error:
|
||||
Buildozer().error('%s' % error)
|
||||
|
||||
def set_config_from_envs(config):
|
||||
'''Takes a ConfigParser, and checks every section/token for an
|
||||
environment variable of the form SECTION_TOKEN, with any dots
|
||||
replaced by underscores. If the variable exists, sets the config
|
||||
variable to the env value.
|
||||
'''
|
||||
for section in config.sections():
|
||||
for token in config.options(section):
|
||||
set_config_token_from_env(section, token, config)
|
||||
|
||||
def set_config_token_from_env(section, token, config):
|
||||
'''Given a config section and token, checks for an appropriate
|
||||
environment variable. If the variable exists, sets the config entry to
|
||||
its value.
|
||||
|
||||
The environment variable checked is of the form SECTION_TOKEN, all
|
||||
upper case, with any dots replaced by underscores.
|
||||
|
||||
Returns True if the environment variable exists and was used, or
|
||||
False otherwise.
|
||||
|
||||
'''
|
||||
env_var_name = ''.join([section.upper(), '_',
|
||||
token.upper().replace('.', '_')])
|
||||
env_var = os.environ.get(env_var_name)
|
||||
if env_var is None:
|
||||
return False
|
||||
config.set(section, token, env_var)
|
||||
return True
|
||||
|
|
|
@ -75,6 +75,9 @@ fullscreen = 1
|
|||
# (str) Android SDK directory (if empty, it will be automatically downloaded.)
|
||||
#android.sdk_path =
|
||||
|
||||
# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
|
||||
#android.p4a_dir =
|
||||
|
||||
# (str) Android entry point, default is ok for Kivy-based app
|
||||
#android.entrypoint = org.renpy.android.PythonActivity
|
||||
|
||||
|
|
|
@ -301,7 +301,12 @@ class TargetAndroid(Target):
|
|||
cmd = self.buildozer.cmd
|
||||
self.pa_dir = pa_dir = join(self.buildozer.platform_dir, 'python-for-android')
|
||||
if not self.buildozer.file_exists(pa_dir):
|
||||
cmd('git clone git://github.com/kivy/python-for-android',
|
||||
system_p4a_dir = self.buildozer.config.getdefault('app', 'p4a_dir')
|
||||
if system_p4a_dir:
|
||||
cmd('ln -s {} ./python-for-android'.format(system_p4a_dir),
|
||||
cwd = self.buildozer.platform_dir)
|
||||
else:
|
||||
cmd('git clone git://github.com/kivy/python-for-android',
|
||||
cwd=self.buildozer.platform_dir)
|
||||
elif self.platform_update:
|
||||
cmd('git clean -dxf', cwd=pa_dir)
|
||||
|
@ -352,7 +357,9 @@ class TargetAndroid(Target):
|
|||
need_compile = 0
|
||||
if last_requirements != android_requirements:
|
||||
need_compile = 1
|
||||
if not self.buildozer.file_exists(self.pa_dir, 'dist', 'default', 'build.py'):
|
||||
|
||||
dist_name = self.buildozer.config.get('app', 'package.name')
|
||||
if not self.buildozer.file_exists(self.pa_dir, 'dist', dist_name, 'build.py'):
|
||||
need_compile = 1
|
||||
|
||||
if not need_compile:
|
||||
|
@ -362,8 +369,8 @@ class TargetAndroid(Target):
|
|||
modules_str = ' '.join(android_requirements)
|
||||
cmd = self.buildozer.cmd
|
||||
self.buildozer.debug('Clean and build python-for-android')
|
||||
cmd('git clean -dxf', cwd=self.pa_dir)
|
||||
cmd('./distribute.sh -m "{0}"'.format(modules_str), cwd=self.pa_dir)
|
||||
cmd('./distribute.sh -m "{0}" -d "{1}"'.format(modules_str, dist_name),
|
||||
cwd=self.pa_dir)
|
||||
self.buildozer.debug('Remove temporary build files')
|
||||
self.buildozer.rmdir(join(self.pa_dir, 'build'))
|
||||
self.buildozer.rmdir(join(self.pa_dir, '.packages'))
|
||||
|
@ -383,7 +390,8 @@ class TargetAndroid(Target):
|
|||
return package.lower()
|
||||
|
||||
def build_package(self):
|
||||
dist_dir = join(self.pa_dir, 'dist', 'default')
|
||||
dist_name = self.buildozer.config.get('app', 'package.name')
|
||||
dist_dir = join(self.pa_dir, 'dist', dist_name)
|
||||
config = self.buildozer.config
|
||||
package = self._get_package()
|
||||
version = self.buildozer.get_version()
|
||||
|
|
Loading…
Add table
Reference in a new issue