#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.9.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
#  options string: py
#

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 Hbase
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 '  void enableTable(Bytes tableName)'
  print '  void disableTable(Bytes tableName)'
  print '  bool isTableEnabled(Bytes tableName)'
  print '  void compact(Bytes tableNameOrRegionName)'
  print '  void majorCompact(Bytes tableNameOrRegionName)'
  print '   getTableNames()'
  print '   getColumnDescriptors(Text tableName)'
  print '   getTableRegions(Text tableName)'
  print '  void createTable(Text tableName,  columnFamilies)'
  print '  void deleteTable(Text tableName)'
  print '   get(Text tableName, Text row, Text column,  attributes)'
  print '   getVer(Text tableName, Text row, Text column, i32 numVersions,  attributes)'
  print '   getVerTs(Text tableName, Text row, Text column, i64 timestamp, i32 numVersions,  attributes)'
  print '   getRow(Text tableName, Text row,  attributes)'
  print '   getRowWithColumns(Text tableName, Text row,  columns,  attributes)'
  print '   getRowTs(Text tableName, Text row, i64 timestamp,  attributes)'
  print '   getRowWithColumnsTs(Text tableName, Text row,  columns, i64 timestamp,  attributes)'
  print '   getRows(Text tableName,  rows,  attributes)'
  print '   getRowsWithColumns(Text tableName,  rows,  columns,  attributes)'
  print '   getRowsTs(Text tableName,  rows, i64 timestamp,  attributes)'
  print '   getRowsWithColumnsTs(Text tableName,  rows,  columns, i64 timestamp,  attributes)'
  print '  void mutateRow(Text tableName, Text row,  mutations,  attributes)'
  print '  void mutateRowTs(Text tableName, Text row,  mutations, i64 timestamp,  attributes)'
  print '  void mutateRows(Text tableName,  rowBatches,  attributes)'
  print '  void mutateRowsTs(Text tableName,  rowBatches, i64 timestamp,  attributes)'
  print '  i64 atomicIncrement(Text tableName, Text row, Text column, i64 value)'
  print '  void deleteAll(Text tableName, Text row, Text column,  attributes)'
  print '  void deleteAllTs(Text tableName, Text row, Text column, i64 timestamp,  attributes)'
  print '  void deleteAllRow(Text tableName, Text row,  attributes)'
  print '  void increment(TIncrement increment)'
  print '  void incrementRows( increments)'
  print '  void deleteAllRowTs(Text tableName, Text row, i64 timestamp,  attributes)'
  print '  ScannerID scannerOpenWithScan(Text tableName, TScan scan,  attributes)'
  print '  ScannerID scannerOpen(Text tableName, Text startRow,  columns,  attributes)'
  print '  ScannerID scannerOpenWithStop(Text tableName, Text startRow, Text stopRow,  columns,  attributes)'
  print '  ScannerID scannerOpenWithPrefix(Text tableName, Text startAndPrefix,  columns,  attributes)'
  print '  ScannerID scannerOpenTs(Text tableName, Text startRow,  columns, i64 timestamp,  attributes)'
  print '  ScannerID scannerOpenWithStopTs(Text tableName, Text startRow, Text stopRow,  columns, i64 timestamp,  attributes)'
  print '   scannerGet(ScannerID id)'
  print '   scannerGetList(ScannerID id, i32 nbRows)'
  print '  void scannerClose(ScannerID id)'
  print '   getRowOrBefore(Text tableName, Text row, Text family)'
  print '  TRegionInfo getRegionInfo(Text row)'
  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]
  if len(parts) > 1:
    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]
  if url[4]:
    uri += '?%s' % url[4]
  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 = Hbase.Client(protocol)
transport.open()

if cmd == 'enableTable':
  if len(args) != 1:
    print 'enableTable requires 1 args'
    sys.exit(1)
  pp.pprint(client.enableTable(eval(args[0]),))

elif cmd == 'disableTable':
  if len(args) != 1:
    print 'disableTable requires 1 args'
    sys.exit(1)
  pp.pprint(client.disableTable(eval(args[0]),))

