Skip to content

Commit

Permalink
configurable couchdb url
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijndevos committed Aug 30, 2022
1 parent 11ed9cd commit f90b73c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
16 changes: 9 additions & 7 deletions pyttoresque/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
from jupyter_server.extension.handler import ExtensionHandlerJinjaMixin, ExtensionHandlerMixin
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
from tornado.web import addslash
from traitlets import Bool
from shutil import which
from traitlets import Unicode
from configparser import ConfigParser
from secrets import token_hex
from base64 import b64encode

HERE = os.path.dirname(__file__)

has_couchdb = bool(which("couchdb"))

class LibmanHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):
@addslash
def get(self):
Expand All @@ -25,7 +22,8 @@ def get(self):
"libman.html",
static=self.static_url,
token=self.settings["token"],
couchdb=has_couchdb,
couchdb=self.settings['mosaic_config']['couchdb'],
couchdb_sync=self.settings['mosaic_config']['couchdb_sync'],
)
)

Expand All @@ -37,7 +35,8 @@ def get(self):
"editor.html",
static=self.static_url,
token=self.settings["token"],
couchdb=has_couchdb,
couchdb=self.settings['mosaic_config']['couchdb'],
couchdb_sync=self.settings['mosaic_config']['couchdb_sync'],
)
)

Expand All @@ -46,6 +45,9 @@ class Mosaic(ExtensionAppJinjaMixin, ExtensionApp):
default_url = "/mosaic"
static_paths = [os.path.join(HERE, "static")]
template_paths = [os.path.join(HERE, "templates")]

couchdb = Unicode("proxy", help="CouchDB URL to use").tag(config=True)
couchdb_sync = Unicode(help="Remote CouchDB URL to synch PouchDB with").tag(config=True)

def initialize_settings(self):
super().initialize_settings()
Expand Down Expand Up @@ -77,7 +79,7 @@ def command(port):
# so we have to use a persistent file
with open(tmpl, 'w') as f:
cp.write(f)
cmd = ['couchdb', '-couch_ini', tf.name]
cmd = ['couchdb', '-couch_ini', tmpl]
if os.name == 'nt':
cmd = ["cmd.exe", "/c"] + cmd
return cmd
Expand Down
9 changes: 7 additions & 2 deletions pyttoresque/app/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
<body>
<div id="mosaic_editor"></div>
<script>
{% if couchdb %}
window.dburl = new URL("/couchdb/", window.location).href
{% if couchdb=="proxy" %}
window.dburl = new URL("../../couchdb/", window.location).href
{% elif couchdb %}
window.dburl = "{{ couchdb }}"
{% endif %}
{% if couchdb_sync %}
window.default_sync = "{{ couchdb_sync }}"
{% endif %}
window.notebookurl = "../../lab"
window.simulatorurl = "../../panel/app"
Expand Down
9 changes: 7 additions & 2 deletions pyttoresque/app/templates/libman.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@
<body>
<div id="mosaic_libman"></div>
<script>
{% if couchdb %}
window.dburl = new URL("/couchdb/", window.location).href
{% if couchdb=="proxy" %}
window.dburl = new URL("../couchdb/", window.location).href
{% elif couchdb %}
window.dburl = "{{ couchdb }}"
{% endif %}
{% if couchdb_sync %}
window.default_sync = "{{ couchdb_sync }}"
{% endif %}
</script>
<script src="{{ static_url('common.js') }}"></script>
Expand Down

0 comments on commit f90b73c

Please sign in to comment.