Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Fix so that deployment is logged to file
Browse files Browse the repository at this point in the history
  • Loading branch information
Måns Magnusson committed Oct 7, 2020
1 parent f0d562b commit b89cd92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
27 changes: 26 additions & 1 deletion shipping/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

import click

from shipping.configs.base_config import AppConfig
from shipping.commands import Process
from shipping.configs.base_config import AppConfig, HostConfig
from shipping.deploy.conda import deploy_conda
from shipping.environment import get_python_path
from shipping.log import get_log_line, log_deploy
from shipping.package import fetch_package_version

LOG = logging.getLogger(__name__)

Expand All @@ -17,7 +21,10 @@ def deploy_cmd(context):
LOG.info("Running shipping deploy")

app_config: AppConfig = context.obj["app_config"]
host_config: HostConfig = context.obj["host_config"]
env_name: str = context.obj["env_name"]
python_process: Process = Process(str(get_python_path(env_name)))
current_version: str = fetch_package_version(python_process, app_config.tool)

LOG.info(
"%s wants to deploy %s on host %s in environment %s",
Expand All @@ -31,3 +38,21 @@ def deploy_cmd(context):
raise click.Abort

LOG.info("Tool was successfully deployed")

updated_version: str = fetch_package_version(python_process, app_config.tool)
log_line = get_log_line(
time_zone=host_config.tz_object,
user=context.obj["current_user"],
tool=app_config.tool,
current_version=current_version,
updated_version=updated_version,
)

log_path = host_config.log_path
if not log_path:
click.echo(log_line)
return

if not log_path.exists():
log_path.touch()
log_deploy(log_line=log_line, log_file=log_path)
7 changes: 7 additions & 0 deletions shipping/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Code for logging information"""

from datetime import datetime, tzinfo
from pathlib import Path

from shipping import __version__

Expand Down Expand Up @@ -29,3 +30,9 @@ def get_log_line(
__version__,
]
return "\t".join(log_data)


def log_deploy(log_line: str, log_file: Path) -> None:
"""Log information about deployment to file"""
with open(log_file, "a") as file_object:
file_object.write(log_line + "\n")

0 comments on commit b89cd92

Please sign in to comment.