diff --git a/.gitignore b/.gitignore index 872339c..7bb7d67 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -app/__pycache__ \ No newline at end of file +app/__pycache__ diff --git a/app/main.py b/app/main.py index 614612d..dd3beb4 100644 --- a/app/main.py +++ b/app/main.py @@ -5,6 +5,7 @@ import os.path import pwd import corelibs.colors +from utils.autodirectory import make_directory # Config version = "2022.927.1" @@ -30,6 +31,7 @@ def start(): print(f"PyTerm - Beta Release [no version] {color.yellow}(Unstable){color.end}") else: print(f"PyTerm - Beta Release v{version} {color.yellow}(Unstable){color.end}") print(f"Running as PID: {pid}") + make_directory(user) def listen_for_command(errorcode): diff --git a/app/utils/autodirectory.py b/app/utils/autodirectory.py new file mode 100644 index 0000000..35d9057 --- /dev/null +++ b/app/utils/autodirectory.py @@ -0,0 +1,28 @@ +### NKA Development Organization 2022. For enquiries, contact + +# Imports +import os +import os.path +import pwd + + +# Config +user = pwd.getpwuid(os.getuid())[0] + + +# Functions +def make_directory(username: str): + """Makes app path in user's home directory if there is no app path. If there is, this is automatically skipped.""" + default_path = f"/home/{username}" + if not os.path.isdir(f"{default_path}/pyterm"): + os.mkdir(f"{default_path}/pyterm") # Making main directory + open(f"{default_path}/pyterm/pytermrc", "x") + os.mkdir(f"{default_path}/pyterm/history") + open(f"{default_path}/pyterm/history/username_hist.txt", "x") + os.mkdir(f"{default_path}/pyterm/logs") + open(f"{default_path}/pyterm/logs/{username}_info.log", "x") + open(f"{default_path}/pyterm/logs/{username}_error.log", "x") + + +# Initialization +# make_directory(user)