2017-06-14 13:36:37 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# kas - setup tool for bitbake based projects
|
|
|
|
#
|
|
|
|
# Copyright (c) Siemens AG, 2017
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
2017-06-21 13:32:56 +02:00
|
|
|
"""
|
|
|
|
This module is the main entry point for kas, setup tool for bitbake based
|
|
|
|
projects
|
|
|
|
"""
|
2017-06-14 13:36:37 +02:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import traceback
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import pkg_resources
|
|
|
|
|
|
|
|
try:
|
|
|
|
import colorlog
|
2017-06-21 13:32:56 +02:00
|
|
|
HAVE_COLORLOG = True
|
2017-06-14 13:36:37 +02:00
|
|
|
except ImportError:
|
2017-06-21 13:32:56 +02:00
|
|
|
HAVE_COLORLOG = False
|
2017-06-14 13:36:37 +02:00
|
|
|
|
|
|
|
from .build import Build
|
|
|
|
from .shell import Shell
|
2017-06-19 09:16:50 +02:00
|
|
|
from . import __version__
|
2017-06-14 13:36:37 +02:00
|
|
|
|
|
|
|
__license__ = 'MIT'
|
|
|
|
__copyright__ = 'Copyright (c) Siemens AG, 2017'
|
|
|
|
|
|
|
|
|
|
|
|
def create_logger():
|
2017-06-21 13:32:56 +02:00
|
|
|
"""
|
|
|
|
Setup the logging environment
|
|
|
|
"""
|
2017-06-14 13:36:37 +02:00
|
|
|
log = logging.getLogger() # root logger
|
|
|
|
log.setLevel(logging.INFO)
|
2017-06-21 13:32:56 +02:00
|
|
|
format_str = '%(asctime)s - %(levelname)-8s - %(message)s'
|
2017-06-14 13:36:37 +02:00
|
|
|
date_format = '%Y-%m-%d %H:%M:%S'
|
2017-06-21 13:32:56 +02:00
|
|
|
if HAVE_COLORLOG and os.isatty(2):
|
|
|
|
cformat = '%(log_color)s' + format_str
|
2017-06-14 13:36:37 +02:00
|
|
|
colors = {'DEBUG': 'reset',
|
|
|
|
'INFO': 'reset',
|
|
|
|
'WARNING': 'bold_yellow',
|
|
|
|
'ERROR': 'bold_red',
|
|
|
|
'CRITICAL': 'bold_red'}
|
2017-06-21 13:32:56 +02:00
|
|
|
formatter = colorlog.ColoredFormatter(cformat, date_format,
|
|
|
|
log_colors=colors)
|
2017-06-14 13:36:37 +02:00
|
|
|
else:
|
2017-06-21 13:32:56 +02:00
|
|
|
formatter = logging.Formatter(format_str, date_format)
|
|
|
|
stream_handler = logging.StreamHandler()
|
|
|
|
stream_handler.setFormatter(formatter)
|
|
|
|
log.addHandler(stream_handler)
|
2017-06-14 13:36:37 +02:00
|
|
|
return logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def kas(argv):
|
2017-06-21 13:32:56 +02:00
|
|
|
"""
|
|
|
|
The main entry point of kas.
|
|
|
|
"""
|
2017-06-14 13:36:37 +02:00
|
|
|
create_logger()
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Steer ebs-yocto builds')
|
|
|
|
|
|
|
|
parser.add_argument('--version', action='version',
|
|
|
|
version='%(prog)s ' + __version__)
|
|
|
|
|
|
|
|
parser.add_argument('-d', '--debug',
|
|
|
|
action='store_true',
|
|
|
|
help='Enable debug logging')
|
|
|
|
|
|
|
|
subparser = parser.add_subparsers(help='sub command help', dest='cmd')
|
|
|
|
sub_cmds = [Build(subparser), Shell(subparser)]
|
|
|
|
|
|
|
|
for plugin in pkg_resources.iter_entry_points('kas.plugins'):
|
|
|
|
cmd = plugin.load()
|
|
|
|
sub_cmds.append(cmd(subparser))
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
|
|
|
|
if args.debug:
|
|
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
for cmd in sub_cmds:
|
|
|
|
if cmd.run(args):
|
2017-06-15 21:45:45 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
parser.print_help()
|
2017-06-14 13:36:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-06-21 13:32:56 +02:00
|
|
|
"""
|
|
|
|
The main function that operates as a wrapper around kas.
|
|
|
|
"""
|
|
|
|
# pylint: disable=broad-except
|
|
|
|
|
2017-06-14 13:36:37 +02:00
|
|
|
try:
|
|
|
|
sys.exit(kas(sys.argv[1:]))
|
|
|
|
except Exception as err:
|
2017-06-21 13:32:56 +02:00
|
|
|
logging.error('%s', err)
|
2017-06-14 13:36:37 +02:00
|
|
|
traceback.print_exc()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|