summaryrefslogtreecommitdiff
path: root/soledad_sync.py
blob: 154ecfd5d5e95a61ef5d0c13f3bae70dad03a8a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from leap.soledad.client.api import Soledad
from twisted.internet import defer

# EDIT THIS TO MATCH YOUR TEST ENVIRONMENT -------------
UUID = 'deadbeef10'
# HOST = 'http://futeisha:2323'
HOST = 'http://localhost:2323'
# NUM_DOCS = 100
NUM_DOCS = 50
PAYLOAD = '/tmp/payload'
# ------------------------------------------------------



DO_THESEUS = os.environ.get('THESEUS', False)


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()

    if DO_THESEUS:
        from theseus import Tracer
        t = Tracer()
        t.install()

    s = _get_soledad_instance_from_uuid(
        UUID, 'pass', '/tmp/soledadsync', HOST, '', '')

    def do_sync(_):
        d = s.sync()
        d.addCallback(onSyncDone)
        return d

    def stop_tracing(_):
        if DO_THESEUS:
            with open('callgrind.theseus', 'wb') as outfile:
                t.write_data(outfile)
            print "STOPPED TRACING, DUMPED IN CALLGRIND.THESEUS<<<<"

    cd = []
    for i in range(NUM_DOCS):
        cd.append(s.create_doc({'payload': payload}))
    d1 = defer.gatherResults(cd)



    # XXX comment out to nuke out the actual sync
    #d1.addCallback(do_sync)
    d1.addCallback(stop_tracing)


    return d1