summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-26 21:52:03 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-26 21:52:03 +0800
commitc68e0c629b9d763c4714029544d0a686006ba439 (patch)
treedad265ff2de8a15cd0b9d8d9c0cf32f79940c153
parent3efd9fe282ae3311b49a0028da0ebd8bf99633f8 (diff)
added rpath & runutil functions
-rwxr-xr-xstdlib.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/stdlib.py b/stdlib.py
index 6e22999..3059fce 100755
--- a/stdlib.py
+++ b/stdlib.py
@@ -226,6 +226,23 @@ def bgexec(func, arg=False, stop=False):
else:
t = Thread(target=func).start()
+# to give a absolutly perfect path to the location of a file or self(directory)
+def rpath(file: str=None) -> str:
+ from os import path
+ if file:
+ if path.islink(file):
+ from os import readlink
+ file = readlink(file)
+ return f'{path.dirname(path.abspath(__file__))}/{file}'
+ else:
+ return path.dirname(path.abspath(__file__))
+
+# run another python file(utils)
+def runutil(file: str, *arg) -> any:
+ from sys import executable
+ from os import execv
+ execv(executable, ['python3', f'{rpath()}/{file}'] + list(arg))
+
# TODO: fix this "TypeError: Please input @sig as a int(signal number, like 15) or str(signal name, like SIGTERM", tried signal.SIGINT, or str(signal name, like SIGTERM)
# catch & handle signals
def sigcatch(sig, error=None, sysexit=False, handler=None):