Commit 26d19a9d authored by Grant, Josh's avatar Grant, Josh
Browse files

Merge branch 'feature/cli' into 'develop'

Feature/cli

See merge request !43
parents 61f1f1d1 66e83768
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
common-package = {editable = true, path = "./src", extras = ["dev", "minio"]}
common-package = {editable = true, path = "./src", extras = ["dev", "minio", "cli"]}
twine = "*"

[dev-packages]
+740 −663

File changed.

Preview size limit exceeded, changes collapsed.

+33 −0
Original line number Diff line number Diff line
"""Initialize the CLI module."""
import os
import subprocess

try:
    import click
except ImportError:
    import sys

    from common.logz import create_logger

    logger = create_logger()
    logger.warn("the [cli] extra must be installed. ")
    sys.exit(1)


@click.group()
def of_cli():
    """Common/OnlyFeatures CLI."""
    pass


# noqa: PEP402
from common.cli.docker_cli import docker
from common.cli.python_cli import python_cli
from common.cli.gen_cli import gen_cli

of_cli.add_command(docker)
of_cli.add_command(python_cli)
of_cli.add_command(gen_cli)

if __name__ == "__main__":
    of_cli()
+36 −0
Original line number Diff line number Diff line
"""Command line arguments for helping with docker."""
import os
import subprocess

import click


@click.group()
def docker():
    """Docker related commands."""
    pass


@docker.command(name='remove-volumes',
                help='Remove all docker volumes with a specific prefix.')
@click.argument('prefix', required=False)
def remove_volumes(prefix):
    """Remove all docker volumes with a specific prefix."""
    if not prefix:
        prefix = os.path.basename(os.getcwd())
    command = f"docker volume ls -q --filter name={prefix} | xargs -r docker volume rm"
    subprocess.run(command, shell=True)


@docker.command(name='docker-execute-and-mount',
                help='Execute a command in a docker container with a /tmp as the pwd.')
@click.option('--image', '-i', default='python:3.11-latest', help='Docker image to use.')
@click.option('--volume-target', '-t', default=None, help='Target directory to mount.')
@click.option('--volume-mount', '-m', default='/tmp', help='Mount directory inside the container.')
@click.option('--exec', '-e', 'exec_cmd', default='bash', help='Command to execute.')
def docker_execute_and_mount(image, volume_target, volume_mount, exec_cmd):
    """Execute a command in a docker container with a /tmp as the pwd."""
    if not volume_target:
        volume_target = os.getcwd()
    command = f"docker run -it -v {volume_target}:{volume_mount} -w {volume_mount} {image} {exec_cmd}"
    subprocess.run(command, shell=True)
+38 −0
Original line number Diff line number Diff line
"""Command line arguments for helping generate file sizes."""

import click

from common.gen import generate_csv, convert_size_to_bytes


@click.group()
def gen_cli():
    """A CLI to generate large CSV files with random data."""
    pass


@gen_cli.command()
@click.option('--col', '-c', type=int, required=True, help="Number of columns in the CSV.")
@click.option('--row', '-r', type=int, help="Number of rows in the CSV.")
@click.option('--size', '-s', type=str, help="Target file size (e.g., 512MB or 1GB).")
def generate(col, row, size):
    """Generate a CSV file with the specified number of columns and rows or file size."""
    target_file_size = None
    if size:
        try:
            target_file_size = convert_size_to_bytes(size)
        except ValueError as e:
            click.echo(f"Error: {e}")
            return

    generate_csv(
        file_path='output.csv',
        n_columns=col,
        target_row_count=row,
        target_file_size=target_file_size,
        column_types={}  # You can define the column types here if needed
    )


if __name__ == '__main__':
    gen_cli()
Loading