Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 81 lines (63 sloc) 2.841 kB
#!/usr/bin/env python
"""
interactive Cassandra Python shell
"""
try:
from IPython.Shell import IPShellEmbed
except ImportError:
print "[I]: IPython not found, falling back to default interpreter."
def runshell():
import os
os.environ['PYTHONINSPECT'] = '1'
try:
runshell = IPShellEmbed([])
except NameError:
pass
import pycassa, optparse
from pycassa.system_manager import *
from sys import stderr, exit
parser = optparse.OptionParser(usage='Usage: %prog [OPTIONS]')
parser.add_option('-k', '--keyspace', help='Cassandra keyspace name.')
parser.add_option('-H', '--host', help='Hostname.')
parser.add_option('-p', '--port', type="int", help='Thrift port number.')
parser.add_option('-u', '--user', help='Username (for simple auth).')
parser.add_option('-P', '--passwd', help='Password (for simple auth).')
parser.add_option('-S', '--streaming', help='Using streaming transport.',
action="store_false", dest='framed')
parser.add_option('-F', '--framed',
help='Use framed transport. Default transport.',
action="store_true", dest='framed')
(options, args) = parser.parse_args()
hostname = options.host and options.host or 'localhost'
port = options.port and options.port or 9160
framed = True if options.framed is None else options.framed
credentials = None
if options.user or options.passwd:
if options.user and (not options.passwd):
print >>stderr, "You must supply a password for username", options.user
exit(1)
if options.passwd and (not options.user):
print >>stderr, "You need a user to go with that password!"
exit(1)
credentials = {'username': options.user, 'password': options.passwd}
SYSTEM_MANAGER = pycassa.SystemManager('%s:%d' % (hostname, port), credentials, framed)
print "----------------------------------"
print "Cassandra Interactive Python Shell"
print "----------------------------------"
print "Keyspace: %s" % options.keyspace
print "Host: %s:%d" % (hostname, port)
if options.keyspace:
pool = pycassa.QueuePool(keyspace=options.keyspace,
server_list=['%s:%d' % (hostname, port)],
credentials=credentials,
framed_transport=framed)
print "\nAvailable ColumnFamily instances:"
for cfname in SYSTEM_MANAGER.get_keyspace_description(options.keyspace).keys():
cfinstance = pycassa.ColumnFamily(pool, cfname)
exec('%s = cfinstance' % cfname.upper())
spaces = " " * (25 - len(cfname))
print " *", cfname.upper(), spaces, "(", cfname, ")"
else:
print "\nColumnFamily instances are only available if a keyspace is specified with -k/--keyspace"
print "\nSchema definition tools and cluster information are available through SYSTEM_MANAGER."
runshell()
Jump to Line
Something went wrong with that request. Please try again.