elif cmd == 'isTableEnabled':
  if len(args) != 1:
    print 'isTableEnabled requires 1 args'
    sys.exit(1)
  pp.pprint(client.isTableEnabled(eval(args[0]),))

elif cmd == 'compact':
  if len(args) != 1:
    print 'compact requires 1 args'
    sys.exit(1)
  pp.pprint(client.compact(eval(args[0]),))

elif cmd == 'majorCompact':
  if len(args) != 1:
    print 'majorCompact requires 1 args'
    sys.exit(1)
  pp.pprint(client.majorCompact(eval(args[0]),))

elif cmd == 'getTableNames':
  if len(args) != 0:
    print 'getTableNames requires 0 args'
    sys.exit(1)
  pp.pprint(client.getTableNames())

elif cmd == 'getColumnDescriptors':
  if len(args) != 1:
    print 'getColumnDescriptors requires 1 args'
    sys.exit(1)
  pp.pprint(client.getColumnDescriptors(eval(args[0]),))

elif cmd == 'getTableRegions':
  if len(args) != 1:
    print 'getTableRegions requires 1 args'
    sys.exit(1)
  pp.pprint(client.getTableRegions(eval(args[0]),))

elif cmd == 'createTable':
  if len(args) != 2:
    print 'createTable requires 2 args'
    sys.exit(1)
  pp.pprint(client.createTable(eval(args[0]),eval(args[1]),))

elif cmd == 'deleteTable':
  if len(args) != 1:
    print 'deleteTable requires 1 args'
    sys.exit(1)
  pp.pprint(client.deleteTable(eval(args[0]),))

