2025-09-26 20:28:47 +02:00
|
|
|
import tempfile
|
2025-09-27 13:08:30 +02:00
|
|
|
import argparse
|
2025-09-26 20:28:47 +02:00
|
|
|
|
2025-09-27 17:31:58 +02:00
|
|
|
from modules.tempbox_functions import execute_as_subprocess
|
|
|
|
|
from modules.tempbox_logger import logger
|
2025-09-26 20:28:47 +02:00
|
|
|
|
2025-09-27 17:31:58 +02:00
|
|
|
tempbox_version = "Tempbox Beta b0.2.1"
|
2025-09-27 13:08:30 +02:00
|
|
|
# Argument parsing
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2025-09-27 19:05:44 +02:00
|
|
|
prog="tempbox",
|
2025-09-27 13:08:30 +02:00
|
|
|
description="This program accepts an\
|
|
|
|
|
command whicht it executes in an temporary directory in /temp.",
|
|
|
|
|
# epilog="helloooooooo",
|
|
|
|
|
)
|
2025-09-26 20:28:47 +02:00
|
|
|
|
2025-09-27 13:08:30 +02:00
|
|
|
parser.add_argument(
|
|
|
|
|
"-v",
|
|
|
|
|
"--verbose",
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="Activates or deactivates verbose output. (default=%(default)s)",
|
|
|
|
|
)
|
2025-09-26 20:28:47 +02:00
|
|
|
|
2025-09-27 13:08:30 +02:00
|
|
|
parser.add_argument(
|
|
|
|
|
"-c",
|
|
|
|
|
"--command",
|
|
|
|
|
help="Takes the string right after the flag to execute it.",
|
|
|
|
|
)
|
2025-09-26 20:28:47 +02:00
|
|
|
|
2025-09-27 15:29:34 +02:00
|
|
|
parser.add_argument("-V", "--version", action="version", version=tempbox_version)
|
|
|
|
|
|
2025-09-27 13:08:30 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
if args.command is not None:
|
|
|
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
2025-09-27 17:31:58 +02:00
|
|
|
logger.debug(f"'{temp_dir}' was created")
|
2025-09-27 13:08:30 +02:00
|
|
|
if args.command is not None:
|
|
|
|
|
execute_as_subprocess(
|
|
|
|
|
args.command,
|
|
|
|
|
base_path=temp_dir,
|
|
|
|
|
verbosity=args.verbose,
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
parser.print_help()
|
2025-09-27 17:31:58 +02:00
|
|
|
logger.info("Printed Version")
|
2025-09-27 13:08:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Creates a temporary directory and executes the command in it.
|