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",
|
"email":"maloja@krateng.dev",
|
||||||
"github": "krateng"
|
"github": "krateng"
|
||||||
}
|
}
|
||||||
version = 2,4,10
|
version = 2,4,11
|
||||||
versionstr = ".".join(str(n) for n in version)
|
versionstr = ".".join(str(n) for n in version)
|
||||||
links = {
|
links = {
|
||||||
"pypi":"malojaserver",
|
"pypi":"malojaserver",
|
||||||
|
@ -1,23 +1,34 @@
|
|||||||
import os
|
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
|
|
||||||
|
|
||||||
|
# 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:
|
try:
|
||||||
DATA_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
HOME_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
||||||
assert os.path.exists(DATA_DIR)
|
assert os.path.exists(HOME_DIR)
|
||||||
except:
|
except:
|
||||||
DATA_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
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)
|
os.makedirs(DATA_DIR,exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def datadir(*args):
|
def datadir(*args):
|
||||||
return os.path.join(DATA_DIR,*args)
|
return os.path.join(DATA_DIR,*args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### DOREAH CONFIGURATION
|
### DOREAH CONFIGURATION
|
||||||
|
|
||||||
from doreah import config
|
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
|
# thumbor
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user