Skip to content

Commit

Permalink
feat(script): add option --chimedb-enable-test
Browse files Browse the repository at this point in the history
  • Loading branch information
nritsche committed Nov 2, 2020
1 parent 9669ead commit 4b28836
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 0 additions & 2 deletions bondia/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from chimedb.core import connect as connect_chimedb
from chimedb.core.mediawiki import MediaWikiUser

import os
Expand Down Expand Up @@ -37,7 +36,6 @@ def post(self):
self.redirect(os.getenv("BONDIA_ROOT_URL", "") + "/login" + error_msg)
return

connect_chimedb()
try:
MediaWikiUser.authenticate(username, password)
except UserWarning as err:
Expand Down
8 changes: 2 additions & 6 deletions bondia/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
import logging
import panel as pn

from chimedb.core import connect as chimedbconnect

from .data import DataLoader
from .util.exception import ConfigError
from .gui import BondiaGui

logger = logging.getLogger(__name__)

# Open DB connection
chimedbconnect(reconnect=True)
logging.basicConfig(level=logging.DEBUG)


class BondiaServer(Reader):
Expand Down Expand Up @@ -54,7 +50,7 @@ def _finalise_config(self):
raise ConfigError("No data available.")

def gui_instance(self):
# logger.debug(f"Starting user session {pn.state.curdoc.session_context.id}.")
logger.debug("Starting user session.")
instance = BondiaGui(
self._template,
self._width_drawer_widgets,
Expand Down
23 changes: 22 additions & 1 deletion scripts/bondia-server
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import pathlib
import secrets
import yaml

from chimedb.core import test_enable as chimedb_test_enable, connect as chimedb_connect

from bondia.server import BondiaServer
from bondia import auth, __version__

Expand Down Expand Up @@ -50,7 +52,22 @@ logger = logging.getLogger("bondia-server")
default=True,
show_default=True,
)
def start(configfile, show, port, num_procs, websocket_origin, login, print_config):
@click.option(
"--chimedb-enable-test/--co-chimedb-enable-test",
help="Use chimedb in test mode (make sure to not use production DB settings).",
default=False,
show_default=True,
)
def start(
configfile,
show,
port,
num_procs,
websocket_origin,
login,
print_config,
chimedb_enable_test,
):

logging.basicConfig(level=logging.INFO)

Expand All @@ -60,6 +77,10 @@ def start(configfile, show, port, num_procs, websocket_origin, login, print_conf
if print_config:
logger.info(f"Loaded config: {config}")

if chimedb_enable_test:
chimedb_test_enable()
chimedb_connect(reconnect=True)

if isinstance(websocket_origin, str):
websocket_origin = [websocket_origin]

Expand Down

0 comments on commit 4b28836

Please sign in to comment.