Skip to content

Commit 199beb0

Browse files
committed
Add python example
1 parent 28bf943 commit 199beb0

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Introduction
88

99
BulletinBoard is a general-purpose Distributed-Hash-Table based on [Kademlia](http://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf).
1010

11-
The interface is provided as a D-Bus service via these commands (see [example below](#usage)):
11+
The interface is provided as a D-Bus service via these commands (see [example below](#usage) or [python example](https://github.com/manuels/bulletinboard-dht/tree/master/examples/example.py)):
1212

1313
Service: org.manuel.BulletinBoard
1414
Object Path: /

ci/before_deploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ main() {
5353

5454
gem install --no-ri --no-rdoc ffi
5555
gem install --no-ri --no-rdoc fpm
56-
fpm -s dir -t deb -n $CRATE_NAME -v $TRAVIS_TAG \
56+
fpm -s dir -t deb -n $CRATE_NAME -v `echo $TRAVIS_TAG | tr -d v` \
5757
$src/org.manuel.BulletinBoard.service=/usr/share/dbus-1/services/ \
5858
$src/target/$TARGET/release/bulletinboard=/usr/bin/
59-
fpm -s dir -t rpm -n $CRATE_NAME -v $TRAVIS_TAG \
59+
fpm -s dir -t rpm -n $CRATE_NAME -v `echo $TRAVIS_TAG | tr -d v` \
6060
$src/org.manuel.BulletinBoard.service=/usr/share/dbus-1/services/ \
6161
$src/target/$TARGET/release/bulletinboard=/usr/bin/
6262
cp *deb $src

examples/example.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import dbus
4+
5+
APP_ID = 'mytestapp'
6+
7+
def put(key, value):
8+
bus = dbus.SessionBus()
9+
10+
proxy = bus.get_object('org.manuel.BulletinBoard', '/')
11+
iface = dbus.Interface(proxy, 'org.manuel.BulletinBoard')
12+
iface.Put(APP_ID, key.encode('utf-8'), value.encode('utf-8'))
13+
14+
15+
def get(key):
16+
bus = dbus.SessionBus()
17+
18+
proxy = bus.get_object('org.manuel.BulletinBoard', '/')
19+
iface = dbus.Interface(proxy, 'org.manuel.BulletinBoard')
20+
values = iface.Get(APP_ID, key.encode('utf-8'))
21+
22+
return [bytearray(v).decode('utf-8') for v in values]
23+
24+
25+
def main():
26+
key = 'what is love?'
27+
value = "Baby don't hurt me, don't hurt me no more."
28+
put(key, value)
29+
30+
print(key, get(key))
31+
32+
33+
if __name__ == '__main__':
34+
main()
35+

0 commit comments

Comments
 (0)