<s> import sys <EOL> import argparse <EOL> import logging <EOL> import os <EOL> import subprocess <EOL> import warnings <EOL> from wlauto . core . bootstrap import settings <EOL> from wlauto . core . extension_loader import ExtensionLoader <EOL> from wlauto . exceptions import WAError , ConfigError <EOL> from wlauto . utils . misc import get_traceback <EOL> from wlauto . utils . log import init_logging <EOL> from wlauto . utils . cli import init_argument_parser <EOL> from wlauto . utils . doc import format_body <EOL> warnings . filterwarnings ( action = '<STR_LIT:ignore>' , category = UserWarning , module = '<STR_LIT>' ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def load_commands ( subparsers ) : <EOL> ext_loader = ExtensionLoader ( paths = settings . extension_paths ) <EOL> for command in ext_loader . list_commands ( ) : <EOL> settings . commands [ command . name ] = ext_loader . get_command ( command . name , subparsers = subparsers ) <EOL> def main ( ) : <EOL> try : <EOL> description = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser = argparse . ArgumentParser ( description = format_body ( description , <NUM_LIT> ) , <EOL> prog = '<STR_LIT>' , <EOL> formatter_class = argparse . RawDescriptionHelpFormatter , <EOL> ) <EOL> init_argument_parser ( parser ) <EOL> load_commands ( parser . add_subparsers ( dest = '<STR_LIT>' ) ) <EOL> args = parser . parse_args ( ) <EOL> settings . verbosity = args . verbose <EOL> settings . debug = args . debug <EOL> if args . config : <EOL> if not os . path . exists ( args . config ) : <EOL> raise ConfigError ( "<STR_LIT>" . format ( args . config ) ) <EOL> settings . update ( args . config ) <EOL> init_logging ( settings . verbosity ) <EOL> command = settings . commands [ args . command ] <EOL> sys . exit ( command . execute ( args ) ) <EOL> except KeyboardInterrupt : <EOL> logging . info ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> except WAError as e : <EOL> logging . critical ( e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> except subprocess . CalledProcessError as e : <EOL> tb = get_traceback ( ) <EOL> logging . critical ( tb ) <EOL> command = e . cmd <EOL> if e . args : <EOL> command = '<STR_LIT>' . format ( command , '<STR_LIT:U+0020>' . join ( e . args ) ) <EOL> message = '<STR_LIT>' <EOL> logging . critical ( message . format ( command , e . returncode , e . output ) ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> except SyntaxError as e : <EOL> tb = get_traceback ( ) <EOL> logging . critical ( tb ) <EOL> message = '<STR_LIT>' <EOL> logging . critical ( message . format ( e . filename , e . lineno , e . offset ) ) <EOL> logging . critical ( '<STR_LIT>' . format ( e . msg ) ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> except Exception as e : <EOL> tb = get_traceback ( ) <EOL> logging . critical ( tb ) <EOL> logging . critical ( '<STR_LIT>' . format ( e . __class__ . __name__ , e ) ) <EOL> sys . exit ( <NUM_LIT:2> ) </s>
