summaryrefslogtreecommitdiff
path: root/scripts/preload_server_database.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-05-02 20:13:19 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-05-02 20:13:19 -0400
commit01e2a72ce30f0fbb4a027d3246a8ba16e00ae197 (patch)
tree22fc0d2b7016d34d48fad45c88349b0103cd8308 /scripts/preload_server_database.py
parent71a21f8fa46e8ea834fe3381abdadde59788d37b (diff)
parentf72a3bf28f4bf001106ad4d42ae7eb4f61b77828 (diff)
Merge remote-tracking branch 'kali-github/pr/2'
Diffstat (limited to 'scripts/preload_server_database.py')
-rwxr-xr-xscripts/preload_server_database.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/scripts/preload_server_database.py b/scripts/preload_server_database.py
new file mode 100755
index 0000000..95e8cfd
--- /dev/null
+++ b/scripts/preload_server_database.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+"""
+Preload the server database with a certain amount of documents so we can
+receive them during the sync process and gather meaningful statistics for that
+specific phase of sync.
+
+Gets uuid, payload file path and amount of documents to preload from
+"defaults.conf" config file:
+
+ UUID = some-uuid
+ PAYLOAD = /path/to/payload/file
+ NUM_DOCS = 100
+"""
+
+import os
+from ConfigParser import ConfigParser
+from leap.soledad.common.couch import CouchDatabase
+
+parser = ConfigParser()
+parser.read('defaults.conf')
+
+UUID = parser.get('client', 'uuid')
+PAYLOAD = parser.get('sync', 'payload')
+NUM_DOCS = int(parser.get('sync', 'num_docs'))
+
+db = CouchDatabase.open_database(
+ 'http://127.0.0.1:5984/user-%s' % UUID,
+ False) # should create database?
+
+payload = None
+if os.path.isfile(PAYLOAD):
+ with open(PAYLOAD, 'r') as f:
+ payload = f.read()
+
+for i in xrange(NUM_DOCS):
+ db.create_doc({'payload': payload})
+
+db.close()