<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import logging <EOL> import pprint <EOL> import sys <EOL> from functools import partial <EOL> from tornado import options <EOL> from viewfinder . backend . base import main <EOL> from viewfinder . backend . db import db_client , db_import , vf_schema <EOL> from viewfinder . backend . db . tools . util import AttrParser <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> options . define ( '<STR_LIT>' , default = None , multiple = True , help = '<STR_LIT>' ) <EOL> def QueryRange ( client , table , cls , key , range_desc , callback ) : <EOL> """<STR_LIT>""" <EOL> def _OnQuery ( retry_cb , count , items ) : <EOL> for item in items : <EOL> pprint . pprint ( item ) <EOL> if len ( items ) == <NUM_LIT:100> : <EOL> retry_cb ( items [ - <NUM_LIT:1> ] . GetKey ( ) , count + len ( items ) ) <EOL> else : <EOL> return callback ( '<STR_LIT>' % count ) <EOL> def _Query ( last_key = None , count = <NUM_LIT:0> ) : <EOL> cls . RangeQuery ( client , key . hash_key , range_desc , limit = <NUM_LIT:100> , <EOL> col_names = ( options . options . col_names or None ) , <EOL> callback = partial ( _OnQuery , _Query , count ) , <EOL> excl_start_key = last_key ) <EOL> _Query ( ) <EOL> def RunDBA ( callback ) : <EOL> """<STR_LIT>""" <EOL> client = db_client . DBClient . Instance ( ) <EOL> op = options . options . op <EOL> table = None <EOL> if options . options . table : <EOL> table = vf_schema . SCHEMA . GetTable ( options . options . table ) <EOL> assert table , '<STR_LIT>' % options . options . table <EOL> cls = db_import . GetTableClass ( table . name ) <EOL> key = None <EOL> if options . options . hash_key and options . options . range_key : <EOL> assert table . range_key_col <EOL> key = db_client . DBKey ( eval ( options . options . hash_key ) , eval ( options . options . range_key ) ) <EOL> elif options . options . hash_key : <EOL> assert not table . range_key_col <EOL> key = db_client . DBKey ( eval ( options . options . hash_key ) , None ) <EOL> start_key = eval ( options . options . start_key ) if options . options . start_key else None <EOL> end_key = eval ( options . options . end_key ) if options . options . end_key else None <EOL> range_desc = None <EOL> if start_key and end_key : <EOL> range_desc = db_client . RangeOperator ( [ start_key , end_key ] , '<STR_LIT>' ) <EOL> elif start_key : <EOL> range_desc = db_client . RangeOperator ( [ start_key ] , '<STR_LIT>' ) <EOL> elif end_key : <EOL> range_desc = db_client . RangeOperator ( [ end_key ] , '<STR_LIT>' ) <EOL> user_id = None <EOL> if options . options . user_id : <EOL> user_id = eval ( options . options . user_id ) <EOL> limit = None <EOL> if options . options . limit : <EOL> limit = eval ( options . options . limit ) <EOL> if options . options . attributes : <EOL> parser = AttrParser ( table ) <EOL> attrs = parser . Run ( options . options . attributes ) <EOL> if table and key : <EOL> attrs [ table . hash_key_col . name ] = key . hash_key <EOL> if key . range_key : <EOL> attrs [ table . range_key_col . name ] = key . range_key <EOL> logging . info ( '<STR_LIT>' % attrs ) <EOL> def _OnOp ( * args , ** kwargs ) : <EOL> if args : <EOL> logging . info ( '<STR_LIT>' % pprint . pformat ( args ) ) <EOL> if kwargs : <EOL> logging . info ( '<STR_LIT>' % pprint . pformat ( kwargs ) ) <EOL> callback ( ) <EOL> if op in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> assert table , '<STR_LIT>' <EOL> if op in ( '<STR_LIT>' ) : <EOL> assert table . range_key_col , '<STR_LIT>' % table . name <EOL> logging . info ( '<STR_LIT>' % op ) <EOL> if op == '<STR_LIT>' : <EOL> QueryRange ( client , table , cls , key , range_desc , _OnOp ) <EOL> elif op == '<STR_LIT>' : <EOL> o = cls ( ) <EOL> o . UpdateFromKeywords ( ** attrs ) <EOL> o . Update ( client , _OnOp ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' % op ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main . InitAndRun ( RunDBA ) ) </s>
