From 678d9e0e4d792256e53b505706620eda76c7dba0 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 13 Jul 2024 01:46:18 +0200 Subject: [PATCH] util --- spcd/__init__.py | 43 ++----------------------------------------- spcd/cmd.py | 2 +- spcd/util.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 spcd/util.py diff --git a/spcd/__init__.py b/spcd/__init__.py index 51f53b2..0549dc0 100644 --- a/spcd/__init__.py +++ b/spcd/__init__.py @@ -1,40 +1,20 @@ -"""Python Integration, Delivery & Deployment.""" +"""Shell to Python Continuous Deployment.""" __version__ = "0.0.1" -import os import sys from pathlib import Path -import env from rwx import fs from rwx.log import stream as log import spcd from spcd import cmd +from spcd.util import browse, cat, step COMMANDS_PREFIX = "spcd-" -def browse(root: str) -> None: - paths = [] - for directory, _, files in os.walk(root): - for file in files: - absolute_path = Path(directory) / file - relative_path = os.path.relpath(absolute_path, start=root) - paths.append(relative_path) - frame(root) - for path in sorted(paths): - log.info(path) - shut(root) - - -def cat(file: str) -> None: - frame(file) - log.info(fs.read_file_text(file).rstrip()) - shut(file) - - def install_commands(path: str) -> None: step("Install commands") user = Path("/usr/local/bin") @@ -85,22 +65,3 @@ def set_ssh(*arguments: list[str]) -> None: # display browse(ssh) cat(known) - - -def frame(text: str) -> None: - log.info(f"{env.SPCD_OPEN}{text}") - - -def shut(text: str) -> None: - log.info(f"{env.SPCD_SHUT}{text}") - - -def split() -> None: - log.info(env.SPCD_SPLT) - - -def step(text: str) -> None: - env.SPCD_STEP += 1 - log.info(env.SPCD_DOWN) - log.info(f"{env.SPCD_VERT} {env.SPCD_STEP} {text}") - log.info(env.SPCD___UP) diff --git a/spcd/cmd.py b/spcd/cmd.py index 644f703..be9ba26 100644 --- a/spcd/cmd.py +++ b/spcd/cmd.py @@ -4,8 +4,8 @@ from pathlib import Path from rwx import ps from rwx.log import stream as log -from spcd import browse, split from spcd.ci import project, projects +from spcd.util import browse, split def spcd_browse_workspace() -> None: diff --git a/spcd/util.py b/spcd/util.py new file mode 100644 index 0000000..161cc37 --- /dev/null +++ b/spcd/util.py @@ -0,0 +1,44 @@ +import os +from pathlib import Path + +import env +from rwx import fs +from rwx.log import stream as log + + +def browse(root: str) -> None: + paths = [] + for directory, _, files in os.walk(root): + for file in files: + absolute_path = Path(directory) / file + relative_path = os.path.relpath(absolute_path, start=root) + paths.append(relative_path) + frame(root) + for path in sorted(paths): + log.info(path) + shut(root) + + +def cat(file: str) -> None: + frame(file) + log.info(fs.read_file_text(file).rstrip()) + shut(file) + + +def frame(text: str) -> None: + log.info(f"{env.SPCD_OPEN}{text}") + + +def shut(text: str) -> None: + log.info(f"{env.SPCD_SHUT}{text}") + + +def split() -> None: + log.info(env.SPCD_SPLT) + + +def step(text: str) -> None: + env.SPCD_STEP += 1 + log.info(env.SPCD_DOWN) + log.info(f"{env.SPCD_VERT} {env.SPCD_STEP} {text}") + log.info(env.SPCD___UP)