implement profiles. bump to 0.6
This commit is contained in:
parent
70bec9fb0c
commit
efc5c7b3e4
2 changed files with 79 additions and 18 deletions
|
@ -10,7 +10,7 @@ Layout directory for buildozer:
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
__version__ = '0.5'
|
__version__ = '0.6'
|
||||||
|
|
||||||
import fcntl
|
import fcntl
|
||||||
import os
|
import os
|
||||||
|
@ -84,6 +84,7 @@ class Buildozer(object):
|
||||||
self.specfilename = filename
|
self.specfilename = filename
|
||||||
self.state = None
|
self.state = None
|
||||||
self.build_id = None
|
self.build_id = None
|
||||||
|
self.config_profile = ''
|
||||||
self.config = SafeConfigParser(allow_no_value=True)
|
self.config = SafeConfigParser(allow_no_value=True)
|
||||||
self.config.getlist = self._get_config_list
|
self.config.getlist = self._get_config_list
|
||||||
self.config.getdefault = self._get_config_default
|
self.config.getdefault = self._get_config_default
|
||||||
|
@ -93,7 +94,6 @@ class Buildozer(object):
|
||||||
self.config.read(filename)
|
self.config.read(filename)
|
||||||
self.check_configuration_tokens()
|
self.check_configuration_tokens()
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.log_level = int(self.config.getdefault(
|
self.log_level = int(self.config.getdefault(
|
||||||
'buildozer', 'log_level', '1'))
|
'buildozer', 'log_level', '1'))
|
||||||
|
@ -705,7 +705,9 @@ class Buildozer(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def usage(self):
|
def usage(self):
|
||||||
print 'Usage: buildozer [--verbose] [target] [command1] [command2]'
|
print 'Usage:'
|
||||||
|
print ' buildozer [--profile <name>] [--verbose] [target] <command>...'
|
||||||
|
print ' buildozer --version'
|
||||||
print
|
print
|
||||||
print 'Available targets:'
|
print 'Available targets:'
|
||||||
targets = list(self.targets())
|
targets = list(self.targets())
|
||||||
|
@ -766,14 +768,19 @@ class Buildozer(object):
|
||||||
if arg in ('-v', '--verbose'):
|
if arg in ('-v', '--verbose'):
|
||||||
self.log_level = 2
|
self.log_level = 2
|
||||||
|
|
||||||
if arg in ('-h', '--help'):
|
elif arg in ('-h', '--help'):
|
||||||
self.usage()
|
self.usage()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if arg == '--version':
|
elif arg in ('-p', '--profile'):
|
||||||
|
self.config_profile = args.pop(0)
|
||||||
|
|
||||||
|
elif arg == '--version':
|
||||||
print 'Buildozer {0}'.format(__version__)
|
print 'Buildozer {0}'.format(__version__)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
self._merge_config_profile()
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
self.run_default()
|
self.run_default()
|
||||||
return
|
return
|
||||||
|
@ -829,6 +836,37 @@ class Buildozer(object):
|
||||||
# Private
|
# Private
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def _merge_config_profile(self):
|
||||||
|
profile = self.config_profile
|
||||||
|
if not profile:
|
||||||
|
return
|
||||||
|
for section in self.config.sections():
|
||||||
|
|
||||||
|
# extract the profile part from the section name
|
||||||
|
# example: [app@default,hd]
|
||||||
|
parts = section.split('@', 1)
|
||||||
|
if len(parts) < 2:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# create a list that contain all the profiles of the current section
|
||||||
|
# ['default', 'hd']
|
||||||
|
section_base, section_profiles = parts
|
||||||
|
section_profiles = section_profiles.split(',')
|
||||||
|
if profile not in section_profiles:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# the current profile is one available in the section
|
||||||
|
# merge with the general section, or make it one.
|
||||||
|
if not self.config.has_section(section_base):
|
||||||
|
self.config.add_section(section_base)
|
||||||
|
for name, value in self.config.items(section):
|
||||||
|
print 'merged ({}, {}) into {} (profile is {})'.format(name,
|
||||||
|
value, section_base, profile)
|
||||||
|
self.config.set(section_base, name, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _get_config_list(self, section, token, default=None):
|
def _get_config_list(self, section, token, default=None):
|
||||||
# monkey-patch method for ConfigParser
|
# monkey-patch method for ConfigParser
|
||||||
# get a key as a list of string, seperated from the comma
|
# get a key as a list of string, seperated from the comma
|
||||||
|
@ -865,6 +903,7 @@ class Buildozer(object):
|
||||||
return default
|
return default
|
||||||
return self.config.getboolean(section, token)
|
return self.config.getboolean(section, token)
|
||||||
|
|
||||||
|
|
||||||
class BuildozerRemote(Buildozer):
|
class BuildozerRemote(Buildozer):
|
||||||
def run_command(self, args):
|
def run_command(self, args):
|
||||||
while args:
|
while args:
|
||||||
|
@ -875,14 +914,19 @@ class BuildozerRemote(Buildozer):
|
||||||
if arg in ('-v', '--verbose'):
|
if arg in ('-v', '--verbose'):
|
||||||
self.log_level = 2
|
self.log_level = 2
|
||||||
|
|
||||||
if arg in ('-h', '--help'):
|
elif arg in ('-p', '--profile'):
|
||||||
|
self.config_profile = args.pop(0)
|
||||||
|
|
||||||
|
elif arg in ('-h', '--help'):
|
||||||
self.usage()
|
self.usage()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if arg == '--version':
|
elif arg == '--version':
|
||||||
print 'Buildozer (remote) {0}'.format(__version__)
|
print 'Buildozer (remote) {0}'.format(__version__)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
self._merge_config_profile()
|
||||||
|
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
self.usage()
|
self.usage()
|
||||||
return
|
return
|
||||||
|
@ -1035,10 +1079,6 @@ class BuildozerRemote(Buildozer):
|
||||||
finally:
|
finally:
|
||||||
channel.close()
|
channel.close()
|
||||||
|
|
||||||
def usage(self):
|
|
||||||
print 'Usage: buildozer-remote [--verbose] [remote-name] [buildozer args]'
|
|
||||||
|
|
||||||
|
|
||||||
def _interactive_shell(self, chan):
|
def _interactive_shell(self, chan):
|
||||||
if has_termios:
|
if has_termios:
|
||||||
self._posix_shell(chan)
|
self._posix_shell(chan)
|
||||||
|
|
|
@ -115,18 +115,39 @@ log_level = 1
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Alternatively, you can define all the "list" as [section:key].
|
# List as sections
|
||||||
|
#
|
||||||
|
# You can define all the "list" as [section:key].
|
||||||
# Each line will be considered as a option to the list.
|
# Each line will be considered as a option to the list.
|
||||||
# Let's take [app] / source.exclude_patterns.
|
# Let's take [app] / source.exclude_patterns.
|
||||||
# Instead of doing:
|
# Instead of doing:
|
||||||
#
|
#
|
||||||
# [app]
|
# [app]
|
||||||
# source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
|
# source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
|
||||||
#
|
#
|
||||||
# This can be translated into:
|
# This can be translated into:
|
||||||
#
|
#
|
||||||
# [app:source.exclude_patterns]
|
# [app:source.exclude_patterns]
|
||||||
# license
|
# license
|
||||||
# data/audio/*.wav
|
# data/audio/*.wav
|
||||||
# data/images/original/*
|
# data/images/original/*
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Profiles
|
||||||
|
#
|
||||||
|
# You can extend section / key with a profile
|
||||||
|
# For example, you want to deploy a demo version of your application without
|
||||||
|
# HD content. You could first change the title to add "(demo)" in the name
|
||||||
|
# and extend the excluded directories to remove the HD content.
|
||||||
|
#
|
||||||
|
# [app@demo]
|
||||||
|
# title = My Application (demo)
|
||||||
|
#
|
||||||
|
# [app:source.exclude_patterns@demo]
|
||||||
|
# images/hd/*
|
||||||
|
#
|
||||||
|
# Then, invoke the command line with the "demo" profile:
|
||||||
|
#
|
||||||
|
# buildozer --profile demo android debug
|
||||||
|
|
Loading…
Add table
Reference in a new issue