Compare commits

..

No commits in common. "8c896c9074f1a9b1f17f4ed56092d6d3fbd1c127" and "076f654a2dc66cfbc07853e40bb330a61ddc540f" have entirely different histories.

3 changed files with 9 additions and 21 deletions

View file

@ -1,35 +1,31 @@
"""Handle logging."""
import logging import logging
import sys import sys
def get_file_logger(name: str) -> logging.Logger: def get_file_logger(name: str) -> logging.Logger:
"""Return a file logger."""
# formatter
formatter = logging.Formatter( formatter = logging.Formatter(
"%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s", "%(name)s: %(asctime)s | %(levelname)s | %(filename)s:%(lineno)s | %(process)d >>> %(message)s",
) )
# handler #
out_handler = logging.StreamHandler(stream=sys.stdout) out_handler = logging.StreamHandler(stream=sys.stdout)
out_handler.setFormatter(formatter) out_handler.setFormatter(formatter)
out_handler.setLevel(logging.INFO) out_handler.setLevel(logging.INFO)
# logger #
logger = logging.getLogger(name) logger = logging.getLogger(name)
logger.addHandler(out_handler) logger.addHandler(out_handler)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
#
return logger return logger
def get_stream_logger(level: int) -> logging.Logger: def get_stream_logger(level: int) -> logging.Logger:
"""Return a stream logger."""
# handler
out_handler = logging.StreamHandler(stream=sys.stdout) out_handler = logging.StreamHandler(stream=sys.stdout)
out_handler.setLevel(level) out_handler.setLevel(level)
# logger #
logger = logging.getLogger() logger = logging.getLogger()
logger.addHandler(out_handler) logger.addHandler(out_handler)
logger.setLevel(level) logger.setLevel(level)
#
return logger return logger

View file

@ -1,12 +1,9 @@
"""Handle processes."""
import subprocess import subprocess
from rwx import txt from rwx import txt
def get_tuples_args(*tuples: tuple[str]) -> list[str]: def get_tuples_args(tuples) -> list[str]:
"""Turn arguments tuples into an arguments list."""
args: list[str] = [] args: list[str] = []
for item in tuples: for item in tuples:
if type(item) is tuple: if type(item) is tuple:
@ -16,21 +13,18 @@ def get_tuples_args(*tuples: tuple[str]) -> list[str]:
return args return args
def run(*tuples: tuple[str]) -> subprocess.CompletedProcess: def run(*tuples) -> subprocess.CompletedProcess:
"""Run from a list of arguments tuples."""
return subprocess.run( return subprocess.run(
get_tuples_args(tuples), capture_output=False, check=True get_tuples_args(tuples), capture_output=False, check=True
) )
def run_line(*tuples: tuple[str], charset: str = txt.CHARSET) -> str: def run_line(*tuples, charset: str = txt.CHARSET) -> str:
"""Run and return output line."""
lines = run_lines(*get_tuples_args(tuples), charset=charset) lines = run_lines(*get_tuples_args(tuples), charset=charset)
return lines[0] return lines[0]
def run_lines(*tuples: tuple[str], charset: str = txt.CHARSET) -> list[str]: def run_lines(*tuples, charset: str = txt.CHARSET) -> list[str]:
"""Run and return output lines."""
process = subprocess.run( process = subprocess.run(
get_tuples_args(tuples), capture_output=True, check=True get_tuples_args(tuples), capture_output=True, check=True
) )

View file

@ -1,3 +1 @@
"""Handle text."""
CHARSET = "UTF-8" CHARSET = "UTF-8"