Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement the clean command. #79

Merged
merged 14 commits into from
Apr 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BuildozerCommandException(BuildozerException):

class Buildozer(object):

standard_cmds = ('clean', 'update', 'debug', 'release',
standard_cmds = ('distclean', 'update', 'debug', 'release',
'deploy', 'run', 'serve')

def __init__(self, filename='buildozer.spec', target=None):
Expand All @@ -100,6 +100,10 @@ def __init__(self, filename='buildozer.spec', target=None):
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'))
Expand Down Expand Up @@ -302,7 +306,7 @@ def check_configuration_tokens(self):
adderror('[app] "title" is missing')
if not get('app', 'source.dir', ''):
adderror('[app] "source.dir" is missing')

package_name = get('app', 'package.name', '')
if not package_name:
adderror('[app] "package.name" is missing')
Expand Down Expand Up @@ -846,10 +850,17 @@ def cmd_init(self, *args):
copyfile(join(dirname(__file__), 'default.spec'), 'buildozer.spec')
print 'File buildozer.spec created, ready to customize!'

def cmd_clean(self, *args):
def cmd_distclean(self, *args):
'''Clean the whole Buildozer environment.
'''
pass
import sys
print("Warning: Your ndk, sdk and all other cached packages will be"+\
" removed. Continue? (y/n)")
if sys.stdin.readline().lower()[0] == 'y':
self.info('Clean the global build directory')
if not exists(self.global_buildozer_dir):
return
rmtree(self.global_buildozer_dir)

def cmd_help(self, *args):
'''Show the Buildozer help.
Expand Down Expand Up @@ -919,6 +930,9 @@ def _get_config_list(self, section, token, default=None, with_values=False):
# 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):
Expand All @@ -939,7 +953,12 @@ def _get_config_list(self, section, token, default=None, with_values=False):

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):
Expand All @@ -949,6 +968,10 @@ def _get_config_default(self, section, token, default=None):
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):
Expand Down Expand Up @@ -1211,3 +1234,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
3 changes: 3 additions & 0 deletions buildozer/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 13 additions & 5 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ def install_platform(self):
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)
Expand Down Expand Up @@ -352,7 +357,9 @@ def compile_platform(self):
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:
Expand All @@ -362,8 +369,8 @@ def compile_platform(self):
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'))
Expand All @@ -383,7 +390,8 @@ def _get_package(self):
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()
Expand Down