made some minor adjustments
This commit is contained in:
@@ -29,12 +29,15 @@ def execute_as_subprocess(command, base_path, verbosity=False):
|
|||||||
"""executes the string given with the '-c, --command' flag."""
|
"""executes the string given with the '-c, --command' flag."""
|
||||||
|
|
||||||
logger.debug("Entered execute_as_subprocess()")
|
logger.debug("Entered execute_as_subprocess()")
|
||||||
logger.debug(f"Path:\t{base_path}\nCommand:\t{command}")
|
logger.debug(f"Path:\t{base_path}\nCommand:\t\t\t{command}")
|
||||||
|
|
||||||
|
# Decicion if the terminal output is verbose or not
|
||||||
if verbosity:
|
if verbosity:
|
||||||
|
# Verbose output
|
||||||
logger.info("Running subprocess with terminal output.")
|
logger.info("Running subprocess with terminal output.")
|
||||||
subprocess.run(command, cwd=base_path, shell=True)
|
subprocess.run(command, cwd=base_path, shell=True)
|
||||||
else:
|
else:
|
||||||
|
# Suppressed output
|
||||||
logger.info("Running with suppressed stdout and stderr")
|
logger.info("Running with suppressed stdout and stderr")
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
command,
|
command,
|
||||||
@@ -43,5 +46,4 @@ def execute_as_subprocess(command, base_path, verbosity=False):
|
|||||||
stdout=subprocess.DEVNULL,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug("Exited execute_as_subprocess()")
|
logger.debug("Exited execute_as_subprocess()")
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ logging.basicConfig(
|
|||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.debug(f"Log path:\t{log_dir}")
|
# logger.debug(f"Log path:\t{log_dir}")
|
||||||
logger.debug(f"Log file:\t{log_file}")
|
# logger.debug(f"Log file:\t{log_file}")
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ from modules.tempbox_functions import execute_as_subprocess
|
|||||||
from modules.tempbox_logger import logger
|
from modules.tempbox_logger import logger
|
||||||
|
|
||||||
tempbox_version = "Tempbox Beta b0.2.1"
|
tempbox_version = "Tempbox Beta b0.2.1"
|
||||||
|
|
||||||
# Argument parsing
|
# Argument parsing
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="tempbox",
|
prog="tempbox",
|
||||||
description="This program accepts an\
|
description="This program accepts an\
|
||||||
command whicht it executes in an temporary directory in /temp.",
|
command whicht it executes in an temporary directory in /temp.",
|
||||||
# epilog="helloooooooo",
|
epilog=tempbox_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -19,20 +20,19 @@ parser.add_argument(
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Activates or deactivates verbose output. (default=%(default)s)",
|
help="Activates or deactivates verbose output. (default=%(default)s)",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
"--command",
|
"--command",
|
||||||
help="Takes the string right after the flag to execute it.",
|
help="Takes the string right after the flag to execute it.",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument("-V", "--version", action="version", version=tempbox_version)
|
parser.add_argument("-V", "--version", action="version", version=tempbox_version)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
# Begin of script logic
|
||||||
if args.command is not None:
|
if args.command is not None:
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
logger.debug(f"'{temp_dir}' was created")
|
logger.info(f"'{temp_dir}' was created")
|
||||||
if args.command is not None:
|
if args.command is not None:
|
||||||
execute_as_subprocess(
|
execute_as_subprocess(
|
||||||
args.command,
|
args.command,
|
||||||
@@ -41,7 +41,4 @@ if args.command is not None:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
logger.info("Printed Version")
|
logger.debug("Printed Version")
|
||||||
|
|
||||||
|
|
||||||
# Creates a temporary directory and executes the command in it.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user