summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-04-08 02:41:29 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-04-08 02:41:29 -0400
commit4dec62b52e9ee5982fc3587ea6c8eefc21d76417 (patch)
tree4603d6c7a34eed267b811efa76dc9a43642d4a93
parent575a267f4f24b1363c63b92a81f1fa0b5c4cc856 (diff)
start soledad sync
-rw-r--r--server-solsync.py18
-rw-r--r--soledad_sync.py50
2 files changed, 68 insertions, 0 deletions
diff --git a/server-solsync.py b/server-solsync.py
new file mode 100644
index 0000000..a228845
--- /dev/null
+++ b/server-solsync.py
@@ -0,0 +1,18 @@
+from klein import run, route
+
+import soledad_sync
+
+
+@route('/start-sync')
+def home(request):
+ print "GOT REQUEST FOR STARTING SYNC..."
+ d = soledad_sync.upload_soledad_stuff()
+ return d
+
+
+@route('/ping')
+def ping(request):
+ return 'easy!'
+
+if __name__ == "__main__":
+ run("localhost", 8080)
diff --git a/soledad_sync.py b/soledad_sync.py
new file mode 100644
index 0000000..403433e
--- /dev/null
+++ b/soledad_sync.py
@@ -0,0 +1,50 @@
+import os
+from leap.soledad.client.api import Soledad
+from twisted.internet import defer
+
+
+UUID = 'deadbeef1'
+HOST = 'http://localhost:2323'
+NUM_DOCS = 20
+PAYLOAD = '/tmp/payload'
+
+
+def _get_soledad_instance_from_uuid(uuid, passphrase, basedir, server_url,
+ cert_file, token):
+ secrets_path = os.path.join(basedir, '%s.secret' % uuid)
+ local_db_path = os.path.join(basedir, '%s.db' % uuid)
+ return Soledad(
+ uuid,
+ unicode(passphrase),
+ secrets_path=secrets_path,
+ local_db_path=local_db_path,
+ server_url=server_url,
+ cert_file=cert_file,
+ auth_token=token,
+ defer_encryption=True,
+ syncable=True)
+
+
+def onSyncDone(result):
+ print "SYNC DONE!", result
+
+
+def upload_soledad_stuff():
+
+ with open(PAYLOAD, 'r') as f:
+ payload = f.read()
+
+ s = _get_soledad_instance_from_uuid(
+ UUID, 'pass', '/tmp/soledadsync', HOST, '', '')
+
+ def do_sync(_):
+ d = s.sync()
+ d.addCallback(onSyncDone)
+ return d
+
+ cd = []
+ for i in range(NUM_DOCS):
+ cd.append(s.create_doc({'payload': payload}))
+ d1 = defer.gatherResults(cd)
+ d1.addCallback(do_sync)
+ return d1