Exemple #1
0
def mongodb(context: click.core.Context):
    """Commands to operate on the mongodb database"""
    if context.invoked_subcommand is None:
        click.echo(mongodb.get_help(context))
        if isinstance(context.obj, Project):
            from derex.runner.mongodb import list_databases

            click.echo()
            project = context.obj
            for db in list_databases():
                if db["name"] == project.mongodb_db_name:
                    click.echo(
                        f'Current MongoDB databases for project "{project.name}"'
                    )
                    console = get_rich_console()
                    table = get_rich_table("Database",
                                           "Tables",
                                           "Django users",
                                           show_lines=True)
                    table.add_row(
                        db["name"],
                        str(db["sizeOnDisk"]),
                        str(db["empty"]),
                    )
                    console.print(table)
                    break
            else:
                click.echo(
                    f'No MongoDB database "{project.mongodb_db_name}" found for project "{project.name}"'
                )
Exemple #2
0
def show_users_cmd():
    """List all MySQL users"""
    from derex.runner.mysql import list_users

    console = get_rich_console()
    table = get_rich_table("User", "Host", "Password", show_lines=True)
    for user in list_users():
        table.add_row(user[0], user[1], user[2])
    console.print(table)
    return 0
Exemple #3
0
def show_databases_cmd():
    """List all MySQL databases"""
    from derex.runner.mysql import show_databases

    console = get_rich_console()
    table = get_rich_table("Database", "Tables", "Django users", show_lines=True)
    for database in show_databases():
        table.add_row(database[0], str(database[1]), str(database[2]))
    console.print(table)
    return 0
Exemple #4
0
def list_users():
    """List all MongoDB users"""
    from derex.runner.mongodb import list_users

    console = get_rich_console()
    table = get_rich_table("User", "Db", "Roles", show_lines=True)
    for user in list_users():
        roles = []
        for role in user["roles"]:
            roles.append(f"\"{role['role']}\" on database \"{role['db']}\"")
        table.add_row(user["user"], user["db"], "\n".join(roles))
    console.print(table)
    return 0
Exemple #5
0
def list_databases_cmd(project: Optional[Project], db_name: str):
    """List all MongoDB databases"""
    from derex.runner.mongodb import list_databases

    console = get_rich_console()
    table = get_rich_table("Database",
                           "Size (bytes)",
                           "Empty",
                           show_lines=True)
    for database in list_databases():
        table.add_row(database["name"], str(database["sizeOnDisk"]),
                      str(database["empty"]))
    console.print(table)
    return 0
Exemple #6
0
def derex(ctx):
    """Derex directs edX: commands to manage an Open edX installation
    """
    # Optimize --help and bash completion by importing
    from derex.runner.project import Project

    try:
        ctx.obj = Project()
    except ProjectNotFound:
        pass
    except Exception as ex:
        logger.error("\n".join(map(str, ex.args)))
        sys.exit(1)

    if ctx.invoked_subcommand:
        return

    click.echo(derex.get_help(ctx) + "\n")

    from derex.runner.docker_utils import get_exposed_container_names

    container_names = get_exposed_container_names()
    if not container_names:
        return

    console = get_rich_console()
    table = get_rich_table(
        "Name",
        title=
        "[bold green]These containers are running and exposing an HTTP server on port 80",
        box=rich.box.SIMPLE,
    )
    for container in container_names:
        container = (f"[bold]{container[0]}", ) + container[1:]
        table.add_row(*container)
    console.print(table)
Exemple #7
0
def mysql(context: click.core.Context):
    """Commands to operate on the mysql database"""
    if context.invoked_subcommand is None:
        from derex.runner.mysql import show_databases

        click.echo(mysql.get_help(context))
        if isinstance(context.obj, Project):
            click.echo()
            project = context.obj
            for db in show_databases():
                if db[0] == project.mysql_db_name:
                    click.echo(f'Current MySQL databases for project "{project.name}"')
                    console = get_rich_console()
                    table = get_rich_table(
                        "Database", "Tables", "Django users", show_lines=True
                    )
                    table.add_row(db[0], str(db[1]), str(db[2]))
                    console.print(table)
                    break
            else:
                click.echo(
                    f'No MySQL database "{project.mysql_db_name}" found for project "{project.name}"'
                )
                click.echo('You can prime it with "derex mysql reset"')