# Path: servi/command.py
# def process_and_run_command_line(command_line=None):
#         servi_parser, sub_parsers = setup_parsers()
# 
#         commands = load_plugins(sub_parsers)
# 
#         args, extra_args = parse_args(commands, servi_parser, command_line)
# 
#         log_level = arg_to_log_level(args.verbose)
#         retval = False
#         with use_log_level(log_level):
#             if args.template_dir:
#                 c.TMPL_DIR_SITE = args.template_dir
#                 warn('*** Just set TMPL_DIR_SITE to |{0}|'.format(
#                     c.TMPL_DIR_SITE))
# 
#             if not args.command:
#                 error('\n***** Error ******\nNo command on command line.\n')
#                 servi_parser.print_help()
#                 raise ServiError('No command line')
# 
#             if args.command not in commands:
#                 raise ServiError('Unknown command: {0}'.format(args.command))
# 
#             special = getattr(commands[args.command], "special", {})
# 
#             if not special.get("skip_init", False):
#                 master_dir = c.find_master_dir(os.getcwd())
#                 set_master_dir(master_dir)
#                 load_user_config()
# 
#             try:
#                 info('Servi - Running: {0}\n'.format(args.command))
#                 if c.MASTER_DIR:
#                     debug('Master Directory: {0}'
#                           .format(os.path.abspath(c.MASTER_DIR)))
#                 debug('Template Directory: {0}'
#                       .format(os.path.abspath(c.TMPL_DIR_SITE)))
# 
#                 retval = args.command_func(args, extra_args)
#             except (ForceError, ServiError):
#                 raise
# 
# 
#         return retval
# 
# Path: servi/exceptions.py
# class ServiError(Exception):
#     # Expected errrors. Handle gracefully (ie: no stack dump)
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             '{0}\n'
#             '\n**Servi Aborting**'.format(self.msg))
# 
# class ForceError(Exception):
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             '{0}\n'
#             'Use -f / --force to override.\n'
#             '\n**Servi Aborting**'.format(self.msg))
# 
# class MasterNotFound(Exception):
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             'Master directory not found at or above current directory.\n'
#             'Looking for: <master>/ServiFile.yml\n'
#             'Above cwd: {0}\n'
#             'Run "servi init <dirname>"\n'
#             '\n**Servi Aborting**'.format(os.getcwd()))
# 
# Path: servi/config.py
# DEFAULT_LOG_LEVEL = logging.INFO


import sys
import logging
from servi.command import process_and_run_command_line
from servi.exceptions import ServiError, ForceError, MasterNotFound
from servi.config import DEFAULT_LOG_LEVEL as DEFAULT_LOG_LEVEL
        LT = 'LT'
        GTE = 'GTE'

        def __init__(self, level, comp):
            super().__init__()
            self.level = level
            self.comp = comp
            assert comp in [LevelFilter.LT, LevelFilter.GTE]

        def filter(self, record):
            if self.comp == LevelFilter.LT:
                return record.levelno < self.level
            else:
                return record.levelno >= self.level

    # Set a default logger
    fmt = MyFormatter()

    stdout_hdlr = logging.StreamHandler(sys.stdout)
    stdout_hdlr.setFormatter(fmt)
    lower_than_error = LevelFilter(logging.ERROR, LevelFilter.LT)
    stdout_hdlr.addFilter(lower_than_error)
    logging.root.addHandler(stdout_hdlr)

    stderr_hdlr = logging.StreamHandler(sys.stderr)
    stderr_hdlr.setFormatter(fmt)
    gte_than_error = LevelFilter(logging.ERROR, LevelFilter.GTE)
    stderr_hdlr.addFilter(gte_than_error)
    logging.root.addHandler(stderr_hdlr)


# Path: servi/command.py
# def process_and_run_command_line(command_line=None):
#         servi_parser, sub_parsers = setup_parsers()
# 
#         commands = load_plugins(sub_parsers)
# 
#         args, extra_args = parse_args(commands, servi_parser, command_line)
# 
#         log_level = arg_to_log_level(args.verbose)
#         retval = False
#         with use_log_level(log_level):
#             if args.template_dir:
#                 c.TMPL_DIR_SITE = args.template_dir
#                 warn('*** Just set TMPL_DIR_SITE to |{0}|'.format(
#                     c.TMPL_DIR_SITE))
# 
#             if not args.command:
#                 error('\n***** Error ******\nNo command on command line.\n')
#                 servi_parser.print_help()
#                 raise ServiError('No command line')
# 
#             if args.command not in commands:
#                 raise ServiError('Unknown command: {0}'.format(args.command))
# 
#             special = getattr(commands[args.command], "special", {})
# 
#             if not special.get("skip_init", False):
#                 master_dir = c.find_master_dir(os.getcwd())
#                 set_master_dir(master_dir)
#                 load_user_config()
# 
#             try:
#                 info('Servi - Running: {0}\n'.format(args.command))
#                 if c.MASTER_DIR:
#                     debug('Master Directory: {0}'
#                           .format(os.path.abspath(c.MASTER_DIR)))
#                 debug('Template Directory: {0}'
#                       .format(os.path.abspath(c.TMPL_DIR_SITE)))
# 
#                 retval = args.command_func(args, extra_args)
#             except (ForceError, ServiError):
#                 raise
# 
# 
#         return retval
# 
# Path: servi/exceptions.py
# class ServiError(Exception):
#     # Expected errrors. Handle gracefully (ie: no stack dump)
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             '{0}\n'
#             '\n**Servi Aborting**'.format(self.msg))
# 
# class ForceError(Exception):
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             '{0}\n'
#             'Use -f / --force to override.\n'
#             '\n**Servi Aborting**'.format(self.msg))
# 
# class MasterNotFound(Exception):
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             'Master directory not found at or above current directory.\n'
#             'Looking for: <master>/ServiFile.yml\n'
#             'Above cwd: {0}\n'
#             'Run "servi init <dirname>"\n'
#             '\n**Servi Aborting**'.format(os.getcwd()))
# 
# Path: servi/config.py
# DEFAULT_LOG_LEVEL = logging.INFO


# Path: main.py
import sys
import logging
from servi.command import process_and_run_command_line
from servi.exceptions import ServiError, ForceError, MasterNotFound
from servi.config import DEFAULT_LOG_LEVEL as DEFAULT_LOG_LEVEL

        LT = 'LT'
        GTE = 'GTE'

        def __init__(self, level, comp):
            super().__init__()
            self.level = level
            self.comp = comp
            assert comp in [LevelFilter.LT, LevelFilter.GTE]

        def filter(self, record):
            if self.comp == LevelFilter.LT:
                return record.levelno < self.level
            else:
                return record.levelno >= self.level

    # Set a default logger
    fmt = MyFormatter()

    stdout_hdlr = logging.StreamHandler(sys.stdout)
    stdout_hdlr.setFormatter(fmt)
    lower_than_error = LevelFilter(logging.ERROR, LevelFilter.LT)
    stdout_hdlr.addFilter(lower_than_error)
    logging.root.addHandler(stdout_hdlr)

    stderr_hdlr = logging.StreamHandler(sys.stderr)
    stderr_hdlr.setFormatter(fmt)
    gte_than_error = LevelFilter(logging.ERROR, LevelFilter.GTE)
    stderr_hdlr.addFilter(gte_than_error)
    logging.root.addHandler(stderr_hdlr)


    logging.root.setLevel(DEFAULT_LOG_LEVEL)