chaind/chaind/setup.py

50 lines
1.6 KiB
Python
Raw Normal View History

2021-06-03 13:48:33 +02:00
# standard imports
import os
import uuid
# external imports
import chainqueue
import chainsyncer
from xdg.BaseDirectory import (
xdg_data_dirs,
get_runtime_dir,
load_first_config,
2021-07-17 08:22:39 +02:00
save_config_path,
2021-06-03 13:48:33 +02:00
)
class Environment:
def __init__(self, domain=None, session=None, env={}):
if not session:
session = env.get('CHAIND_SESSION')
if not session:
session = uuid.uuid4()
self.__session = session
if not domain:
domain = env.get('CHAIND_DOMAIN')
base_config_dir = load_first_config('chaind')
self.runtime_dir = os.path.join(get_runtime_dir(), 'chaind')
self.data_dir = os.path.join(xdg_data_dirs[0], 'chaind')
2021-07-17 08:22:39 +02:00
self.config_dir = env.get('CONFINI_DIR', base_config_dir)
if self.config_dir == None:
save_config_path('chaind')
self.config_dir = load_first_config('chaind')
2021-06-03 13:48:33 +02:00
self.session_runtime_dir = os.path.join(self.runtime_dir, self.session)
if domain:
self.runtime_dir = os.path.join(self.runtime_dir, domain)
2021-07-17 08:22:39 +02:00
os.makedirs(self.runtime_dir, exist_ok=True)
2021-06-03 13:48:33 +02:00
self.data_dir = os.path.join(self.data_dir, domain)
2021-07-17 08:22:39 +02:00
os.makedirs(self.data_dir, exist_ok=True)
2021-06-03 13:48:33 +02:00
self.config_dir = os.path.join(self.config_dir, domain)
2021-07-17 08:22:39 +02:00
os.makedirs(self.config_dir, exist_ok=True)
2021-06-03 13:48:33 +02:00
self.session_runtime_dir = os.path.join(self.runtime_dir, self.session)
2021-07-17 08:22:39 +02:00
os.makedirs(self.session_runtime_dir, exist_ok=True)
2021-06-03 13:48:33 +02:00
@property
def session(self):
return str(self.__session)