-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabsolutePath.py
More file actions
27 lines (23 loc) · 926 Bytes
/
absolutePath.py
File metadata and controls
27 lines (23 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from sys import argv, executable
from os import path
from pathlib import Path
def get_base_path():
"""Get the base path, handling both normal Python and Nuitka onefile mode."""
if hasattr(argv, 'frozen') or getattr(argv, 'frozen', False):
# Nuitka onefile mode
return Path(argv[0]).parent
return Path(__file__).parent
def loadFile(file_name: str) -> str:
return path.join(path.dirname(__file__), file_name)
def loadRealFile(file_name: str, level_down: bool = False) -> str:
base_path = Path(argv[0]).parent if argv[0] else Path(executable).parent
if level_down:
return str(base_path.parent)
else:
return str(base_path / file_name)
def realWorkingDirectory(level_down: bool = False) -> str:
base_path = Path(argv[0]).parent if argv[0] else Path(executable).parent
if level_down:
return str(base_path.parent)
else:
return str(base_path)