2 # -*- coding: utf-8 -*-
5 sys
.path
.insert(0, "bindings/python/.libs/")
6 from libelliptics_python
import *
8 from pprint
import pprint
11 log
= elliptics_log_file("/dev/stderr", 31)
12 cfg
= elliptics_config()
13 cfg
.cookie
= "0123456789012345678901234567890123456789"
14 cfg
.config
.wait_timeout
= 60
16 n
= elliptics_node_python(log
, cfg
)
19 n
.add_remote("localhost", 1025)
24 addr
= n
.lookup_addr(obj
, group
)
25 print "object", obj
, "should live at", addr
, "in group", group
26 except Exception as e
:
27 print "Failed to lookup in group", group
, ":", e
29 id = elliptics_id([1, 2, 3, 4], 1, 0)
31 # write data by ID into specified group (# 2)
32 # read data from the same group (# 2)
34 data
= '1234567890qwertyuio'
35 n
.write_data(id, data
, 0, 0, 0)
37 n
.write_metadata(id, "", [1], 0)
38 print "Write metadata"
39 except Exception as e
:
40 print "Failed to write data by id:", e
43 s
= n
.read_data(id, 0, 0, 0, 0)
45 except Exception as e
:
46 print "Failed to read data by id:", e
51 s
= n
.read_data(id, 0, 0, 0, 0)
53 except Exception as e
:
54 print "Failed to read data by id:", e
56 # write data into all 3 groups specified in add_groups() call.
57 # read data from the first available group
60 data
= '1234567890qwertyuio'
61 n
.write_data(key
, data
, 0, 0, 0, 0)
62 print "WRITE:", key
, ":", data
63 n
.write_metadata(key
, 0)
64 print "Write metadata"
65 except Exception as e
:
66 print "Failed to write data by string:", e
70 s
= n
.read_data("test.txt", 0, 0, 0, 0, 0)
71 print " READ:", key
, ":", s
72 except Exception as e
:
73 print "Failed to read data by string:", e
76 print n
.read_latest("test.txt", 0, 0, 0, 0, 0);
77 except Exception as e
:
78 print "Failed to read latest data by string:", e
80 # bulk read of keys by name
82 files
= n
.bulk_read(["test1", "test2", "test3", "test4", "test5"], 1, 0)
84 print binascii
.hexlify(f
[:6]), ":", f
[68:]
85 except Exception as e
:
86 print "Failed to read bulk:", e
88 routes
= n
.get_routes()
90 print route
[0].group_id
, route
[0].id, route
[1]
92 print "Requesting stat_log"
96 print "Unexpected error:", sys
.exc_info()