Permalink
Browse files

Initial revision

  • Loading branch information...
0 parents commit 810496e244050a89171ef792c47fddcc2ea51670 @driftx committed Sep 10, 2009
@@ -0,0 +1,3 @@
+*.pyc
+*.sw?
+*.cache
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2009 Brandon Williams, <brandon@faltering.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
21 README
@@ -0,0 +1,21 @@
+Telephus
+========
+
+Description
+-----------
+
+Telephus is a connection pooled, low-level client API for Cassandra in Twisted python.
+
+Installation
+------------
+
+Prerequisites:
+
+ * Python 2.4 or later
+ * Twisted 8.1.0 or later
+ * Thrift (latest svn)
+
+Usage
+-----
+
+See example.py for an example of how to use the Telephus API.
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+from telephus.protocol import ManagedCassandraClientFactory
+from telephus.client import CassandraClient
+from telephus.cassandra.ttypes import ColumnPath, ColumnParent
+from twisted.internet import defer
+
+HOST = 'localhost'
+PORT = 9160
+KEYSPACE = 'MyKeyspace'
+CF = 'MyColumnFamily'
+SCF = 'MySuperColumnFamily'
+colname = 'foo'
+
+@defer.inlineCallbacks
+def dostuff(client):
+ yield client.insert('test', ColumnPath(CF, None, colname), 'testval')
+ yield client.insert('test2', ColumnPath(CF, None, colname), 'testval')
+ res = yield client.get('test', ColumnPath(CF, None, colname))
+ print 'get', res
+ res = yield client.get_slice('test', ColumnParent(CF))
+ print 'get_slice', res
+ res = yield client.multiget(['test', 'test2'], ColumnPath(CF, None, colname))
+ print 'multiget', res
+ res = yield client.multiget_slice(['test', 'test2'], ColumnParent(CF))
+ print 'multiget_slice', res
+ res = yield client.get_count('test', ColumnParent(CF))
+ print 'get_count', res
+ res = yield client.batch_insert('test', CF, {colname: 'bar'})
+ print "batch_insert", res
+ res = yield client.batch_insert('test', SCF, {'foo': {colname: 'bar'}})
+ print "batch_insert", res
+
+
+if __name__ == '__main__':
+ from twisted.internet import reactor
+ from twisted.python import log
+ import sys
+ log.startLogging(sys.stdout)
+
+ f = ManagedCassandraClientFactory()
+ c = CassandraClient(f, KEYSPACE)
+ testem(c)
+ reactor.connectTCP(HOST, PORT, f)
+ reactor.run()
No changes.
@@ -0,0 +1,156 @@
+#!/usr/bin/env python
+#
+# Autogenerated by Thrift
+#
+# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+#
+
+import sys
+import pprint
+from urlparse import urlparse
+from thrift.transport import TTransport
+from thrift.transport import TSocket
+from thrift.transport import THttpClient
+from thrift.protocol import TBinaryProtocol
+
+import Cassandra
+from ttypes import *
+
+if len(sys.argv) <= 1 or sys.argv[1] == '--help':
+ print ''
+ print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
+ print ''
+ print 'Functions:'
+ print ' ColumnOrSuperColumn get(string keyspace, string key, ColumnPath column_path, ConsistencyLevel consistency_level)'
+ print ' get_slice(string keyspace, string key, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)'
+ print ' multiget(string keyspace, keys, ColumnPath column_path, ConsistencyLevel consistency_level)'
+ print ' multiget_slice(string keyspace, keys, ColumnParent column_parent, SlicePredicate predicate, ConsistencyLevel consistency_level)'
+ print ' i32 get_count(string keyspace, string key, ColumnParent column_parent, ConsistencyLevel consistency_level)'
+ print ' get_key_range(string keyspace, string column_family, string start, string finish, i32 count, ConsistencyLevel consistency_level)'
+ print ' void insert(string keyspace, string key, ColumnPath column_path, string value, i64 timestamp, ConsistencyLevel consistency_level)'
+ print ' void batch_insert(string keyspace, string key, cfmap, ConsistencyLevel consistency_level)'
+ print ' void remove(string keyspace, string key, ColumnPath column_path, i64 timestamp, ConsistencyLevel consistency_level)'
+ print ' string get_string_property(string property)'
+ print ' get_string_list_property(string property)'
+ print ' describe_keyspace(string keyspace)'
+ print ''
+ sys.exit(0)
+
+pp = pprint.PrettyPrinter(indent = 2)
+host = 'localhost'
+port = 9090
+uri = ''
+framed = False
+http = False
+argi = 1
+
+if sys.argv[argi] == '-h':
+ parts = sys.argv[argi+1].split(':')
+ host = parts[0]
+ port = int(parts[1])
+ argi += 2
+
+if sys.argv[argi] == '-u':
+ url = urlparse(sys.argv[argi+1])
+ parts = url[1].split(':')
+ host = parts[0]
+ if len(parts) > 1:
+ port = int(parts[1])
+ else:
+ port = 80
+ uri = url[2]
+ http = True
+ argi += 2
+
+if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
+ framed = True
+ argi += 1
+
+cmd = sys.argv[argi]
+args = sys.argv[argi+1:]
+
+if http:
+ transport = THttpClient.THttpClient(host, port, uri)
+else:
+ socket = TSocket.TSocket(host, port)
+ if framed:
+ transport = TTransport.TFramedTransport(socket)
+ else:
+ transport = TTransport.TBufferedTransport(socket)
+protocol = TBinaryProtocol.TBinaryProtocol(transport)
+client = Cassandra.Client(protocol)
+transport.open()
+
+if cmd == 'get':
+ if len(args) != 4:
+ print 'get requires 4 args'
+ sys.exit(1)
+ pp.pprint(client.get(args[0],args[1],eval(args[2]),eval(args[3]),))
+
+elif cmd == 'get_slice':
+ if len(args) != 5:
+ print 'get_slice requires 5 args'
+ sys.exit(1)
+ pp.pprint(client.get_slice(args[0],args[1],eval(args[2]),eval(args[3]),eval(args[4]),))
+
+elif cmd == 'multiget':
+ if len(args) != 4:
+ print 'multiget requires 4 args'
+ sys.exit(1)
+ pp.pprint(client.multiget(args[0],eval(args[1]),eval(args[2]),eval(args[3]),))
+
+elif cmd == 'multiget_slice':
+ if len(args) != 5:
+ print 'multiget_slice requires 5 args'
+ sys.exit(1)
+ pp.pprint(client.multiget_slice(args[0],eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))
+
+elif cmd == 'get_count':
+ if len(args) != 4:
+ print 'get_count requires 4 args'
+ sys.exit(1)
+ pp.pprint(client.get_count(args[0],args[1],eval(args[2]),eval(args[3]),))
+
+elif cmd == 'get_key_range':
+ if len(args) != 6:
+ print 'get_key_range requires 6 args'
+ sys.exit(1)
+ pp.pprint(client.get_key_range(args[0],args[1],args[2],args[3],eval(args[4]),eval(args[5]),))
+
+elif cmd == 'insert':
+ if len(args) != 6:
+ print 'insert requires 6 args'
+ sys.exit(1)
+ pp.pprint(client.insert(args[0],args[1],eval(args[2]),args[3],eval(args[4]),eval(args[5]),))
+
+elif cmd == 'batch_insert':
+ if len(args) != 4:
+ print 'batch_insert requires 4 args'
+ sys.exit(1)
+ pp.pprint(client.batch_insert(args[0],args[1],eval(args[2]),eval(args[3]),))
+
+elif cmd == 'remove':
+ if len(args) != 5:
+ print 'remove requires 5 args'
+ sys.exit(1)
+ pp.pprint(client.remove(args[0],args[1],eval(args[2]),eval(args[3]),eval(args[4]),))
+
+elif cmd == 'get_string_property':
+ if len(args) != 1:
+ print 'get_string_property requires 1 args'
+ sys.exit(1)
+ pp.pprint(client.get_string_property(args[0],))
+
+elif cmd == 'get_string_list_property':
+ if len(args) != 1:
+ print 'get_string_list_property requires 1 args'
+ sys.exit(1)
+ pp.pprint(client.get_string_list_property(args[0],))
+
+elif cmd == 'describe_keyspace':
+ if len(args) != 1:
+ print 'describe_keyspace requires 1 args'
+ sys.exit(1)
+ pp.pprint(client.describe_keyspace(args[0],))
+
+transport.close()
Oops, something went wrong.

0 comments on commit 810496e

Please sign in to comment.