Skip to content

Commit

Permalink
Merge pull request #34 from jefflester/minitrino
Browse files Browse the repository at this point in the history
Minitrino Refactor and Additions
  • Loading branch information
jefflester authored May 17, 2021
2 parents a1874df + 0ed06ab commit a71ce5a
Show file tree
Hide file tree
Showing 125 changed files with 1,988 additions and 1,273 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ before_install:
script:
- |
pip3 install --editable ./cli/ &&
minipresto --help || exit 1 && echo -e '\n' &&
minitrino --help || exit 1 && echo -e '\n' &&
source ~/virtualenv/python3.8/bin/activate &&
python ./cli/minipresto/test/runner.py
python ./cli/minitrino/test/runner.py
after_failure:
- "Tests failed."
Expand Down
19 changes: 0 additions & 19 deletions cli/minipresto/cmd/cmd_version.py

This file was deleted.

30 changes: 0 additions & 30 deletions cli/minipresto/test/runner.py

This file was deleted.

File renamed without changes.
18 changes: 9 additions & 9 deletions cli/minipresto/cli.py → cli/minitrino/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import os
import click

from minipresto import settings
from minipresto import components
from minitrino import settings
from minitrino import components

from pathlib import Path

CONTEXT_SETTINGS = {"auto_envvar_prefix": "MINIPRESTO"}
CONTEXT_SETTINGS = {"auto_envvar_prefix": "MINITRINO"}

pass_environment = click.make_pass_decorator(components.Environment, ensure=True)

Expand All @@ -26,7 +26,7 @@ def list_commands(self, ctx):

def get_command(self, ctx, name):
try:
mod = __import__(f"minipresto.cmd.cmd_{name}", None, None, ["cli"])
mod = __import__(f"minitrino.cmd.cmd_{name}", None, None, ["cli"])
except ImportError:
return
return mod.cli
Expand All @@ -49,21 +49,21 @@ def get_command(self, ctx, name):
help=(
"""Add or override environment variables.
Environment variables are sourced from the Minipresto library's root
'minipresto.env' file as well as the user config file in
'~/.minipresto/minipresto.cfg'. Variables supplied by this option will
Environment variables are sourced from the Minitrino library's root
'minitrino.env' file as well as the user config file in
'~/.minitrino/minitrino.cfg'. Variables supplied by this option will
override values from either of those sources. The variables will also be
passed to the environment of the shell executing commands during the
'provision' command."""
),
)
@pass_environment
def cli(ctx, verbose, env):
"""Welcome to the Minipresto command line interface.
"""Welcome to the Minitrino command line interface.
To report issues and ask questions, please file a GitHub issue and apply a
descriptive label at the GitHub repository:
https://github.com/jefflester/minipresto
https://github.com/jefflester/minitrino
"""

ctx._user_init(verbose, env)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import os
import click

from minipresto.cli import pass_environment
from minipresto import utils
from minipresto.settings import CONFIG_TEMPLATE
from minitrino.cli import pass_environment
from minitrino import utils
from minitrino.settings import CONFIG_TEMPLATE

from shutil import rmtree


@click.command(
"config",
help=("""Edit the Minipresto user configuration file."""),
help=("""Edit the Minitrino user configuration file."""),
)
@click.option(
"-r",
"--reset",
is_flag=True,
default=False,
help=(
"""Reset the Minipresto user configuration file and create a new config
"""Reset the Minitrino user configuration file and create a new config
file from a template.
WARNING: This will remove your configuration file (if it exists) and
Expand All @@ -31,11 +31,11 @@
@utils.exception_handler
@pass_environment
def cli(ctx, reset):
"""Config command for Minipresto."""
"""Config command for Minitrino."""

if not os.path.isdir(ctx.minipresto_user_dir):
ctx.logger.log(f"No {ctx.minipresto_user_dir} directory found. Creating...")
os.mkdir(ctx.minipresto_user_dir)
if not os.path.isdir(ctx.minitrino_user_dir):
ctx.logger.log(f"No {ctx.minitrino_user_dir} directory found. Creating...")
os.mkdir(ctx.minitrino_user_dir)

if os.path.isfile(ctx.config_file) and not reset:
ctx.logger.log(
Expand All @@ -49,7 +49,7 @@ def cli(ctx, reset):
write_template()
edit_file()
else:
ctx.logger.log(f"Opted out of recreating {ctx.minipresto_user_dir} file.")
ctx.logger.log(f"Opted out of recreating {ctx.minitrino_user_dir} file.")
else:
ctx.logger.log(
f"No config file found at path: {ctx.config_file}. "
Expand Down
20 changes: 10 additions & 10 deletions cli/minipresto/cmd/cmd_down.py → cli/minitrino/cmd/cmd_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import sys
import click

from minipresto.cli import pass_environment
from minipresto import utils
from minipresto import errors as err
from minipresto.settings import RESOURCE_LABEL
from minitrino.cli import pass_environment
from minitrino import utils
from minitrino import errors as err
from minitrino.settings import RESOURCE_LABEL


@click.command(
"down",
help=(
"""Bring down running Minipresto containers. This command follows the
"""Bring down running Minitrino containers. This command follows the
behavior of `docker-compose down` where containers are both stopped and
removed."""
),
Expand All @@ -32,13 +32,13 @@
"--sig-kill",
is_flag=True,
default=False,
help=("""Stop Minipresto containers without a grace period."""),
help=("""Stop Minitrino containers without a grace period."""),
)
@utils.exception_handler
@pass_environment
def cli(ctx, sig_kill, keep):
"""Down command for Minipresto. Exits with a 0 status code if there are no
running minipresto containers."""
"""Down command for Minitrino. Exits with a 0 status code if there are no
running minitrino containers."""

