# Path: servi/exceptions.py
# 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 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))
# 
# Path: servi/config.py
# def set_master_dir(set_dir_to):
#     """
#     sets c.MASTER_DIR
#         by finding the first ancestor(default)
#         to set_dir_to (if supplied - only for servi init)
#     """
#     global MASTER_DIR
# 
#     MASTER_DIR = set_dir_to
#     # TODO - remove this function
# 
# def load_user_config():
#     """
#     Reads and processes Servifile.yml, adding all variables to this modules
#     globals()
# 
#     For Servifile_Globals, Servifile:
#         Step 1: Render the file as a Jinja2 template
#                     (with custom function: lookup('env', envvar) )
#         Step 2: Load as a yaml doc
#         Step 3: Add to this module's globals()
# 
#     Note - Servifile.yml can essentially update or override Servifile_globals
#       but it CAN NOT delete a key from Servifile_globals
#       ie: combined >= servifile_globals
# 
#     """
# 
#     # Global config
#     global_config = {}
#     if not os.path.exists(SERVIFILE_GLOBAL_FULL):
#         warn('No global servifile found in {0}'.format(SERVIFILE_GLOBAL_FULL))
#     else:
#         with open(SERVIFILE_GLOBAL_FULL) as f:
#             servi_raw = f.read()
#             global_config = process_config(servi_raw)
# 
#     if MASTER_DIR:
#         user_config = getconfig(
#             SERVIFILE, TEMPLATE, MASTER, TMPL_DIR_SITE, MASTER_DIR)
#     else:
#         warn('Getting config but MASTER_DIR is empty.')
#         user_config = {}
# 
#     combined_config = deep_update(global_config, user_config)
#     for k, v in combined_config.items():
#         globals()[k] = v
# 
#     return global_config, user_config, combined_config


from glob import glob
from importlib import import_module
from logging import debug, info, warning as warn, error
from contextlib import contextmanager
from servi.exceptions import ForceError, ServiError
from servi.config import set_master_dir, load_user_config
import argparse
import io
import os
import logging
import servi.config as c
    import servi.commands  # required for import_module()



class Command(object):
    def __init__(self):
        self.special = {
            "skip_init": False,
            "parse_known_args": False
        }

    def register_command_line(self, sub_parser):
        pass

    def run(self, args, extra_args):
        pass


def find_plugins():
    plugins = []
    for f in glob(os.path.dirname(__file__) + '/commands/*.py'):

# Path: servi/exceptions.py
# 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 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))
# 
# Path: servi/config.py
# def set_master_dir(set_dir_to):
#     """
#     sets c.MASTER_DIR
#         by finding the first ancestor(default)
#         to set_dir_to (if supplied - only for servi init)
#     """
#     global MASTER_DIR
# 
#     MASTER_DIR = set_dir_to
#     # TODO - remove this function
# 
# def load_user_config():
#     """
#     Reads and processes Servifile.yml, adding all variables to this modules
#     globals()
# 
#     For Servifile_Globals, Servifile:
#         Step 1: Render the file as a Jinja2 template
#                     (with custom function: lookup('env', envvar) )
#         Step 2: Load as a yaml doc
#         Step 3: Add to this module's globals()
# 
#     Note - Servifile.yml can essentially update or override Servifile_globals
#       but it CAN NOT delete a key from Servifile_globals
#       ie: combined >= servifile_globals
# 
#     """
# 
#     # Global config
#     global_config = {}
#     if not os.path.exists(SERVIFILE_GLOBAL_FULL):
#         warn('No global servifile found in {0}'.format(SERVIFILE_GLOBAL_FULL))
#     else:
#         with open(SERVIFILE_GLOBAL_FULL) as f:
#             servi_raw = f.read()
#             global_config = process_config(servi_raw)
# 
#     if MASTER_DIR:
#         user_config = getconfig(
#             SERVIFILE, TEMPLATE, MASTER, TMPL_DIR_SITE, MASTER_DIR)
#     else:
#         warn('Getting config but MASTER_DIR is empty.')
#         user_config = {}
# 
#     combined_config = deep_update(global_config, user_config)
#     for k, v in combined_config.items():
#         globals()[k] = v
# 
#     return global_config, user_config, combined_config


# Path: servi/command.py
from glob import glob
from importlib import import_module
from logging import debug, info, warning as warn, error
from contextlib import contextmanager
from servi.exceptions import ForceError, ServiError
from servi.config import set_master_dir, load_user_config
import argparse
import io
import os
import logging
import servi.config as c
    import servi.commands  # required for import_module()




class Command(object):
    def __init__(self):
        self.special = {
            "skip_init": False,
            "parse_known_args": False
        }

    def register_command_line(self, sub_parser):
        pass

    def run(self, args, extra_args):
        pass


def find_plugins():
    plugins = []
    for f in glob(os.path.dirname(__file__) + '/commands/*.py'):

        if os.path.isfile(f) and not os.path.basename(f).startswith('_'):