add rad_development_python, remove common functions

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
2024-08-04 10:40:00 -04:00
parent 257e30abcb
commit bdc15b2c41
10 changed files with 22 additions and 57 deletions

View File

@ -1,39 +1 @@
#!/usr/bin/env python3
"""common."""
import logging
import sys
from subprocess import PIPE, Popen
def configure_logger(level: str = "INFO") -> None:
"""Configure the logger.
Args:
level (str, optional): The logging level. Defaults to "INFO".
"""
logging.basicConfig(
level=level,
datefmt="%Y-%m-%dT%H:%M:%S%z",
format="%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s",
handlers=[logging.StreamHandler(sys.stdout)],
)
def bash_wrapper(command: str, path: str = ".") -> tuple[str, str, int]:
"""Execute a bash command and capture the output.
Args:
command (str): The bash command to be executed.
path (str): The current working directory, '.' by default
Returns:
Tuple[str, int]: A tuple containing the output of the command (stdout) as a string,
the error output (stderr) as a string (optional), and the return code as an integer.
"""
# This is a acceptable risk
process = Popen(command.split(), stdout=PIPE, stderr=PIPE, cwd=path) # noqa: S603
output, error = process.communicate()
return output.decode(), error.decode(), process.returncode

View File

@ -2,7 +2,7 @@
import logging
from typing import Optional
from flupdt.common import bash_wrapper
from rad_development_python import bash_wrapper
import re
drv_re = re.compile(r".*(/nix/store/.*\.drv).*")

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import json
from flupdt.common import bash_wrapper
from rad_development_python import bash_wrapper
import shutil
import logging
import re

View File

@ -3,7 +3,6 @@
from flupdt.flake_show import get_derivations
from flupdt.cli import parse_inputs
from flupdt.flake_eval import evaluate_output
from flupdt.common import configure_logger
import logging
import rad_development_python as rd