Skip to content

Commit

Permalink
Merge pull request #96 from saritasa-nest/adjust-usage-of-cmd-commands
Browse files Browse the repository at this point in the history
Replace usage of cmd commands with python
  • Loading branch information
TheSuperiorStanislav authored Aug 13, 2024
2 parents 4124224 + 04d4d14 commit 9d3240b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ We follow [Semantic Versions](https://semver.org/).

## unreleased

- Replace usage of cmd commands with python

## 1.1.1

- Make default for `default_entry` for `K8SDefaultSettings` use absolute path
Expand Down
5 changes: 3 additions & 2 deletions saritasa_invocations/cruft.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pathlib
import shutil

import invoke

Expand Down Expand Up @@ -53,8 +54,8 @@ def create_project(
config = _config.Config.from_context(context)
tmp_folder = config.cruft.project_tmp_folder
printing.print_success(f"Recreating tmp ({tmp_folder}) folder")
context.run(f"rm -rf {tmp_folder}")
context.run(f"mkdir -p {tmp_folder}")
shutil.rmtree(tmp_folder, ignore_errors=True)
pathlib.Path(tmp_folder).mkdir(parents=True, exist_ok=True)
with context.cd(tmp_folder):
context.run(
"cruft create ../. --no-input --overwrite-if-exists "
Expand Down
3 changes: 2 additions & 1 deletion saritasa_invocations/django.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections.abc
import os
import pathlib

import invoke

Expand Down Expand Up @@ -338,7 +339,7 @@ def load_django_remote_env_db_settings(
import decouple

env_config = decouple.Config(decouple.RepositoryEnv(env_path))
context.run(f"rm {env_path}")
pathlib.Path(env_path).unlink()
return {
arg: str(env_config(env_var))
for arg, env_var in config.django.remote_db_config_mapping.items()
Expand Down
7 changes: 4 additions & 3 deletions saritasa_invocations/docker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections.abc
import pathlib
import shutil

import invoke

Expand All @@ -26,16 +27,16 @@ def buildpack(
config = _config.Config.from_context(context)
# Builder needs requirements.txt
if pathlib.Path(config.docker.buildpack_requirements_path).exists():
context.run(
f"cp {config.docker.buildpack_requirements_path}/{env}.txt "
shutil.copy(
f"{config.docker.buildpack_requirements_path}/{env}.txt",
"requirements.txt",
)
builder = builder or config.docker.buildpack_builder
runner = runner or config.docker.buildpack_runner
tag = tag or config.docker.build_image_tag
context.run(f"pack build --builder={builder} --run-image={runner} {tag}")
if pathlib.Path(config.docker.buildpack_requirements_path).exists():
context.run("rm requirements.txt")
pathlib.Path("requirements.txt").unlink()


def docker_compose_run(
Expand Down
3 changes: 2 additions & 1 deletion saritasa_invocations/k8s.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import collections.abc
import contextlib
import pathlib
import typing

import invoke
Expand Down Expand Up @@ -259,7 +260,7 @@ def download_file_and_remove_afterwards(
printing.print_success(
f"Deleting file({path_to_where_save_file}) after use",
)
context.run(f"rm {path_to_where_save_file}")
pathlib.Path(path_to_where_save_file).unlink()


@contextlib.contextmanager
Expand Down
5 changes: 3 additions & 2 deletions saritasa_invocations/system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pathlib
import shutil

import invoke

Expand Down Expand Up @@ -57,7 +58,7 @@ def _rewrite_file(
) -> None:
"""Copy file to destination."""
if force_update or not pathlib.Path(to_path).is_file():
context.run(f"cp {from_path} {to_path}")
shutil.copy(from_path, to_path)


@invoke.task
Expand All @@ -74,4 +75,4 @@ def chown(context: invoke.Context) -> None:
@invoke.task
def create_tmp_folder(context: invoke.Context) -> None:
"""Create folder for temporary files."""
context.run("mkdir -p .tmp")
pathlib.Path(".tmp").mkdir(parents=True, exist_ok=True)

0 comments on commit 9d3240b

Please sign in to comment.