utils.check_daemon(ctx.docker_client)
utils.check_lib(ctx)
Expand All @@ -54,7 +54,7 @@ def cli(ctx, sig_kill, keep):
if sig_kill:
stop_timeout = 1
ctx.logger.log(
"Stopping Minipresto containers with sig-kill...",
"Stopping Minitrino containers with sig-kill...",
level=ctx.logger.verbose,
)
else:
Expand All @@ -78,4 +78,4 @@ def cli(ctx, sig_kill, keep):
container.remove()
ctx.logger.log(f"Removed container: {identifier}", level=ctx.logger.verbose)

ctx.logger.log("Brought down all Minipresto containers.")
ctx.logger.log("Brought down all Minitrino containers.")
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import click
import shutil

from minipresto.cli import pass_environment
from minipresto import errors as err
from minipresto import utils
from minitrino.cli import pass_environment
from minitrino import errors as err
from minitrino import utils


@click.command(
"lib_install",
help=("""Install the Minipresto library."""),
help=("""Install the Minitrino library."""),
)
@click.option(
"-v",
Expand All @@ -25,15 +25,15 @@
@utils.exception_handler
@pass_environment
def cli(ctx, version):
"""Library installation command for Minipresto."""
"""Library installation command for Minitrino."""

if not version:
version = utils.get_cli_ver()

lib_dir = os.path.join(ctx.minipresto_user_dir, "lib")
lib_dir = os.path.join(ctx.minitrino_user_dir, "lib")
if os.path.isdir(lib_dir):
response = ctx.logger.prompt_msg(
f"The Minipresto library at {lib_dir} will be overwritten. "
f"The Minitrino library at {lib_dir} will be overwritten. "
f"Continue? [Y/N]"
)
if utils.validate_yes(response):
Expand All @@ -52,18 +52,18 @@ def cli(ctx, version):
@pass_environment
def download_and_extract(ctx, version=""):

github_uri = f"https://github.com/jefflester/minipresto/archive/{version}.tar.gz"
tarball = os.path.join(ctx.minipresto_user_dir, f"{version}.tar.gz")
github_uri = f"https://github.com/jefflester/minitrino/archive/{version}.tar.gz"
tarball = os.path.join(ctx.minitrino_user_dir, f"{version}.tar.gz")
file_basename = f"minitrino-{version}" # filename after unpacking
lib_dir = os.path.join(ctx.minipresto_user_dir, file_basename, "lib")
lib_dir = os.path.join(ctx.minitrino_user_dir, file_basename, "lib")

try:
# Download the release tarball
cmd = f"curl -fsSL {github_uri} > {tarball}"
ctx.cmd_executor.execute_commands(cmd)
if not os.path.isfile(tarball):
raise err.MiniprestoError(
f"Failed to download Minipresto library ({tarball} not found)."
raise err.MinitrinoError(
f"Failed to download Minitrino library ({tarball} not found)."
)

# Unpack tarball and copy lib
Expand All @@ -72,14 +72,14 @@ def download_and_extract(ctx, version=""):
level=ctx.logger.verbose,
)
ctx.cmd_executor.execute_commands(
f"tar -xzvf {tarball} -C {ctx.minipresto_user_dir}",
f"mv {lib_dir} {ctx.minipresto_user_dir}",
f"tar -xzvf {tarball} -C {ctx.minitrino_user_dir}",
f"mv {lib_dir} {ctx.minitrino_user_dir}",
)

# Check that the library is present
lib_dir = os.path.join(ctx.minipresto_user_dir, "lib")
lib_dir = os.path.join(ctx.minitrino_user_dir, "lib")
if not os.path.isdir(lib_dir):
raise err.MiniprestoError(
raise err.MinitrinoError(
f"Library failed to install (not found at {lib_dir})"
)

Expand All @@ -88,13 +88,13 @@ def download_and_extract(ctx, version=""):

except Exception as e:
cleanup(tarball, file_basename, False)
raise err.MiniprestoError(str(e))
raise err.MinitrinoError(str(e))


@pass_environment
def cleanup(ctx, tarball="", file_basename="", trigger_error=True):

ctx.cmd_executor.execute_commands(
f"rm -rf {tarball} {os.path.join(ctx.minipresto_user_dir, file_basename)}",
f"rm -rf {tarball} {os.path.join(ctx.minitrino_user_dir, file_basename)}",
trigger_error=trigger_error,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import click
import json

from minipresto.cli import pass_environment
from minipresto import errors as err
from minipresto import utils
from minitrino.cli import pass_environment
from minitrino import errors as err
from minitrino import utils


@click.command(
Expand Down Expand Up @@ -43,7 +43,7 @@
@utils.exception_handler
@pass_environment
def cli(ctx, modules, json_format, running):
"""Version command for Minipresto."""
"""Version command for Minitrino."""

utils.check_lib(ctx)

Expand All @@ -55,7 +55,7 @@ def cli(ctx, modules, json_format, running):
if not module_dict:
raise err.UserError(
f"Invalid module: {module}",
"Ensure the module you're referencing is in the Minipresto library.",
"Ensure the module you're referencing is in the Minitrino library.",
)
log_info(module, module_dict, json_format)
else:
Expand All @@ -81,10 +81,10 @@ def log_info(ctx, module_name="", module_dict={}, json_format=False):
module_dict = {module_name: module_dict}
ctx.logger.log(json.dumps(module_dict, indent=2))
else:
description = module_dict.get("description", "")
incompatible_modules = module_dict.get("incompatible_modules", [])
ctx.logger.log(
f"Module: {module_name}\n"
f"Description: {description}\n"
f"Incompatible Modules: {incompatible_modules}",
)
log_msg = [f"Module: {module_name}\n"]
keys = ["description", "incompatibleModules", "enterprise"]
for k, v in module_dict.items():
if k in keys:
log_msg.extend(f"{k.title()}: {v}\n")

ctx.logger.log("".join(log_msg))
Loading

0 comments on commit a71ce5a

Please sign in to comment.