improvements

* multi-sign and multi-web configuration
* change default configuration to do not use architecture
* change units to be templated
* some refactoring
This commit is contained in:
2021-03-11 03:55:17 +03:00
parent 30ededb2cd
commit 1770793e69
32 changed files with 235 additions and 173 deletions

View File

@ -18,11 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from aiohttp.web import middleware, Request, Response
from aiohttp.web_exceptions import HTTPClientError
from logging import Logger
from typing import Callable
from aiohttp.web_exceptions import HTTPClientError
def exception_handler(logger: Logger) -> Callable:
@middleware

View File

@ -22,6 +22,7 @@ from aiohttp.web import View
from ahriman.core.watcher.watcher import Watcher
# special class to make it typed
class BaseView(View):
@property

View File

@ -17,18 +17,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from typing import Any, Dict
from aiohttp_jinja2 import template
from typing import Any, Dict
from ahriman.web.views.base import BaseView
class IndexView(BaseView):
@template("index.jinja2")
@template("build-status.jinja2")
async def get(self) -> Dict[str, Any]:
# some magic to make it jinja-readable
# some magic to make it jinja-friendly
packages = [
{
'base': package.base,

View File

@ -38,17 +38,19 @@ async def on_startup(app: web.Application) -> None:
app.logger.info('server started')
try:
app['watcher'].load()
except Exception as e:
except Exception:
app.logger.exception('could not load packages', exc_info=True)
raise InitializeException() from e
raise InitializeException()
def run_server(app: web.Application) -> None:
def run_server(app: web.Application, architecture: str) -> None:
app.logger.info('start server')
web.run_app(app,
host=app['config'].get('web', 'host'),
port=app['config'].getint('web', 'port'),
handle_signals=False)
section = app['config'].get_section_name('web', architecture)
host = app['config'].get(section, 'host')
port = app['config'].getint(section, 'port')
web.run_app(app, host=host, port=port, handle_signals=False)
def setup_service(architecture: str, config: Configuration) -> web.Application: