Beispiel #1
0
def main(args=None):
    """Main programme.

    Called when `diceware` script is called.

    `args` is a list of command line arguments to process. If no such
    args are given, we use `sys.argv`.
    """
    if args is None:
        args = sys.argv[1:]
    options = handle_options(args)
    configure(options.verbose)
    if options.version:
        print_version()
        raise SystemExit(0)
    print(get_passphrase(options))
Beispiel #2
0
def test_configure():
    # we can configure the logger.
    my_logger = logging.getLogger("ulif.diceware")
    configure(None)
    assert my_logger.level == logging.NOTSET
    configure(0)
    assert my_logger.level == logging.CRITICAL
    configure(1)
    assert my_logger.level == logging.INFO
    configure(2)
    assert my_logger.level == logging.DEBUG
Beispiel #3
0
def test_configure():
    # we can configure the logger.
    logger.setLevel(23)
    my_logger = logging.getLogger("ulif.diceware")
    configure(None)
    assert my_logger.level == 23
    configure(0)
    assert my_logger.level == logging.ERROR
    configure(1)
    assert my_logger.level == logging.INFO
    configure(2)
    assert my_logger.level == logging.DEBUG
Beispiel #4
0
def main(args=None):
    """Main programme.

    Called when `diceware` script is called.

    `args` is a list of command line arguments to process. If no such
    args are given, we use `sys.argv`.
    """
    if args is None:
        args = sys.argv[1:]
    options = handle_options(args)
    configure(options.verbose)
    if options.version:
        print_version()
        raise SystemExit(0)
    try:
        print(get_passphrase(options))
    except (OSError, IOError) as infile_error:
        if getattr(infile_error, 'errno', 0) == ENOENT:
            logging.getLogger('ulif.diceware').error(
                "The file '%s' does not exist." % infile_error.filename)
            raise SystemExit(1)
        else:
            raise
Beispiel #5
0
def main(args=None):
    """Main programme.

    Called when `diceware` script is called.

    `args` is a list of command line arguments to process. If no such
    args are given, we use `sys.argv`.
    """
    if args is None:
        args = sys.argv[1:]
    options = handle_options(args)
    configure(options.verbose)
    if options.version:
        print_version()
        raise SystemExit(0)
    try:
        print(get_passphrase(options))
    except (OSError, IOError) as infile_error:
        if getattr(infile_error, 'errno', 0) == ENOENT:
            logging.getLogger('ulif.diceware').error(
                "The file '%s' does not exist." % infile_error.filename)
            raise SystemExit(1)
        else:
            raise
Beispiel #6
0
def test_get_logger_by_name():
    # we can get a logger directly from std lib
    my_logger = logging.getLogger("ulif.diceware")
    configure(0)
    assert len(my_logger.handlers) > 0
Beispiel #7
0
def test_logger_has_handler():
    # the logger has at least one handler
    configure(0)
    assert len(logger.handlers) > 0