<s> from __future__ import print_function <EOL> import aerospike <EOL> import re <EOL> import sys <EOL> import os . path <EOL> from optparse import OptionParser <EOL> from aerospike import predicates as p <EOL> usage = "<STR_LIT>" <EOL> optparser = OptionParser ( usage = usage , add_help_option = False ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:username>" , type = "<STR_LIT:string>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:password>" , type = "<STR_LIT:string>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:host>" , type = "<STR_LIT:string>" , default = "<STR_LIT:127.0.0.1>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:port>" , type = "<STR_LIT:int>" , default = <NUM_LIT> , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , default = "<STR_LIT:test>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , default = "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> optparser . add_option ( <EOL> "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> ( options , args ) = optparser . parse_args ( ) <EOL> if options . help : <EOL> optparser . print_help ( ) <EOL> print ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> optparser . print_help ( ) <EOL> print ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> config = { <EOL> '<STR_LIT>' : [ ( options . host , options . port ) ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : os . path . dirname ( __file__ ) <EOL> } <EOL> } <EOL> exitCode = <NUM_LIT:0> <EOL> try : <EOL> client = aerospike . client ( config ) . connect ( <EOL> options . username , options . password ) <EOL> try : <EOL> re_bin = "<STR_LIT>" <EOL> re_str_eq = "<STR_LIT>" <EOL> re_int_eq = "<STR_LIT>" <EOL> re_int_rg = "<STR_LIT>" <EOL> re_w = re . compile ( "<STR_LIT>" % <EOL> ( re_bin , re_str_eq , re_int_eq , re_int_rg ) ) <EOL> namespace = options . namespace if options . namespace and options . namespace != '<STR_LIT:None>' else None <EOL> set = options . set if options . set and options . set != '<STR_LIT:None>' else None <EOL> q = None <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> w = re_w . match ( args [ <NUM_LIT:0> ] ) <EOL> if w is not None : <EOL> q = client . query ( namespace , set ) <EOL> if w . group ( <NUM_LIT:2> ) : <EOL> b = w . group ( <NUM_LIT:1> ) <EOL> v = w . group ( <NUM_LIT:2> ) <EOL> q . where ( p . equals ( b , v ) ) <EOL> elif w . group ( <NUM_LIT:3> ) : <EOL> b = w . group ( <NUM_LIT:1> ) <EOL> v = w . group ( <NUM_LIT:3> ) <EOL> q . where ( p . equals ( b , v ) ) <EOL> elif w . group ( <NUM_LIT:4> ) : <EOL> b = w . group ( <NUM_LIT:1> ) <EOL> v = int ( w . group ( <NUM_LIT:4> ) ) <EOL> q . where ( p . equals ( b , v ) ) <EOL> elif w . group ( <NUM_LIT:5> ) and w . group ( <NUM_LIT:6> ) : <EOL> b = w . group ( <NUM_LIT:1> ) <EOL> l = int ( w . group ( <NUM_LIT:5> ) ) <EOL> u = int ( w . group ( <NUM_LIT:6> ) ) <EOL> q . where ( p . between ( b , l , u ) ) <EOL> if q is None : <EOL> q = client . scan ( namespace , set ) <EOL> if options . bins and len ( options . bins ) > <NUM_LIT:0> : <EOL> q . select ( * options . bins ) <EOL> if options . module and options . function : <EOL> if options . arguments : <EOL> q . apply ( options . module , options . function , * options . arguments ) <EOL> else : <EOL> q . apply ( options . module , options . function ) <EOL> results = [ ] <EOL> def callback ( input_tuple ) : <EOL> ( key , meta , rec ) = input_tuple <EOL> results . append ( ( key , meta , rec ) ) <EOL> if options . show_key and options . show_meta : <EOL> print ( key , meta , rec ) <EOL> elif options . show_key : <EOL> print ( key , rec ) <EOL> elif options . show_meta : <EOL> print ( meta , rec ) <EOL> else : <EOL> print ( rec ) <EOL> q . foreach ( callback ) <EOL> print ( "<STR_LIT>" ) <EOL> if len ( results ) == <NUM_LIT:1> : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" % len ( results ) ) <EOL> except Exception as eargs : <EOL> print ( "<STR_LIT>" . format ( eargs ) , file = sys . stderr ) <EOL> exitCode = <NUM_LIT:2> <EOL> client . close ( ) <EOL> except Exception as eargs : <EOL> print ( "<STR_LIT>" . format ( eargs ) , file = sys . stderr ) <EOL> exitCode = <NUM_LIT:3> <EOL> sys . exit ( exitCode ) </s>
