From f4fc770797826aa6f5c9123f28b310d8a62fe0d7 Mon Sep 17 00:00:00 2001 From: dh00601 <dh00601@surrey.ac.uk> Date: Sat, 25 Sep 2021 13:10:31 +0100 Subject: [PATCH] added change to tmp dir function to always include the username --- binarycpython/utils/functions.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index f16992d31..3f6022af9 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -18,6 +18,7 @@ import sys import subprocess import time import types +import psutil from io import StringIO from typing import Union, Any @@ -505,6 +506,9 @@ def remove_file(file: str, verbosity: int = 0) -> None: ) +def get_username(): + return psutil.Process().username() + def temp_dir(*args: str) -> str: """ Function to create directory within the TMP directory of the file system @@ -519,7 +523,8 @@ def temp_dir(*args: str) -> str: """ tmp_dir = tempfile.gettempdir() - path = os.path.join(tmp_dir, "binary_c_python") + username = get_username() + path = os.path.join(tmp_dir, "binary_c_python-{}".format(username)) # loop over the other paths if there are any: if args: @@ -531,7 +536,6 @@ def temp_dir(*args: str) -> str: return path - def create_hdf5(data_dir: str, name: str) -> None: """ Function to create an hdf5 file from the contents of a directory: -- GitLab