added logging
This commit is contained in:
47
tempbox/src/modules/tempbox_functions.py
Normal file
47
tempbox/src/modules/tempbox_functions.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from .tempbox_logger import logger
|
||||
|
||||
|
||||
def create_folders(number_folders, base_path, verbosity=False):
|
||||
"""creates an amount of folders and returning its path"""
|
||||
|
||||
if verbosity:
|
||||
while number_folders > 0:
|
||||
number_folders = number_folders - 1
|
||||
|
||||
folder_name = f"folder_{number_folders}"
|
||||
full_path = os.path.join(base_path, folder_name)
|
||||
|
||||
os.mkdir(full_path)
|
||||
print(f"'{full_path}' was created")
|
||||
else:
|
||||
while number_folders > 0:
|
||||
number_folders = number_folders - 1
|
||||
|
||||
folder_name = f"folder_{number_folders}"
|
||||
full_path = os.path.join(base_path, folder_name)
|
||||
os.mkdir(full_path)
|
||||
|
||||
|
||||
def execute_as_subprocess(command, base_path, verbosity=False):
|
||||
"""executes the string given with the '-c, --command' flag."""
|
||||
|
||||
logger.debug("Entered execute_as_subprocess()")
|
||||
logger.debug(f"Path:\t{base_path}\nCommand:\t{command}")
|
||||
|
||||
if verbosity:
|
||||
logger.info("Running subprocess with terminal output.")
|
||||
subprocess.run(command, cwd=base_path, shell=True)
|
||||
else:
|
||||
logger.info("Running with suppressed stdout and stderr")
|
||||
subprocess.run(
|
||||
command,
|
||||
cwd=base_path,
|
||||
shell=True,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
|
||||
logger.debug("Exited execute_as_subprocess()")
|
||||
17
tempbox/src/modules/tempbox_logger.py
Normal file
17
tempbox/src/modules/tempbox_logger.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
log_dir = Path.home() / ".local" / "share" / "tempbox"
|
||||
log_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
log_file = log_dir / "tempbox.log"
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||
filename=log_file,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.debug(f"Log path:\t{log_dir}")
|
||||
logger.debug(f"Log file:\t{log_file}")
|
||||
Reference in New Issue
Block a user