remove config caching and add ability to set config default

This commit is contained in:
Izalia Mae 2021-09-15 08:14:50 -04:00
parent 0620b67bd3
commit 11d9bd9890
5 changed files with 37 additions and 17 deletions

View file

@ -77,6 +77,7 @@ class Session(SqlSession):
privkey = (None, str),
name = ('Uncia Relay', str),
description = ('Small and fast ActivityPub relay', str),
rules = ([], DotDict),
require_approval = (True, boolean),
email = (None, str),
show_domain_bans = (False, boolean),

View file

@ -52,10 +52,10 @@ def cmd_config(self, key):
if key not in self.config_defaults:
raise KeyError(f'Invalid config option: {key}')
cache = self.cache.config.fetch(key)
#cache = self.cache.config.fetch(key)
if cache:
return cache
#if cache:
#return cache
row = self.fetch('config', key=key)
@ -63,7 +63,7 @@ def cmd_config(self, key):
return self.config_defaults[key][0]
value = self.config_defaults[key][1](row.value)
self.cache.config.store(key, value)
#self.cache.config.store(key, value)
return value

View file

@ -26,16 +26,20 @@ def cmd_actor(self, url, actor):
return row
def cmd_config(self, key, value):
def cmd_config(self, key, value=None):
row = self.fetch('config', key=key)
if not value:
value = self.config_defaults[key][0]
if row:
self.update(row=row, value=value)
else:
self.insert('config', key=key, value=value)
self.cache.config.store(key, value)
#self.cache.config.store(key, value)
return value
def cmd_instance(self, inbox, actor, followid=None):

View file

@ -13,6 +13,7 @@ exe = f'{sys.executable} -m uncia.manage'
forbidden_keys = ['pubkey', 'privkey', 'version']
## todo: use argparse to simplify argument parsing
class Command:
def __init__(self, arguments):
try:
@ -53,8 +54,11 @@ python3 -m uncia.manage config [key] [value]:
if key in forbidden_keys:
return f'Refusing to set "{key}"'
s.put.config(key, value)
return self.cmd_config(key)
if value == DefaultValue:
value = None
value = s.put.config(key, value)
return f'Set {key} = "{value}"'
elif key and not value:
value = s.get.config(key)
@ -70,6 +74,9 @@ python3 -m uncia.manage config [key] [value]:
def cmd_set(self, key, *value):
if not value:
return self.cmd_config(key, DefaultValue)
return self.cmd_config(key, ' '.join(value))
@ -161,6 +168,10 @@ class InvalidCommandError(Exception):
pass
class DefaultValue(object):
pass
if __name__ == '__main__':
args = sys.argv[1:] if len(sys.argv) > 1 else []
cmd = Command(args)

View file

@ -30,14 +30,7 @@ class UnciaRules(View):
paths = ['/rules']
async def get(self, request, response):
pass
class UnciaAbout(View):
paths = ['/about']
async def get(self, request, response):
return response.template('page/about.haml')
return response.template('page/rules.haml')
class UnciaRegister(View):
@ -81,11 +74,22 @@ class UnciaLogout(View):
return response.redir('/')
class UnciaUser(View):
paths = ['/user']
async def get(self, request, response):
return response.template('page/user.haml')
async def post(self, request, response):
return await self.get(request, response)
class UnciaAdmin(View):
paths = ['/admin']
async def get(self, request, response):
return response.template('page/home.haml')
return response.template('page/admin.haml')
async def post(self, request, response):