예제 #1
0
def main() -> None:
    parser = argparse.ArgumentParser(
        description=
        "A utility for working with databases created with this codebase.")
    parser.add_argument(
        "operation",
        help=
        "Operation to perform, options include 'create', 'generate', 'upgrade', 'change-password', 'add-admin' and 'remove-admin'.",
        type=str,
    )
    parser.add_argument(
        "-u",
        "--username",
        help="Username of user to add/remove admin rights for.",
        type=str,
    )
    parser.add_argument(
        "-m",
        "--message",
        help="Message to use for auto-generated migration scripts.",
        type=str,
    )
    parser.add_argument(
        "-e",
        "--allow-empty",
        help=
        "Allow empty migration script to be generated. Useful for data-only migrations.",
        action='store_true',
    )
    parser.add_argument("-c",
                        "--config",
                        help="Core configuration. Defaults to server.yaml",
                        type=str,
                        default="server.yaml")
    args = parser.parse_args()

    config = yaml.safe_load(open(args.config))
    config['database']['engine'] = Data.create_engine(config)
    try:
        if args.operation == "create":
            create(config)
        elif args.operation == "generate":
            generate(config, args.message, args.allow_empty)
        elif args.operation == "upgrade":
            upgrade(config)
        elif args.operation == "add-admin":
            add_admin(config, args.username)
        elif args.operation == "remove-admin":
            remove_admin(config, args.username)
        elif args.operation == 'change-password':
            change_password(config, args.username)
        else:
            raise Exception(f"Unknown operation '{args.operation}'")
    except DBCreateException as e:
        print(str(e))
        sys.exit(1)
예제 #2
0
        factory.run_scheduled_work(data, config)  # type: ignore

    # Now, warm the caches for the frontend
    for cache in enabled_caches:
        cache.preload(data, config)  # type: ignore

    # Now, possibly delete old log entries
    keep_duration = config.get('event_log_duration', 0)
    if keep_duration > 0:
        # Calculate timestamp of events we should delete
        oldest_event = Time.now() - keep_duration
        data.local.network.delete_events(oldest_event)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description="A scheduler for work that needs to be done periodically.")
    parser.add_argument("-c",
                        "--config",
                        help="Core configuration. Defaults to server.yaml",
                        type=str,
                        default="server.yaml")
    args = parser.parse_args()

    # Set up global configuration
    config = yaml.safe_load(open(args.config))  # type: ignore
    config['database']['engine'] = Data.create_engine(config)

    # Run out of band work
    run_scheduled_work(config)
예제 #3
0
def load_config(filename: str) -> None:
    global config

    config.update(yaml.safe_load(open(filename)))  # type: ignore
    config['database']['engine'] = Data.create_engine(config)
    app.secret_key = config['secret_key']
예제 #4
0
def load_config(filename: str) -> None:
    global config

    config.update(yaml.safe_load(open(filename)))
    config['database']['engine'] = Data.create_engine(config)