Пример #1
0
def test_get_config_path(sys):
    samples = {
        '--conf=test.ini': 'test.ini',
        "--conf='test.ini'": 'test.ini',
        '--conf="test.ini"': 'test.ini',
        '--conf test.ini': 'test.ini',
        '--conf /path/to/file-test.ini': '/path/to/file-test.ini',
        '--conf=/path/to/file-test.ini': '/path/to/file-test.ini',
        "--conf='/path/to/file-test.ini'": '/path/to/file-test.ini',
        '--conf="/path/to/file-test.ini"': '/path/to/file-test.ini',
        '--conf c:\path\\to\mis leading': 'c:\path\\to\mis',
    }
    for (value, expected) in samples.items():
        sys.argv = ['cmd', '-t', '--flag', '--var="te st"', value, '--var2=3']
        result = mod.get_config_path()
        assert result == expected
Пример #2
0
def shutdown(*args, **kwargs):
    """ Cleanly shut down the server """
    logging.info('Librarian is going down.')
    # run shutdown hooks
    app.events.publish(hooks.SHUTDOWN, app)
    # stop all servers
    servers.stop_all(5)
    logging.info('Clean shutdown completed')
    print('Bye! Have a nice day! Those books are due Tuesday, by the way!')


def main(config_path):
    app.config = ConfDict.from_file(config_path, catchall=True, autojson=True)
    app.version = version.get_version(__version__, app.config)
    hooks.register_hooks(app)
    # register command line arg handlers
    parser = argparse.ArgumentParser()
    app.events.publish(hooks.COMMANDS, parser, app)
    # parse command line args
    app.args = parser.parse_args(sys.argv[1:])
    commands.select_command(app)
    # begin app-start sequence
    prestart()
    return start()


if __name__ == '__main__':
    config_path = commands.get_config_path() or app.CONFPATH
    sys.exit(main(config_path))