<s> """<STR_LIT>""" <EOL> import json <EOL> import argparse <EOL> import logging <EOL> import os <EOL> import sys <EOL> import pkg_resources <EOL> from atomic_reactor import set_logging <EOL> from atomic_reactor . api import build_image_here , build_image_in_privileged_container , build_image_using_hosts_docker <EOL> from atomic_reactor . constants import CONTAINER_BUILD_JSON_PATH , DESCRIPTION , PROG <EOL> from atomic_reactor . buildimage import BuildImageBuilder <EOL> from atomic_reactor . inner import build_inside , BuildResults <EOL> from atomic_reactor . util import process_substitutions <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def cli_create_build_image ( args ) : <EOL> b = BuildImageBuilder ( reactor_tarball_path = args . reactor_tarball_path , <EOL> reactor_local_path = args . reactor_local_path , <EOL> reactor_remote_path = args . reactor_remote_git , <EOL> use_official_reactor_git = args . reactor_latest ) <EOL> try : <EOL> b . create_image ( args . dockerfile_dir_path , args . image , use_cache = args . use_cache ) <EOL> except RuntimeError : <EOL> logger . error ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> def cli_build_image ( args ) : <EOL> if args . plugin_files : <EOL> args . plugin_files = [ os . path . abspath ( f ) for f in args . plugin_files ] <EOL> if args . source__provider == '<STR_LIT>' : <EOL> with open ( args . json_path ) as json_fp : <EOL> common_kwargs = json . load ( json_fp ) <EOL> if args . substitute : <EOL> process_substitutions ( common_kwargs , args . substitute ) <EOL> else : <EOL> common_kwargs = construct_kwargs ( ** vars ( args ) ) <EOL> response = BuildResults ( ) <EOL> if args . method == "<STR_LIT>" : <EOL> response = build_image_using_hosts_docker ( args . build_image , ** common_kwargs ) <EOL> elif args . method == "<STR_LIT>" : <EOL> response = build_image_in_privileged_container ( args . build_image , ** common_kwargs ) <EOL> elif args . method == '<STR_LIT>' : <EOL> build_result = build_image_here ( plugin_files = args . plugin_files , ** common_kwargs ) <EOL> if build_result . is_failed ( ) : <EOL> response . return_code = - <NUM_LIT:1> <EOL> else : <EOL> response . return_code = <NUM_LIT:0> <EOL> if response . return_code != <NUM_LIT:0> : <EOL> logger . error ( "<STR_LIT>" ) <EOL> sys . exit ( response . return_code ) <EOL> def construct_kwargs ( ** kwargs ) : <EOL> ret = { } <EOL> ret [ '<STR_LIT:source>' ] = { '<STR_LIT>' : { } } <EOL> recognized_kwargs = [ '<STR_LIT:image>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> is_recognized_kwarg = lambda x : x in recognized_kwargs or x . startswith ( '<STR_LIT>' ) <EOL> for k , v in kwargs . items ( ) : <EOL> if is_recognized_kwarg ( k ) : <EOL> if k . startswith ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:source>' ] [ '<STR_LIT>' ] [ k . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] ] = v <EOL> elif k . startswith ( '<STR_LIT>' ) : <EOL> ret [ '<STR_LIT:source>' ] [ k . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] ] = v <EOL> else : <EOL> ret [ k ] = v <EOL> return ret <EOL> def cli_inside_build ( args ) : <EOL> build_inside ( input_method = args . input , input_args = args . input_arg , substitutions = args . substitute ) <EOL> class CLI ( object ) : <EOL> def __init__ ( self , formatter_class = argparse . HelpFormatter , prog = PROG ) : <EOL> self . parser = argparse . ArgumentParser ( <EOL> prog = prog , <EOL> description = DESCRIPTION , <EOL> formatter_class = formatter_class , <EOL> ) <EOL> self . build_parser = None <EOL> self . bi_parser = None <EOL> self . ib_parser = None <EOL> def set_arguments ( self ) : <EOL> try : <EOL> version = pkg_resources . get_distribution ( "<STR_LIT>" ) . version <EOL> except pkg_resources . DistributionNotFound : <EOL> version = "<STR_LIT>" <EOL> exclusive_group = self . parser . add_mutually_exclusive_group ( ) <EOL> exclusive_group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" ) <EOL> exclusive_group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" ) <EOL> exclusive_group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:version>" , version = version ) <EOL> subparsers = self . parser . add_subparsers ( help = '<STR_LIT>' ) <EOL> self . build_parser = subparsers . add_parser ( <EOL> '<STR_LIT>' , <EOL> usage = "<STR_LIT>" % PROG , <EOL> description = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def cli_build_with_source ( args ) : <EOL> if args . source__provider is None : <EOL> self . build_parser . print_help ( ) <EOL> else : <EOL> cli_build_image ( args ) <EOL> self . build_parser . set_defaults ( func = cli_build_with_source ) <EOL> self . generate_source_types_subparsers ( ) <EOL> self . bi_parser = subparsers . add_parser ( '<STR_LIT>' , <EOL> usage = "<STR_LIT>" % PROG , <EOL> description = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . bi_parser . set_defaults ( func = cli_create_build_image ) <EOL> reactor_source = self . bi_parser . add_mutually_exclusive_group ( ) <EOL> reactor_source . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> reactor_source . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store>' , <EOL> help = "<STR_LIT>" ) <EOL> reactor_source . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store>' , <EOL> help = "<STR_LIT>" ) <EOL> reactor_source . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store>' , <EOL> help = "<STR_LIT>" ) <EOL> self . bi_parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> self . bi_parser . add_argument ( "<STR_LIT:image>" , action = '<STR_LIT:store>' , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> self . bi_parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> self . ib_parser = subparsers . add_parser ( <EOL> '<STR_LIT>' , <EOL> usage = "<STR_LIT>" % PROG , <EOL> description = "<STR_LIT>" <EOL> "<STR_LIT>" % CONTAINER_BUILD_JSON_PATH + <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . ib_parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store>' , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> self . ib_parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . ib_parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> self . ib_parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . ib_parser . set_defaults ( func = cli_inside_build ) <EOL> def generate_source_types_subparsers ( self ) : <EOL> build_subparsers = self . build_parser . add_subparsers ( help = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' ) <EOL> self . source_types_parsers = { <EOL> '<STR_LIT>' : build_subparsers . add_parser ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> usage = "<STR_LIT>" % PROG ) , <EOL> '<STR_LIT:path>' : build_subparsers . add_parser ( <EOL> '<STR_LIT:path>' , <EOL> help = '<STR_LIT>' , <EOL> usage = "<STR_LIT>" % PROG ) , <EOL> } <EOL> source_types_uri_help = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> } <EOL> source_types_df_path_help = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> } <EOL> for st , stp in self . source_types_parsers . items ( ) : <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , required = True , <EOL> help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , metavar = "<STR_LIT>" , required = True , <EOL> help = source_types_uri_help [ st ] , dest = '<STR_LIT>' ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , help = source_types_df_path_help [ st ] , <EOL> dest = '<STR_LIT>' ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , nargs = "<STR_LIT:*>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> self . source_types_parsers [ '<STR_LIT>' ] = build_subparsers . add_parser ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> usage = "<STR_LIT>" % PROG ) <EOL> for stp in self . source_types_parsers . values ( ) : <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , <EOL> help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = "<STR_LIT:store>" , nargs = "<STR_LIT:*>" , metavar = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> stp . add_argument ( <EOL> "<STR_LIT>" , action = '<STR_LIT:store>' , required = True , <EOL> choices = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . source_types_parsers [ '<STR_LIT>' ] . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) <EOL> self . source_types_parsers [ '<STR_LIT>' ] . add_argument ( <EOL> '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> self . source_types_parsers [ '<STR_LIT>' ] . add_argument ( <EOL> '<STR_LIT>' , nargs = '<STR_LIT:*>' , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> def run ( self ) : <EOL> self . set_arguments ( ) <EOL> args = self . parser . parse_args ( ) <EOL> try : <EOL> logging . captureWarnings ( True ) <EOL> except AttributeError : <EOL> pass <EOL> if args . verbose : <EOL> set_logging ( level = logging . DEBUG ) <EOL> elif args . quiet : <EOL> set_logging ( level = logging . WARNING ) <EOL> else : <EOL> set_logging ( level = logging . INFO ) <EOL> try : <EOL> args . func ( args ) <EOL> except AttributeError : <EOL> if hasattr ( args , '<STR_LIT>' ) : <EOL> raise <EOL> else : <EOL> self . parser . print_help ( ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> except Exception as ex : <EOL> if args . verbose : <EOL> raise <EOL> else : <EOL> logger . error ( "<STR_LIT>" , ex ) <EOL> def run ( ) : <EOL> cli = CLI ( ) <EOL> cli . run ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> run ( ) </s>
