def script():
    """
    Execute the program as a script.

    Set up logging, invoke main() using the user-provided arguments and handle
    any exception raised.
    """
    # Setup logging
    import logging
    logging.basicConfig(
        format="%(levelname)s: %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
        stream=sys.stdout)
    logger = logging.getLogger()

    # Dispatch to the command according to the script name
    script = sys.argv[0]
    args = sys.argv[1:]
    if os.path.basename(script).startswith('pgxn-'):
        args.insert(0, os.path.basename(script)[5:])
        # for help print
        sys.argv[0] = os.path.join(os.path.dirname(script), 'pgxn')

    # Execute the script
    try:
        main(args)

    # Different ways to fail
    except UserAbort, e:
        # The user replied "no" to some question
        logger.info("%s", e)
        sys.exit(1)

    except PgxnException, e:
        # An regular error from the program
        logger.error("%s", e)
        sys.exit(1)

    except __HOLE__, e:
        # Usually the arg parser bailing out.
        pass

    except Exception, e:
        logger.error(_("unexpected error: %s - %s"),
            e.__class__.__name__, e, exc_info=True)
        sys.exit(1)

    except BaseException, e:
        # ctrl-c
        sys.exit(1)
dataset/ETHPy150Open dvarrazzo/pgxnclient/pgxnclient/cli.py/script