dnet_remove_object_raw() should return error if it failed and dnet_trans_create_send_...
[elliptics.git] / bindings / python / read_latest.py
blob6aa7f24b1f6910956d21a53f52332fe95d9c8f0e
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 import sys
5 #sys.path.insert(0, "/usr/lib/")
6 sys.path.insert(0, "/tmp/dnet/lib/")
7 from libelliptics_python import *
9 from time import time, ctime
11 def add_remotes(n):
12 addresses = [("localhost", 1025),
13 ("localhost", 1026),
14 ("172.16.136.1", 1025),
15 ("172.16.136.1", 1026),
17 failed = 0
19 for addr in addresses:
20 try:
21 n.add_remote(addr[0], addr[1])
22 except:
23 failed += 1
24 pass
26 if failed == len(addresses):
27 raise NameError("Can not add remote nodes")
29 def write(n, id, aflags, groups):
30 remote_offset = 0
31 ioflags = 0
33 n.write_data(id, "time: " + ctime(time()), remote_offset, aflags, ioflags)
34 n.write_metadata(id, "remote id", groups, aflags)
37 def main():
38 try:
39 log = elliptics_log_file("/dev/stderr", 8)
40 n = elliptics_node_python(log)
42 groups = [1, 2, 3]
44 n.add_groups(groups)
45 add_remotes(n)
47 id = elliptics_id([1, 2, 3, 4], 3, 0)
49 aflags = 16 # no locks
51 write(n, id, aflags, groups)
52 ret = n.prepare_latest(id, aflags, groups)
54 print "Groups returned:", ret
56 except Exception as e:
57 print "Exception:", e
59 if __name__ == "__main__":
60 main()