<s> from kamaki . cli . config import Config <EOL> from kamaki . clients import astakos , pithos , ClientError <EOL> cnf = Config ( ) <EOL> CLOUD = cnf . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> URL = cnf . get_cloud ( CLOUD , '<STR_LIT:url>' ) <EOL> TOKEN = cnf . get_cloud ( CLOUD , '<STR_LIT>' ) <EOL> identity_client = astakos . AstakosClient ( URL , TOKEN ) <EOL> pithosURL = identity_client . get_endpoint_url ( pithos . PithosClient . service_type ) <EOL> storage_client = pithos . PithosClient ( pithosURL , TOKEN ) <EOL> storage_client . account = identity_client . user_info [ '<STR_LIT:id>' ] <EOL> storage_client . container = '<STR_LIT>' <EOL> obj = raw_input ( '<STR_LIT>' ) <EOL> destination = raw_input ( '<STR_LIT>' ) <EOL> obj_size = int ( storage_client . get_object_info ( obj ) [ '<STR_LIT>' ] ) <EOL> BLOCK_SIZE = int ( storage_client . get_container_info ( ) [ '<STR_LIT>' ] ) <EOL> CHUNK_SIZE = <NUM_LIT:4> * BLOCK_SIZE <EOL> def stream ( i , output ) : <EOL> """<STR_LIT>""" <EOL> output . write ( bufs [ i ] ) <EOL> from kamaki . clients import SilentEvent <EOL> with open ( destination , '<STR_LIT>' ) as output : <EOL> event = None <EOL> bufs = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for i in range ( <NUM_LIT:1> + ( obj_size / CHUNK_SIZE ) ) : <EOL> buf_index = i % <NUM_LIT:2> <EOL> start , end = CHUNK_SIZE * i , min ( CHUNK_SIZE * ( i + <NUM_LIT:1> ) , obj_size ) <EOL> bufs [ buf_index ] = storage_client . download_to_string ( <EOL> obj , range_str = '<STR_LIT>' % ( start , end ) ) <EOL> if event and not event . is_alive ( ) : <EOL> event . join ( ) <EOL> event = SilentEvent ( stream , buf_index , output ) <EOL> event . start ( ) </s>
