2021-04-26 06:25:32 +02:00
|
|
|
#!/usr/bin/env python
|
2019-05-01 20:57:03 +02:00
|
|
|
# coding: utf-8
|
|
|
|
# PYTHON_ARGCOMPLETE_OK
|
|
|
|
# Copyright: (c) 2019, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from straight.plugin import load
|
|
|
|
|
|
|
|
try:
|
|
|
|
import argcomplete
|
|
|
|
except ImportError:
|
|
|
|
argcomplete = None
|
|
|
|
|
|
|
|
|
2019-07-16 21:19:01 +02:00
|
|
|
def build_lib_path(this_script=__file__):
|
2020-07-17 22:07:35 +02:00
|
|
|
"""Return path to the common build library directory."""
|
2019-05-01 20:57:03 +02:00
|
|
|
hacking_dir = os.path.dirname(this_script)
|
|
|
|
libdir = os.path.abspath(os.path.join(hacking_dir, 'build_library'))
|
|
|
|
|
2019-07-16 21:19:01 +02:00
|
|
|
return libdir
|
2019-05-01 20:57:03 +02:00
|
|
|
|
|
|
|
|
2020-07-17 22:07:35 +02:00
|
|
|
def ansible_lib_path(this_script=__file__):
|
|
|
|
"""Return path to the common build library directory."""
|
|
|
|
hacking_dir = os.path.dirname(this_script)
|
|
|
|
libdir = os.path.abspath(os.path.join(hacking_dir, '..', 'lib'))
|
|
|
|
|
|
|
|
return libdir
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, ansible_lib_path())
|
2019-07-16 21:19:01 +02:00
|
|
|
sys.path.insert(0, build_lib_path())
|
2019-05-01 20:57:03 +02:00
|
|
|
|
2020-07-17 22:07:35 +02:00
|
|
|
|
2019-07-16 21:19:01 +02:00
|
|
|
from build_ansible import commands, errors
|
2019-05-01 20:57:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
def create_arg_parser(program_name):
|
|
|
|
"""
|
|
|
|
Creates a command line argument parser
|
|
|
|
|
|
|
|
:arg program_name: The name of the script. Used in help texts
|
|
|
|
"""
|
|
|
|
parser = argparse.ArgumentParser(prog=program_name,
|
|
|
|
description="Implements utilities to build Ansible")
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""
|
2020-07-17 22:07:35 +02:00
|
|
|
Start our run.
|
2019-05-01 20:57:03 +02:00
|
|
|
|
|
|
|
"It all starts here"
|
|
|
|
"""
|
|
|
|
subcommands = load('build_ansible.command_plugins', subclasses=commands.Command)
|
|
|
|
|
|
|
|
arg_parser = create_arg_parser(os.path.basename(sys.argv[0]))
|
2020-07-17 22:07:35 +02:00
|
|
|
arg_parser.add_argument('--debug', dest='debug', required=False, default=False,
|
|
|
|
action='store_true',
|
2019-09-10 02:28:52 +02:00
|
|
|
help='Show tracebacks and other debugging information')
|
2019-05-01 20:57:03 +02:00
|
|
|
subparsers = arg_parser.add_subparsers(title='Subcommands', dest='command',
|
2019-07-02 21:18:40 +02:00
|
|
|
help='for help use build-ansible.py SUBCOMMANDS -h')
|
2019-05-01 20:57:03 +02:00
|
|
|
subcommands.pipe('init_parser', subparsers.add_parser)
|
|
|
|
|
|
|
|
if argcomplete:
|
|
|
|
argcomplete.autocomplete(arg_parser)
|
|
|
|
|
|
|
|
args = arg_parser.parse_args(sys.argv[1:])
|
2019-07-16 21:19:01 +02:00
|
|
|
if args.command is None:
|
|
|
|
print('Please specify a subcommand to run')
|
|
|
|
sys.exit(1)
|
2019-05-01 20:57:03 +02:00
|
|
|
|
|
|
|
for subcommand in subcommands:
|
|
|
|
if subcommand.name == args.command:
|
2019-07-16 21:19:01 +02:00
|
|
|
command = subcommand
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# Note: We should never trigger this because argparse should shield us from it
|
|
|
|
print('Error: {0} was not a recognized subcommand'.format(args.command))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
retval = command.main(args)
|
2019-09-10 02:28:52 +02:00
|
|
|
except (errors.DependencyError, errors.MissingUserInput, errors.InvalidUserInput) as e:
|
2019-07-16 21:19:01 +02:00
|
|
|
print(e)
|
2019-09-10 02:28:52 +02:00
|
|
|
if args.debug:
|
|
|
|
raise
|
2019-07-16 21:19:01 +02:00
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
sys.exit(retval)
|
2019-05-01 20:57:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|