Skip to content

Commit

Permalink
launch local couchdb
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijndevos committed May 3, 2022
1 parent 72b023f commit 0316d7e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 6 deletions.
12 changes: 9 additions & 3 deletions pyttoresque/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
from tornado.web import addslash
from traitlets import Bool
from subprocess import Popen
from shutil import which

HERE = os.path.dirname(__file__)

Expand Down Expand Up @@ -42,7 +44,7 @@ class Mosaic(ExtensionAppJinjaMixin, ExtensionApp):
static_paths = [os.path.join(HERE, "static")]
template_paths = [os.path.join(HERE, "templates")]

couchdb = Bool(help="Use localhost CouchDB instead of PouchDB").tag(config=True)
couchdb = Bool(help="Launch localhost CouchDB instead of using PouchDB").tag(config=True)

def initialize_settings(self):
self.settings["mosaic_couchdb"] = self.couchdb
Expand All @@ -54,15 +56,19 @@ def initialize_handlers(self):

super().initialize_handlers()

binpath = which('couchdb')
if binpath and self.couchdb:
Popen([binpath, '-couch_ini', os.path.join(HERE, "static", "local.ini")])


def main():
Mosaic.launch_instance()


def setup_pouchdb():
def setup_couchdb():
return {
# hardcode port for backend access
'command': ['pouchdb-server', '-p', '{port}'],
'command': ['couchdb', '-couch_ini', os.path.join(HERE, "static", "local.ini")],
'port': 5984
}

Expand Down
101 changes: 101 additions & 0 deletions pyttoresque/app/static/local.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
; CouchDB Configuration Settings

; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.

[couchdb]
;max_document_size = 4294967296 ; bytes
single_node=true

[httpd]
;port = 5984
;bind_address = 127.0.0.1
; Options for the MochiWeb HTTP server.
;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
; For more socket options, consult Erlang's module 'inet' man page.
;socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]

; Uncomment next line to trigger basic-auth popup on unauthorized requests.
;WWW-Authenticate = Basic realm="administrator"

; Uncomment next line to set the configuration modification whitelist. Only
; whitelisted values may be changed via the /_config URLs. To allow the admin
; to change this value over HTTP, remember to include {httpd,config_whitelist}
; itself. Excluding it from the list would require editing this file to update
; the whitelist.
;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]
enable_cors = true

[cors]
origins = *
credentials = true
methods = GET, PUT, POST, HEAD, DELETE
headers = accept, authorization, content-type, origin, referer, x-csrf-token

[httpd_global_handlers]
;_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}

[couch_httpd_auth]
; If you set this to true, you should also uncomment the WWW-Authenticate line
; above. If you don't configure a WWW-Authenticate header, CouchDB will send
; Basic realm="server" in order to prevent you getting logged out.
; require_valid_user = false

[log]
;level = debug

[log_level_by_module]
; In this section you can specify any of the four log levels 'none', 'info',
; 'error' or 'debug' on a per-module basis. See src/*/*.erl for various
; modules.
;couch_httpd = error


[os_daemons]
; For any commands listed here, CouchDB will attempt to ensure that
; the process remains alive. Daemons should monitor their environment
; to know when to exit. This can most easily be accomplished by exiting
; when stdin is closed.
;foo = /path/to/command -with args

[daemons]
; enable SSL support by uncommenting the following line and supply the PEM's below.
; the default ssl port CouchDB listens on is 6984
; httpsd = {couch_httpd, start_link, [https]}

[ssl]
;cert_file = /full/path/to/server_cert.pem
;key_file = /full/path/to/server_key.pem
;password = somepassword
; set to true to validate peer certificates
verify_ssl_certificates = false
; Path to file containing PEM encoded CA certificates (trusted
; certificates used for verifying a peer certificate). May be omitted if
; you do not want to verify the peer.
;cacert_file = /full/path/to/cacertf
; The verification fun (optional) if not specified, the default
; verification fun will be used.
;verify_fun = {Module, VerifyFun}
; maximum peer certificate depth
ssl_certificate_max_depth = 1

; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
; the Virual Host will be redirected to the path. In the example below all requests
; to http://example.com/ are redirected to /database.
; If you run CouchDB on a specific port, include the port number in the vhost:
; example.com:5984 = /database
[vhosts]
;example.com = /database/

[update_notification]
;unique notifier name=/full/path/to/exe -with "cmd line arg"

; To create an admin account uncomment the '[admins]' section below and add a
; line in the format 'username = password'. When you next start CouchDB, it
; will change the password to a hash (so that your passwords don't linger
; around in plain-text files). You can add more admin accounts with more
; 'username = password' lines. Don't forget to restart CouchDB after
; changing this.
[admins]
admin = admin
2 changes: 1 addition & 1 deletion pyttoresque/app/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div id="mosaic_editor"></div>
<script>
{% if couchdb %}
window.dburl = "http://localhost:5984"
window.dburl = "http://admin:admin@localhost:5984"
{% endif %}
window.notebookurl = "../../lab"
window.simulatorurl = "../../panel/app"
Expand Down
2 changes: 1 addition & 1 deletion pyttoresque/app/templates/libman.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div id="mosaic_libman"></div>
<script>
{% if couchdb %}
window.dburl = "http://localhost:5984"
window.dburl = "http://admin:admin@localhost:5984"
{% endif %}
</script>
<script src="{{ static_url('common.js') }}"></script>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
'jupyter_serverproxy_servers': [
# name = packagename:function_name
# 'pouchdb = pyttoresque.app:setup_pouchdb',
# 'couchdb = pyttoresque.app:setup_couchdb',
'panel = pyttoresque.app:setup_panel',
]
},
Expand Down

0 comments on commit 0316d7e

Please sign in to comment.