summaryrefslogtreecommitdiff
path: root/snapdb.py
diff options
context:
space:
mode:
authorTimo <Code-WvS@quantentunnel.de>2015-02-21 16:30:03 +0100
committerTimo <Code-WvS@quantentunnel.de>2015-02-21 16:30:03 +0100
commit65636d5968e938dbcb21e89644577f9d1fed54e4 (patch)
treec32817d6033fe178da1254a3edb9665e2607d792 /snapdb.py
downloadSnapDB-65636d5968e938dbcb21e89644577f9d1fed54e4.tar.gz
SnapDB-65636d5968e938dbcb21e89644577f9d1fed54e4.zip
first commit
Diffstat (limited to 'snapdb.py')
-rwxr-xr-xsnapdb.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/snapdb.py b/snapdb.py
new file mode 100755
index 0000000..8bdb2ff
--- /dev/null
+++ b/snapdb.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+from mongodict import MongoDict
+from blockext import *
+from config import config
+
+class Storage:
+ def __init__(self):
+ self.db = MongoDict(
+ host=config["host"], port=config["port"],
+ database=config["database"], collection=config["collection"],
+ auth=(config["username"], config["password"]))
+
+ @predicate("%s from the database")
+ def get(self, key):
+ if key in self.db:
+ return self.db[key]
+ else:
+ return ""
+
+ @command("%s as %s into the database")
+ def put(self, value, key):
+ self.db[key] = value
+
+descriptor = Descriptor(
+ name = "SnapDB",
+ port = config["localport"],
+ blocks = get_decorated_blocks_from_class(Storage)
+)
+
+extension = Extension(Storage, descriptor)
+
+if __name__ == "__main__":
+ extension.run_forever(debug=True)