From 8ce3a93675559f8b2e6a195a6f7b029df83b3962 Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:38:17 +0530 Subject: [PATCH] Add app data folder creation system --- .gitignore | 2 ++ app/main.py | 2 ++ app/utils/autodirectory.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 app/utils/autodirectory.py diff --git a/.gitignore b/.gitignore index e69de29..60876d4 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,2 @@ +utils/__pycache__ +corelibs/__pycache__ diff --git a/app/main.py b/app/main.py index e6c671b..8d15363 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 = "0.0.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)