# Path: canaryd/exceptions.py
# class CanarydError(ClickException):
#     '''
#     Generic canaryd exception.
#     '''
# 
#     def __init__(self, message='exiting!', *args, **kwargs):
#         return super(CanarydError, self).__init__(message, *args, **kwargs)
# 
# class UserCancelError(CanarydError):
#     '''
#     Triggered when a user cancels an action.
#     '''
# 
#     def __init__(self):
#         return super(UserCancelError, self).__init__('User cancelled')


from os import geteuid
from canaryd_packages import click
from canaryd.exceptions import CanarydError, UserCancelError




def check_root(message, exit=False):
    # If we're root, we're all good!
    if geteuid() <= 0:
        return

    message = click.style(message, 'yellow')

    # If exit, just fail
    if exit:
        raise CanarydError(message)

    # Warn the user about the implications of running as non-root
    click.echo(message)

    # Confirm this is OK!
    if not click.confirm('Do you wish to continue?'):

# Path: canaryd/exceptions.py
# class CanarydError(ClickException):
#     '''
#     Generic canaryd exception.
#     '''
# 
#     def __init__(self, message='exiting!', *args, **kwargs):
#         return super(CanarydError, self).__init__(message, *args, **kwargs)
# 
# class UserCancelError(CanarydError):
#     '''
#     Triggered when a user cancels an action.
#     '''
# 
#     def __init__(self):
#         return super(UserCancelError, self).__init__('User cancelled')


# Path: canaryd/ctl/check_root.py
from os import geteuid
from canaryd_packages import click
from canaryd.exceptions import CanarydError, UserCancelError





def check_root(message, exit=False):
    # If we're root, we're all good!
    if geteuid() <= 0:
        return

    message = click.style(message, 'yellow')

    # If exit, just fail
    if exit:
        raise CanarydError(message)

    # Warn the user about the implications of running as non-root
    click.echo(message)

    # Confirm this is OK!
    if not click.confirm('Do you wish to continue?'):

        raise UserCancelError()