added logging
This commit is contained in:
47
tempbox/src/tempbox.py
Normal file
47
tempbox/src/tempbox.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import tempfile
|
||||
import argparse
|
||||
|
||||
from modules.tempbox_functions import execute_as_subprocess
|
||||
from modules.tempbox_logger import logger
|
||||
|
||||
tempbox_version = "Tempbox Beta b0.2.1"
|
||||
# Argument parsing
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="Tempbox",
|
||||
description="This program accepts an\
|
||||
command whicht it executes in an temporary directory in /temp.",
|
||||
# epilog="helloooooooo",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
help="Activates or deactivates verbose output. (default=%(default)s)",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-c",
|
||||
"--command",
|
||||
help="Takes the string right after the flag to execute it.",
|
||||
)
|
||||
|
||||
parser.add_argument("-V", "--version", action="version", version=tempbox_version)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command is not None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
logger.debug(f"'{temp_dir}' was created")
|
||||
if args.command is not None:
|
||||
execute_as_subprocess(
|
||||
args.command,
|
||||
base_path=temp_dir,
|
||||
verbosity=args.verbose,
|
||||
)
|
||||
else:
|
||||
parser.print_help()
|
||||
logger.info("Printed Version")
|
||||
|
||||
|
||||
# Creates a temporary directory and executes the command in it.
|
||||
Reference in New Issue
Block a user