-
Notifications
You must be signed in to change notification settings - Fork 0
/
replication.py
38 lines (35 loc) · 1.15 KB
/
replication.py
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
from couchdb import Server
from couchdb.client import Row, ViewResults
try:
import simplejson as json
except ImportError:
import json # Python 2.6
import os
DATABASE = "cozy-files"
SERVER = Server('http://localhost:5984/')
def replicate_from_local_ids(ids):
'''
Replicate metadata from local to cozy with a one-shot replication
'''
database = SERVER[DATABASE]
(username, password) = _get_credentials()
source = 'http://%s:%s@localhost:5984/%s' % (username, password, DATABASE)
res = database.view('device/all')
for device in res:
device = device.value
url = device['url'].split('/')
target = "https://%s:%s@%s/cozy" % (device['login'], device['password'], url[2])
print(source)
print(target)
SERVER.replicate(source, target, doc_ids=ids)
def _get_credentials():
'''
Get credentials from config file.
'''
#credentials_file = open('/etc/cozy/cozy-files/couchdb.login')
#lines = credentials_file.readlines()
#credentials_file.close()
#username = lines[0].strip()
#password = lines[1].strip()
#return (username, password)
return("test", "secret")