elif cmd == 'get':
  if len(args) != 4:
    print 'get requires 4 args'
    sys.exit(1)
  pp.pprint(client.get(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'getVer':
  if len(args) != 5:
    print 'getVer requires 5 args'
    sys.exit(1)
  pp.pprint(client.getVer(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'getVerTs':
  if len(args) != 6:
    print 'getVerTs requires 6 args'
    sys.exit(1)
  pp.pprint(client.getVerTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),eval(args[5]),))

elif cmd == 'getRow':
  if len(args) != 3:
    print 'getRow requires 3 args'
    sys.exit(1)
  pp.pprint(client.getRow(eval(args[0]),eval(args[1]),eval(args[2]),))

elif cmd == 'getRowWithColumns':
  if len(args) != 4:
    print 'getRowWithColumns requires 4 args'
    sys.exit(1)
  pp.pprint(client.getRowWithColumns(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'getRowTs':
  if len(args) != 4:
    print 'getRowTs requires 4 args'
    sys.exit(1)
  pp.pprint(client.getRowTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'getRowWithColumnsTs':
  if len(args) != 5:
    print 'getRowWithColumnsTs requires 5 args'
    sys.exit(1)
  pp.pprint(client.getRowWithColumnsTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'getRows':
  if len(args) != 3:
    print 'getRows requires 3 args'
    sys.exit(1)
  pp.pprint(client.getRows(eval(args[0]),eval(args[1]),eval(args[2]),))

elif cmd == 'getRowsWithColumns':
  if len(args) != 4:
    print 'getRowsWithColumns requires 4 args'
    sys.exit(1)
  pp.pprint(client.getRowsWithColumns(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'getRowsTs':
  if len(args) != 4:
    print 'getRowsTs requires 4 args'
    sys.exit(1)
  pp.pprint(client.getRowsTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'getRowsWithColumnsTs':
  if len(args) != 5:
    print 'getRowsWithColumnsTs requires 5 args'
    sys.exit(1)
  pp.pprint(client.getRowsWithColumnsTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'mutateRow':
  if len(args) != 4:
    print 'mutateRow requires 4 args'
    sys.exit(1)
  pp.pprint(client.mutateRow(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'mutateRowTs':
  if len(args) != 5:
    print 'mutateRowTs requires 5 args'
    sys.exit(1)
  pp.pprint(client.mutateRowTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'mutateRows':
  if len(args) != 3:
    print 'mutateRows requires 3 args'
    sys.exit(1)
  pp.pprint(client.mutateRows(eval(args[0]),eval(args[1]),eval(args[2]),))

elif cmd == 'mutateRowsTs':
  if len(args) != 4:
    print 'mutateRowsTs requires 4 args'
    sys.exit(1)
  pp.pprint(client.mutateRowsTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'atomicIncrement':
  if len(args) != 4:
    print 'atomicIncrement requires 4 args'
    sys.exit(1)
  pp.pprint(client.atomicIncrement(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'deleteAll':
  if len(args) != 4:
    print 'deleteAll requires 4 args'
    sys.exit(1)
  pp.pprint(client.deleteAll(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'deleteAllTs':
  if len(args) != 5:
    print 'deleteAllTs requires 5 args'
    sys.exit(1)
  pp.pprint(client.deleteAllTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'deleteAllRow':
  if len(args) != 3:
    print 'deleteAllRow requires 3 args'
    sys.exit(1)
  pp.pprint(client.deleteAllRow(eval(args[0]),eval(args[1]),eval(args[2]),))

elif cmd == 'increment':
  if len(args) != 1:
    print 'increment requires 1 args'
    sys.exit(1)
  pp.pprint(client.increment(eval(args[0]),))

elif cmd == 'incrementRows':
  if len(args) != 1:
    print 'incrementRows requires 1 args'
    sys.exit(1)
  pp.pprint(client.incrementRows(eval(args[0]),))

elif cmd == 'deleteAllRowTs':
  if len(args) != 4:
    print 'deleteAllRowTs requires 4 args'
    sys.exit(1)
  pp.pprint(client.deleteAllRowTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'scannerOpenWithScan':
  if len(args) != 3:
    print 'scannerOpenWithScan requires 3 args'
    sys.exit(1)
  pp.pprint(client.scannerOpenWithScan(eval(args[0]),eval(args[1]),eval(args[2]),))

elif cmd == 'scannerOpen':
  if len(args) != 4:
    print 'scannerOpen requires 4 args'
    sys.exit(1)
  pp.pprint(client.scannerOpen(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'scannerOpenWithStop':
  if len(args) != 5:
    print 'scannerOpenWithStop requires 5 args'
    sys.exit(1)
  pp.pprint(client.scannerOpenWithStop(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'scannerOpenWithPrefix':
  if len(args) != 4:
    print 'scannerOpenWithPrefix requires 4 args'
    sys.exit(1)
  pp.pprint(client.scannerOpenWithPrefix(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),))

elif cmd == 'scannerOpenTs':
  if len(args) != 5:
    print 'scannerOpenTs requires 5 args'
    sys.exit(1)
  pp.pprint(client.scannerOpenTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),))

elif cmd == 'scannerOpenWithStopTs':
  if len(args) != 6:
    print 'scannerOpenWithStopTs requires 6 args'
    sys.exit(1)
  pp.pprint(client.scannerOpenWithStopTs(eval(args[0]),eval(args[1]),eval(args[2]),eval(args[3]),eval(args[4]),eval(args[5]),))

elif cmd == 'scannerGet':
  if len(args) != 1:
    print 'scannerGet requires 1 args'
    sys.exit(1)
  pp.pprint(client.scannerGet(eval(args[0]),))

elif cmd == 'scannerGetList':
  if len(args) != 2:
    print 'scannerGetList requires 2 args'
    sys.exit(1)
  pp.pprint(client.scannerGetList(eval(args[0]),eval(args[1]),))

elif cmd == 'scannerClose':
  if len(args) != 1:
    print 'scannerClose requires 1 args'
    sys.exit(1)
  pp.pprint(client.scannerClose(eval(args[0]),))

elif cmd == 'getRowOrBefore':
  if len(args) != 3:
    print 'getRowOrBefore requires 3 args'
    sys.exit(1)
  pp.pprint(client.getRowOrBefore(eval(args[0]),eval(args[1]),eval(args[2]),))

elif cmd == 'getRegionInfo':
  if len(args) != 1:
    print 'getRegionInfo requires 1 args'
    sys.exit(1)
  pp.pprint(client.getRegionInfo(eval(args[0]),))

else:
  print 'Unrecognized method %s' % cmd
  sys.exit(1)

transport.close()
