summaryrefslogtreecommitdiff
path: root/scripts/profiling/mail/couchdb_server.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-09-16 11:43:58 -0500
committerKali Kaneko <kali@leap.se>2014-09-16 11:43:58 -0500
commit509f76c21c7c847dc4111847a3585be7bb67e350 (patch)
treeee7b2d6bf5921fee9de6e27b0a7a6d97ab559364 /scripts/profiling/mail/couchdb_server.py
parent22d3a8d4c6a1e652109378245989f4f6a71d1f42 (diff)
parent2f1ee76a7169abc100efdf706f12a0abf6032f04 (diff)
Merge remote-tracking branch 'drebs-github/add-benchmarking-scripts' into develop
Diffstat (limited to 'scripts/profiling/mail/couchdb_server.py')
-rw-r--r--scripts/profiling/mail/couchdb_server.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/profiling/mail/couchdb_server.py b/scripts/profiling/mail/couchdb_server.py
new file mode 100644
index 00000000..2cf0a3fd
--- /dev/null
+++ b/scripts/profiling/mail/couchdb_server.py
@@ -0,0 +1,42 @@
+import hashlib
+import couchdb
+
+from leap.soledad.common.couch import CouchDatabase
+
+from util import log
+from couchdb_wrapper import CouchDBWrapper
+
+
+def start_couchdb_wrapper():
+ log("Starting couchdb... ", line_break=False)
+ couchdb_wrapper = CouchDBWrapper()
+ couchdb_wrapper.start()
+ log("couchdb started on port %d." % couchdb_wrapper.port)
+ return couchdb_wrapper
+
+
+def get_u1db_database(dbname, port):
+ return CouchDatabase.open_database(
+ 'http://127.0.0.1:%d/%s' % (port, dbname),
+ True,
+ ensure_ddocs=True)
+
+
+def create_tokens_database(port, uuid, token_value):
+ tokens_database = couchdb.Server(
+ 'http://127.0.0.1:%d' % port).create('tokens')
+ token = couchdb.Document()
+ token['_id'] = hashlib.sha512(token_value).hexdigest()
+ token['user_id'] = uuid
+ token['type'] = 'Token'
+ tokens_database.save(token)
+
+
+def get_couchdb_wrapper_and_u1db(uuid, token_value):
+ couchdb_wrapper = start_couchdb_wrapper()
+
+ couchdb_u1db = get_u1db_database('user-%s' % uuid, couchdb_wrapper.port)
+ get_u1db_database('shared', couchdb_wrapper.port)
+ create_tokens_database(couchdb_wrapper.port, uuid, token_value)
+
+ return couchdb_wrapper, couchdb_u1db