|
|
|
@ -7,12 +7,13 @@ from dotenv import load_dotenv
|
|
|
|
|
def app_root_path():
|
|
|
|
|
app_path = Path(sys.argv[0]).resolve()
|
|
|
|
|
try:
|
|
|
|
|
if app_path.parent.name == "bin": # Installed in unixy hierachy
|
|
|
|
|
if app_path.parent.name == "bin": # Installed in unixy hierachy
|
|
|
|
|
return app_path.parents[1]
|
|
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
return app_path.parent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# None will let direnv do its' thing
|
|
|
|
|
env_paths = [Path(".env"), app_root_path() / "etc/environment", None]
|
|
|
|
|
|
|
|
|
@ -27,7 +28,7 @@ class EnvService:
|
|
|
|
|
self.env = {}
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def environment_path_with_fallback(env_name, relative_fallback = None):
|
|
|
|
|
def environment_path_with_fallback(env_name, relative_fallback=None):
|
|
|
|
|
dir = os.getenv(env_name)
|
|
|
|
|
if dir != None:
|
|
|
|
|
return Path(dir).resolve()
|
|
|
|
@ -42,11 +43,17 @@ class EnvService:
|
|
|
|
|
@staticmethod
|
|
|
|
|
def find_shared_file(file_name):
|
|
|
|
|
share_file_paths = []
|
|
|
|
|
share_dir = os.getenv("SHARE_DIR")
|
|
|
|
|
share_dir = os.getenv("SHARE_DIR")
|
|
|
|
|
if share_dir != None:
|
|
|
|
|
share_file_paths.append(share_dir)
|
|
|
|
|
share_file_paths.extend([app_root_path() / "share" / file_name, app_root_path() / file_name, Path(file_name)])
|
|
|
|
|
|
|
|
|
|
share_file_paths.append(share_dir)
|
|
|
|
|
share_file_paths.extend(
|
|
|
|
|
[
|
|
|
|
|
app_root_path() / "share" / file_name,
|
|
|
|
|
app_root_path() / file_name,
|
|
|
|
|
Path(file_name),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for share_file_path in share_file_paths:
|
|
|
|
|
if share_file_path.exists():
|
|
|
|
|
return share_file_path.resolve()
|
|
|
|
|