# Path: termicoder/utils/exceptions.py
# def handle_exceptions(*exceptions):
#     """
#     Used as a decorator.
#     Takes exceptions and a function,
#     returns function warpped with try except and debug functionality
#     """
#     # TODO correct the line number
#     def wrapper(function):
#         def customized_function(*args, **kwargs):
#             logger.debug(
#                 "calling function %s" % sys.modules[function.__module__])
#             try:
#                 function(*args, **kwargs)
#             except (exceptions) as e:
#                 if(logger.level == 10 or isinstance(e, click.Abort)):
#                     raise
#                 else:
#                     logger.error("in module %s:function %s:line %s" % (
#                         sys.modules[function.__module__].__file__,
#                         function.__name__, e.__traceback__.tb_lineno))
#                     logger.error("%s %s" % (e.__class__.__name__, e))
#                     raise click.Abort
#         customized_function.__wrapped__ = True
#         customized_function.__doc__ = function.__doc__
#         return customized_function
#     return wrapper
# 
# Path: termicoder/utils/view.py
# def folder(directory, browser_local):
# 
# Path: termicoder/utils/config.py
# def get_config_path(ensure_exists=False):
# def check_config_path():
# def read(rel_path, key=None, safe=False):
# def write(rel_path, key, value):


import click
from ...utils.exceptions import handle_exceptions
from ...utils import view
from ...utils import config


@click.command(short_help="View contents of folder.")
@click.argument("dir_name", type=click.Path(
                    exists=True, file_okay=False, dir_okay=True), default='.')
@click.option("--browser", help='Browser to launch',
              default=config.read('settings.yml', 'browser_local'))
@handle_exceptions(BaseException)
def main(dir_name, browser):
    '''
    display the termicoder contents in current/passed folder

    \b
    if it is a contest folder it displays the list of problems.
    if its a problem folder, displays the problem in a browser.
    '''

# Path: termicoder/utils/exceptions.py
# def handle_exceptions(*exceptions):
#     """
#     Used as a decorator.
#     Takes exceptions and a function,
#     returns function warpped with try except and debug functionality
#     """
#     # TODO correct the line number
#     def wrapper(function):
#         def customized_function(*args, **kwargs):
#             logger.debug(
#                 "calling function %s" % sys.modules[function.__module__])
#             try:
#                 function(*args, **kwargs)
#             except (exceptions) as e:
#                 if(logger.level == 10 or isinstance(e, click.Abort)):
#                     raise
#                 else:
#                     logger.error("in module %s:function %s:line %s" % (
#                         sys.modules[function.__module__].__file__,
#                         function.__name__, e.__traceback__.tb_lineno))
#                     logger.error("%s %s" % (e.__class__.__name__, e))
#                     raise click.Abort
#         customized_function.__wrapped__ = True
#         customized_function.__doc__ = function.__doc__
#         return customized_function
#     return wrapper
# 
# Path: termicoder/utils/view.py
# def folder(directory, browser_local):
# 
# Path: termicoder/utils/config.py
# def get_config_path(ensure_exists=False):
# def check_config_path():
# def read(rel_path, key=None, safe=False):
# def write(rel_path, key, value):


# Path: termicoder/cli/view/folder.py
import click
from ...utils.exceptions import handle_exceptions
from ...utils import view
from ...utils import config



@click.command(short_help="View contents of folder.")
@click.argument("dir_name", type=click.Path(
                    exists=True, file_okay=False, dir_okay=True), default='.')
@click.option("--browser", help='Browser to launch',
              default=config.read('settings.yml', 'browser_local'))
@handle_exceptions(BaseException)
def main(dir_name, browser):
    '''
    display the termicoder contents in current/passed folder

    \b
    if it is a contest folder it displays the list of problems.
    if its a problem folder, displays the problem in a browser.
    '''

    view.folder(dir_name, browser)