Beispiel #1
0
def main():
    """
    Starts the execution of without
    injecting variables into the global namespace. Ensures that
    logging is setup and that sudo access is available and in-use.

    Arguments: N/A
    Returns: 1 for success, 0 for failure
    """
    
    # Do this first so people can see the help message...
    args = opts.parse(load_previous_settings())

    # Configure logging levels
    log_level = logging.INFO
    if args['verbose'] or args['dryrun']:
        log_level = logging.DEBUG
    logging.setupLogging(log_level)

    LOG.debug("Log level is: %s" % (logging.getLevelName(log_level)))

    def clean_exc(exc):
        msg = str(exc).strip()
        if msg.endswith(".") or msg.endswith("!"):
            return msg
        else:
            return msg + "."

    def traceback_fn():
        traceback = None
        if log_level < logging.INFO:
            # See: http://docs.python.org/library/traceback.html
            # When its not none u get more detailed info about the exception
            traceback = sys.exc_traceback
        tb.print_exception(sys.exc_type, sys.exc_value,
                traceback, file=sys.stdout)

    try:
        # Drop to usermode
        sh.user_mode(quiet=False)
    except excp.AnvilException as e:
        print(clean_exc(e))
        print("This program should be running via %s, is it not?" % (colorizer.quote('sudo', quote_color='red')))
        return 1

    try:
        run(args)
        utils.goodbye(True)
        return 0
    except excp.OptionException as e:
        print(clean_exc(e))
        print("Perhaps you should try %s" % (colorizer.quote('--help', quote_color='red')))
        return 1
    except Exception:
        utils.goodbye(False)
        traceback_fn()
        return 1
Beispiel #2
0
def main():
    """
    Starts the execution of without
    injecting variables into the global namespace. Ensures that
    logging is setup and that sudo access is available and in-use.

    Arguments: N/A
    Returns: 1 for success, 0 for failure
    """

    # Do this first so people can see the help message...
    args = opts.parse(load_previous_settings())

    # Configure logging levels
    log_level = logging.INFO
    if args['verbose'] or args['dryrun']:
        log_level = logging.DEBUG
    logging.setupLogging(log_level)

    LOG.debug("Log level is: %s" % (logging.getLevelName(log_level)))

    def clean_exc(exc):
        msg = str(exc).strip()
        if msg.endswith(".") or msg.endswith("!"):
            return msg
        else:
            return msg + "."

    def traceback_fn():
        traceback = None
        if log_level < logging.INFO:
            # See: http://docs.python.org/library/traceback.html
            # When its not none u get more detailed info about the exception
            traceback = sys.exc_traceback
        tb.print_exception(sys.exc_type,
                           sys.exc_value,
                           traceback,
                           file=sys.stdout)

    try:
        # Drop to usermode
        sh.user_mode(quiet=False)
    except excp.AnvilException as e:
        print(clean_exc(e))
        print("This program should be running via %s, is it not?" %
              (colorizer.quote('sudo', quote_color='red')))
        return 1

    try:
        run(args)
        utils.goodbye(True)
        return 0
    except excp.OptionException as e:
        print(clean_exc(e))
        print("Perhaps you should try %s" %
              (colorizer.quote('--help', quote_color='red')))
        return 1
    except Exception:
        utils.goodbye(False)
        traceback_fn()
        return 1
Beispiel #3
0
def ensure_perms():
    # Ensure we are running as root to start...
    if not sh.got_root():
        raise excp.PermException("Root access required")
    # Drop to usermode (which also ensures we can do this...)
    sh.user_mode(quiet=False)
def ensure_perms():
    # Ensure we are running as root to start...
    if not sh.got_root():
        raise excp.PermException("Root access required")
    # Drop to usermode (which also ensures we can do this...)
    sh.user_mode(quiet=False)