From b7e9d6a35129307e9e663dc1697861c9bc79cc77 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 9 Jun 2020 14:34:22 +1000 Subject: [PATCH] Add a trivial stub web service --- requirements.txt | 4 +++ src/www/serve.py | 52 +++++++++++++++++++++++++++++++++++ src/www/static/.keep | 0 src/www/templates/index.xhtml | 8 ++++++ 4 files changed, 64 insertions(+) create mode 100755 src/www/serve.py create mode 100644 src/www/static/.keep create mode 100644 src/www/templates/index.xhtml diff --git a/requirements.txt b/requirements.txt index 4e1622c..81d3580 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,7 @@ alembic sqlalchemy dateparser + +TurboGears2 +kajiki +webhelpers2 diff --git a/src/www/serve.py b/src/www/serve.py new file mode 100755 index 0000000..21aa29e --- /dev/null +++ b/src/www/serve.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import tg +import tg.util +import tg.configurator.components.sqlalchemy + +import sqlalchemy as sa +import sqlalchemy.orm + + +class RootController(tg.TGController): + @tg.expose('templates/index.xhtml') + def index(self, person=None): + return dict(person=person) + + +config = tg.MinimalApplicationConfigurator() +config.register(tg.configurator.components.sqlalchemy.SQLAlchemyConfigurationComponent) +config.update_blueprint({ + 'serve_static': True, + 'paths': { + 'static_files': 'static' + }, + 'root_controller': RootController(), + 'renderers': ['kajiki'], + 'helpers': 'webhelpers2', + 'use_sqlalchemy': True, + 'sqlalchemy.url': 'sqlite:///../../db/data.sqlite' +}) + + +DBSession = sqlalchemy.orm.scoped_session( + sqlalchemy.orm.sessionmaker(autoflush=True, autocommit=False) +) + +def init_model(engine): + DBSession.configure(bind=engine) + + +config.update_blueprint({ + 'model': tg.util.Bunch( + DBSession=DBSession, + init_model=init_model, + ) +}) + +application = config.make_wsgi_app() + +import wsgiref.simple_server +print ("Serving on 8080") +httpd = wsgiref.simple_server.make_server('', 8080, application) +httpd.serve_forever() diff --git a/src/www/static/.keep b/src/www/static/.keep new file mode 100644 index 0000000..e69de29 diff --git a/src/www/templates/index.xhtml b/src/www/templates/index.xhtml new file mode 100644 index 0000000..24068d4 --- /dev/null +++ b/src/www/templates/index.xhtml @@ -0,0 +1,8 @@ + + Hello + +

Hello ${person}

+
+

Hello World!

+
+