mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-23 15:08:00 +00:00
remove appdirs dep and add option to set sqlite database path
This commit is contained in:
parent
e3c4377db6
commit
04ae6a8851
|
@ -1,9 +1,9 @@
|
|||
general:
|
||||
# Address the relay will listen on. Set to "0.0.0.0" for any address
|
||||
listen: 0.0.0.0
|
||||
# Port the relay will listen on
|
||||
# TCP port the relay will listen on
|
||||
port: 3621
|
||||
# Domain the relay will advertise as
|
||||
# Domain the relay will advertise itself as
|
||||
host: relay.example.com
|
||||
|
||||
database:
|
||||
|
@ -14,6 +14,9 @@ database:
|
|||
# Maximum number of database connections to open
|
||||
max_connections: 10
|
||||
|
||||
sqlite:
|
||||
database: relay.sqlite3
|
||||
|
||||
postgres:
|
||||
database: activityrelay
|
||||
hostname: null
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import appdirs
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
from functools import cached_property
|
||||
from pathlib import Path
|
||||
from platform import system
|
||||
|
||||
from .misc import AppBase, DotDict
|
||||
|
||||
|
@ -16,6 +16,7 @@ DEFAULTS = {
|
|||
'database_type': 'sqlite',
|
||||
'database_min_connections': 0,
|
||||
'database_max_connections': 10,
|
||||
'sqlite_database': Path('relay.sqlite3'),
|
||||
'postgres_database': 'activityrelay',
|
||||
'postgres_hostname': None,
|
||||
'postgres_port': None,
|
||||
|
@ -35,26 +36,35 @@ CATEGORY_NAMES = [
|
|||
'mysql'
|
||||
]
|
||||
|
||||
CONFIG_DIRS = [
|
||||
Path.cwd(),
|
||||
Path(appdirs.user_config_dir('activityrelay'))
|
||||
]
|
||||
|
||||
|
||||
def get_config_dir():
|
||||
for path in CONFIG_DIRS:
|
||||
cfgpath = path.joinpath('config.yaml')
|
||||
cwd = Path.cwd().joinpath('config.yaml')
|
||||
plat = system()
|
||||
|
||||
if cwd.exists():
|
||||
return cwd
|
||||
|
||||
elif plat == 'Linux':
|
||||
cfgpath = Path('~/.config/activityrelay/config.yaml').expanduser()
|
||||
|
||||
if cfgpath.exists():
|
||||
return cfgpath
|
||||
|
||||
if sys.platform == 'linux':
|
||||
etcpath = Path('/etc/activityrelay/config.yaml')
|
||||
|
||||
if etcpath.exists():
|
||||
if etcpath.exists() and os.getuid() == etcpath.stat().st_uid:
|
||||
return etcpath
|
||||
|
||||
elif plat == 'Windows':
|
||||
cfgpath = Path('~/AppData/Roaming/activityrelay/config.yaml').expanduer()
|
||||
|
||||
if cfgpath.exists():
|
||||
return cfgpath
|
||||
|
||||
return Path.cwd().joinpath('config.yaml')
|
||||
elif plat == 'Darwin':
|
||||
cfgpath = Path('~/Library/Application Support/activityaelay/config.yaml')
|
||||
|
||||
return cwd
|
||||
|
||||
|
||||
class Config(AppBase, dict):
|
||||
|
@ -68,8 +78,9 @@ class Config(AppBase, dict):
|
|||
path = get_config_dir()
|
||||
|
||||
else:
|
||||
path = Path(path).expanduser().resolve()
|
||||
path = Path(path).expanduser()
|
||||
|
||||
print(path)
|
||||
self._path = path
|
||||
self.load()
|
||||
|
||||
|
@ -81,6 +92,10 @@ class Config(AppBase, dict):
|
|||
elif key in {'general_port', 'database_min_connections', 'database_max_connections'}:
|
||||
value = int(value)
|
||||
|
||||
elif key == 'sqlite_database':
|
||||
if not isinstance(value, Path):
|
||||
value = Path(value)
|
||||
|
||||
dict.__setitem__(self, key, value)
|
||||
|
||||
|
||||
|
@ -93,7 +108,11 @@ class Config(AppBase, dict):
|
|||
}
|
||||
|
||||
if self.dbtype == 'sqlite':
|
||||
config['database'] = self.path.with_name('relay.sqlite3')
|
||||
if not self['sqlite_database'].is_absolute():
|
||||
config['database'] = self.path.with_name(str(self['sqlite_database'])).resolve()
|
||||
|
||||
else:
|
||||
config['database'] = self['sqlite_database'].resolve()
|
||||
|
||||
else:
|
||||
for key, value in self.items():
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
aiohttp>=3.8.0
|
||||
appdirs>=1.4.4
|
||||
aputils@https://git.barkshark.xyz/barkshark/aputils/archive/0.1.3.tar.gz
|
||||
cachetools>=5.2.0
|
||||
click>=8.1.2
|
||||
|
|
Loading…
Reference in a new issue