Exemple #1
0
def main():
    # Set to ERROR so we can see errors during plugin loading.
    logging.basicConfig(loglevel=logging.ERROR)

    # Lazy-load configuration
    config = confit.LazyConfig('spreads', __name__)
    config.read()
    setup_plugin_config(config)

    parser = setup_parser(config)
    args = parser.parse_args()
    # Set configuration from parsed arguments
    set_config_from_args(config, args)

    loglevel = config['loglevel'].as_choice({
        'none':     logging.NOTSET,
        'info':     logging.INFO,
        'debug':    logging.DEBUG,
        'warning':  logging.WARNING,
        'error':    logging.ERROR,
        'critical': logging.CRITICAL,
    })

    # Set up logger
    logger = logging.getLogger()
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)
    handler = ColourStreamHandler()
    handler.setLevel(loglevel)
    handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(handler)
    logger.setLevel(logging.INFO)

    args.subcommand(config)
Exemple #2
0
def main():
    # Set to ERROR so we can see errors during plugin loading.
    logging.basicConfig(loglevel=logging.ERROR)

    config = Configuration()

    parser = setup_parser(config)
    args = parser.parse_args()
    # Set configuration from parsed arguments
    config.set_from_args(args)

    loglevel = config['core']['loglevel'].as_choice({
        'none':
        logging.NOTSET,
        'info':
        logging.INFO,
        'debug':
        logging.DEBUG,
        'warning':
        logging.WARNING,
        'error':
        logging.ERROR,
        'critical':
        logging.CRITICAL,
    })

    # Set up logger
    logger = logging.getLogger()
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)
    stdout_handler = ColourStreamHandler()
    stdout_handler.setLevel(
        logging.DEBUG if config['core']['verbose'].get() else logging.WARNING)
    stdout_handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(stdout_handler)
    logger.addHandler(EventHandler())
    if 'logfile' in config.keys():
        logfile = Path(config['core']['logfile'].as_filename())
        if not logfile.parent.exists():
            logfile.parent.mkdir()
        file_handler = logging.handlers.RotatingFileHandler(
            filename=unicode(logfile), maxBytes=512 * 1024, backupCount=1)
        file_handler.setFormatter(
            logging.Formatter(
                "%(asctime)s %(message)s [%(name)s] [%(levelname)s]"))
        file_handler.setLevel(loglevel)
        logger.addHandler(file_handler)

    logger.setLevel(logging.DEBUG)

    args.subcommand(config)
Exemple #3
0
def main():
    # Set to ERROR so we can see errors during plugin loading.
    logging.basicConfig(loglevel=logging.ERROR)

    # Lazy-load configuration
    config = confit.LazyConfig('spreads', __name__)
    # Load default plugin configuration
    plugin.set_default_config(config)
    # Load user configuration
    config.read()

    parser = setup_parser(config)
    args = parser.parse_args()
    # Set configuration from parsed arguments
    set_config_from_args(config, args)

    loglevel = config['loglevel'].as_choice({
        'none':     logging.NOTSET,
        'info':     logging.INFO,
        'debug':    logging.DEBUG,
        'warning':  logging.WARNING,
        'error':    logging.ERROR,
        'critical': logging.CRITICAL,
    })

    # Set up logger
    logger = logging.getLogger()
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)
    stdout_handler = ColourStreamHandler()
    stdout_handler.setLevel(logging.DEBUG if config['verbose'].get()
                            else logging.WARNING)
    stdout_handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(stdout_handler)
    logger.addHandler(EventHandler())
    if 'logfile' in config.keys():
        logfile = Path(os.path.expanduser(config['logfile'].get()))
        if not logfile.parent.exists():
            logfile.parent.mkdir()
        file_handler = logging.handlers.RotatingFileHandler(
            filename=unicode(logfile), maxBytes=512*1024, backupCount=1)
        file_handler.setFormatter(logging.Formatter(
            "%(asctime)s %(message)s [%(name)s] [%(levelname)s]"))
        file_handler.setLevel(loglevel)
        logger.addHandler(file_handler)

    logger.setLevel(logging.DEBUG)

    args.subcommand(config)
Exemple #4
0
def main():
    # Initialize color support
    colorama.init()
    # Set to ERROR so we can see errors during plugin loading.
    logging.basicConfig(loglevel=logging.ERROR)
    config.read()
    cfg_path = os.path.join(config.config_dir(), confit.CONFIG_FILENAME)
    if not os.path.exists(cfg_path):
        config.dump(filename=cfg_path)

    parser = setup_parser()
    args = parser.parse_args()
    config.set_args(args)

    loglevel = config['loglevel'].as_choice({
        'none': logging.NOTSET,
        'info': logging.INFO,
        'debug': logging.DEBUG,
        'warning': logging.WARNING,
        'error': logging.ERROR,
        'critical': logging.CRITICAL,
    })
    if args.verbose:
        loglevel = logging.DEBUG

    # Set up logger
    logger = logging.getLogger()
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)
    handler = ColourStreamHandler()
    handler.setLevel(loglevel)
    handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(handler)
    logger.setLevel(loglevel)

    args.func(args)

    # Deinitialize color support
    colorama.deinit()
Exemple #5
0
def main():
    # Initialize color support
    colorama.init()
    # Set to ERROR so we can see errors during plugin loading.
    logging.basicConfig(loglevel=logging.ERROR)
    config.read()
    cfg_path = os.path.join(config.config_dir(), confit.CONFIG_FILENAME)
    if not os.path.exists(cfg_path):
        config.dump(filename=cfg_path)

    parser = setup_parser()
    args = parser.parse_args()
    config.set_args(args)

    loglevel = config['loglevel'].as_choice({
        'none':     logging.NOTSET,
        'info':     logging.INFO,
        'debug':    logging.DEBUG,
        'warning':  logging.WARNING,
        'error':    logging.ERROR,
        'critical': logging.CRITICAL,
    })
    if args.verbose:
        loglevel = logging.DEBUG

    # Set up logger
    logger = logging.getLogger()
    if logger.handlers:
        for handler in logger.handlers:
            logger.removeHandler(handler)
    handler = ColourStreamHandler()
    handler.setLevel(loglevel)
    handler.setFormatter(logging.Formatter("%(name)s: %(message)s"))
    logger.addHandler(handler)
    logger.setLevel(loglevel)

    args.func(args)

    # Deinitialize color support
    colorama.deinit()