mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Can now use custom data directory with environment variable, close GH-18
This commit is contained in:
parent
e73e047af9
commit
1828bd35bb
@ -5,7 +5,7 @@ author = {
|
||||
"email":"maloja@krateng.dev",
|
||||
"github": "krateng"
|
||||
}
|
||||
version = 2,4,10
|
||||
version = 2,4,11
|
||||
versionstr = ".".join(str(n) for n in version)
|
||||
links = {
|
||||
"pypi":"malojaserver",
|
||||
|
@ -1,23 +1,34 @@
|
||||
import os
|
||||
from doreah.settings import get_settings
|
||||
from doreah.settings import config as settingsconfig
|
||||
|
||||
|
||||
# data folder
|
||||
# must be determined first because getting settings relies on it
|
||||
|
||||
try:
|
||||
DATA_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
||||
assert os.path.exists(DATA_DIR)
|
||||
except:
|
||||
DATA_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
||||
# check environment variables for data directory
|
||||
# otherwise, go with defaults
|
||||
setting_datadir = get_settings("DATA_DIRECTORY",files=[],environ_prefix="MALOJA_")
|
||||
if setting_datadir is not None and os.path.exists(setting_datadir):
|
||||
DATA_DIR = setting_datadir
|
||||
else:
|
||||
try:
|
||||
HOME_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
||||
assert os.path.exists(HOME_DIR)
|
||||
except:
|
||||
HOME_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
||||
|
||||
DATA_DIR = os.path.join(HOME_DIR,"maloja")
|
||||
|
||||
DATA_DIR = os.path.join(DATA_DIR,"maloja")
|
||||
os.makedirs(DATA_DIR,exist_ok=True)
|
||||
|
||||
|
||||
|
||||
def datadir(*args):
|
||||
return os.path.join(DATA_DIR,*args)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### DOREAH CONFIGURATION
|
||||
|
||||
from doreah import config
|
||||
@ -44,9 +55,10 @@ config(
|
||||
}
|
||||
)
|
||||
|
||||
# because we loaded a doreah module already before setting the config, we need to to that manually
|
||||
settingsconfig._readpreconfig()
|
||||
|
||||
|
||||
from doreah.settings import get_settings
|
||||
|
||||
# thumbor
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user