<s> from prettytable import PrettyTable , ALL <EOL> from boto . s3 . connection import OrdinaryCallingFormat <EOL> from boto . s3 . key import Key <EOL> from boto . s3 . acl import ACL , Grant <EOL> from boto . exception import S3ResponseError <EOL> from boto . s3 . deletemarker import DeleteMarker <EOL> from boto . s3 . bucket import Bucket , Key , DeleteMarker <EOL> import boto . s3 <EOL> from eutester import Eutester <EOL> import hashlib <EOL> import os <EOL> import time <EOL> class S3opsException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , msg ) : <EOL> self . msg = msg <EOL> def __str__ ( self ) : <EOL> print self . msg <EOL> class S3ops ( Eutester ) : <EOL> s3_groups = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> def __init__ ( self , endpoint = None , credpath = None , aws_access_key_id = None , aws_secret_access_key = None , is_secure = False , path = "<STR_LIT:/>" , port = <NUM_LIT> , boto_debug = <NUM_LIT:0> ) : <EOL> self . aws_access_key_id = aws_access_key_id <EOL> self . aws_secret_access_key = aws_secret_access_key <EOL> self . user_id = None <EOL> self . account_id = None <EOL> super ( S3ops , self ) . __init__ ( credpath = credpath ) <EOL> self . setup_s3_connection ( endpoint = endpoint , aws_access_key_id = self . aws_access_key_id , aws_secret_access_key = self . aws_secret_access_key , is_secure = is_secure , path = path , port = port , boto_debug = boto_debug ) <EOL> self . test_resources = { } <EOL> self . setup_s3_resource_trackers ( ) <EOL> def setup_s3_connection ( self , endpoint = None , aws_access_key_id = None , aws_secret_access_key = None , is_secure = False , path = "<STR_LIT:/>" , port = <NUM_LIT> , boto_debug = <NUM_LIT:0> ) : <EOL> try : <EOL> if not endpoint : <EOL> endpoint = self . get_s3_ip ( ) <EOL> s3_connection_args = { '<STR_LIT>' : aws_access_key_id , <EOL> '<STR_LIT>' : aws_secret_access_key , <EOL> '<STR_LIT>' : is_secure , <EOL> '<STR_LIT:host>' : endpoint , <EOL> '<STR_LIT:path>' : path , <EOL> '<STR_LIT:port>' : port , <EOL> '<STR_LIT>' : boto_debug , <EOL> '<STR_LIT>' : OrdinaryCallingFormat ( ) , <EOL> } <EOL> self . debug ( "<STR_LIT>" + endpoint + '<STR_LIT::>' + str ( port ) + path ) <EOL> self . s3 = boto . connect_s3 ( ** s3_connection_args ) <EOL> except Exception , e : <EOL> raise Exception ( "<STR_LIT>" + str ( e ) ) <EOL> def setup_s3_resource_trackers ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_resources [ "<STR_LIT>" ] = [ ] <EOL> self . test_resources [ "<STR_LIT>" ] = [ ] <EOL> def get_s3_ip ( self ) : <EOL> """<STR_LIT>""" <EOL> s3_url = self . parse_eucarc ( "<STR_LIT>" ) <EOL> return s3_url . split ( "<STR_LIT:/>" ) [ <NUM_LIT:2> ] . split ( "<STR_LIT::>" ) [ <NUM_LIT:0> ] <EOL> def get_s3_path ( self ) : <EOL> """<STR_LIT>""" <EOL> s3_url = self . parse_eucarc ( "<STR_LIT>" ) <EOL> s3_path = "<STR_LIT:/>" . join ( s3_url . split ( "<STR_LIT:/>" ) [ <NUM_LIT:3> : ] ) <EOL> return s3_path <EOL> def create_bucket ( self , bucket_name ) : <EOL> """<STR_LIT>""" <EOL> bucket = self . get_bucket_by_name ( bucket_name ) <EOL> if bucket : <EOL> self . debug ( '<STR_LIT>' % bucket_name ) <EOL> else : <EOL> try : <EOL> bucket = self . s3 . create_bucket ( bucket_name ) <EOL> except self . s3 . provider . storage_create_error , e : <EOL> raise S3opsException ( '<STR_LIT>' % bucket_name ) <EOL> def does_bucket_exist ( ) : <EOL> try : <EOL> self . s3 . get_bucket ( bucket_name ) <EOL> return True <EOL> except S3ResponseError : <EOL> return False <EOL> self . wait_for_result ( does_bucket_exist , True , timeout = <NUM_LIT> , poll_wait = <NUM_LIT:5> ) <EOL> self . debug ( "<STR_LIT>" + bucket_name ) <EOL> self . test_resources [ "<STR_LIT>" ] . append ( bucket ) <EOL> return bucket <EOL> def delete_bucket ( self , bucket ) : <EOL> """<STR_LIT>""" <EOL> bucket_name = bucket . name <EOL> try : <EOL> bucket . delete ( ) <EOL> except self . s3 . provider . storage_create_error , e : <EOL> raise S3opsException ( '<STR_LIT>' % bucket_name ) <EOL> def does_bucket_exist ( ) : <EOL> try : <EOL> self . s3 . get_bucket ( bucket_name ) <EOL> return True <EOL> except S3ResponseError : <EOL> return False <EOL> self . wait_for_result ( does_bucket_exist , False , timeout = <NUM_LIT> , poll_wait = <NUM_LIT:5> ) <EOL> def get_bucket_by_name ( self , bucket_name ) : <EOL> """<STR_LIT>""" <EOL> bucket = self . s3 . lookup ( bucket_name ) <EOL> if bucket : <EOL> return bucket <EOL> else : <EOL> return None <EOL> def upload_object ( self , bucket_name , key_name , path_to_file = None , contents = None ) : <EOL> """<STR_LIT>""" <EOL> bucket = self . get_bucket_by_name ( bucket_name ) <EOL> if bucket == None : <EOL> raise S3opsException ( "<STR_LIT>" + bucket_name + "<STR_LIT>" ) <EOL> key = bucket . new_key ( key_name ) <EOL> if key == None : <EOL> self . fail ( "<STR_LIT>" + key_name ) <EOL> if path_to_file is None : <EOL> if contents is None : <EOL> contents = os . urandom ( <NUM_LIT> ) <EOL> key . set_contents_from_string ( contents ) <EOL> else : <EOL> key . set_contents_from_filename ( path_to_file ) <EOL> self . debug ( "<STR_LIT>" + str ( key_name ) + "<STR_LIT>" + str ( bucket_name ) ) <EOL> self . test_resources [ "<STR_LIT>" ] . append ( key ) <EOL> return key <EOL> def get_objects_by_prefix ( self , bucket_name , prefix ) : <EOL> """<STR_LIT>""" <EOL> bucket = self . get_bucket_by_name ( bucket_name ) <EOL> keys = bucket . get_all_keys ( prefix = prefix ) <EOL> if len ( keys ) < <NUM_LIT:1> : <EOL> self . fail ( "<STR_LIT>" + prefix + "<STR_LIT>" + str ( bucket ) ) <EOL> if len ( keys ) == <NUM_LIT:2> : <EOL> return keys [ <NUM_LIT:0> ] <EOL> return keys <EOL> def delete_object ( self , object ) : <EOL> bucket = object . bucket <EOL> name = object . name <EOL> object . delete ( ) <EOL> try : <EOL> self . s3 . get_bucket ( bucket ) . get_key ( name ) <EOL> raise S3opsException ( "<STR_LIT>" + name + "<STR_LIT>" + bucket . name + "<STR_LIT>" ) <EOL> except Exception , e : <EOL> return <EOL> def clear_bucket ( self , bucket_name = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> bucket = self . s3 . get_bucket ( bucket_name = bucket_name ) <EOL> except S3ResponseError as e : <EOL> self . debug ( '<STR_LIT>' + bucket_name + '<STR_LIT>' + e . message ) <EOL> raise Exception ( '<STR_LIT>' ) <EOL> try : <EOL> self . debug ( "<STR_LIT>" + bucket . name ) <EOL> self . debug ( "<STR_LIT>" ) <EOL> key_list = bucket . list ( ) <EOL> self . debug ( "<STR_LIT>" ) <EOL> for k in key_list : <EOL> if isinstance ( k , boto . s3 . prefix . Prefix ) : <EOL> self . debug ( "<STR_LIT>" ) <EOL> continue <EOL> self . debug ( "<STR_LIT>" + k . name ) <EOL> bucket . delete_key ( k ) <EOL> bucket . delete ( ) <EOL> except S3ResponseError as e : <EOL> self . debug ( "<STR_LIT>" + e . message ) <EOL> if e . status == <NUM_LIT> : <EOL> self . debug ( "<STR_LIT>" ) <EOL> try : <EOL> keys = bucket . get_all_versions ( ) <EOL> for k in keys : <EOL> if isinstance ( k , Key ) : <EOL> self . debug ( "<STR_LIT>" + k . name + "<STR_LIT>" + k . version_id + "<STR_LIT>" + str ( k . delete_marker ) ) <EOL> self . debug ( "<STR_LIT>" + k . name ) <EOL> bucket . delete_key ( key_name = k . name , version_id = k . version_id ) <EOL> elif isinstance ( k , DeleteMarker ) : <EOL> self . debug ( "<STR_LIT>" + k . name + "<STR_LIT>" + k . version_id + "<STR_LIT>" + str ( k . is_latest ) ) <EOL> self . debug ( "<STR_LIT>" ) <EOL> bucket . delete_key ( key_name = k . name , version_id = k . version_id ) <EOL> self . debug ( "<STR_LIT>" + bucket . name ) <EOL> bucket . delete ( ) <EOL> except Exception as e : <EOL> self . debug ( "<STR_LIT>" + e . message ) <EOL> else : <EOL> self . debug ( '<STR_LIT>' + e . message + '<STR_LIT>' + str ( e . status ) ) <EOL> def clear_keys_with_prefix ( self , bucket , prefix ) : <EOL> try : <EOL> listing = self . walrus . get_all_buckets ( ) <EOL> for bucket in listing : <EOL> if bucket . name . startswith ( prefix ) : <EOL> self . debug ( "<STR_LIT>" + bucket . name ) <EOL> key_list = bucket . list ( ) <EOL> for k in key_list : <EOL> if isinstance ( k , boto . s3 . prefix . Prefix ) : <EOL> self . debug ( "<STR_LIT>" ) <EOL> continue <EOL> self . debug ( "<STR_LIT>" + k . name ) <EOL> bucket . delete_key ( k ) <EOL> bucket . delete ( ) <EOL> else : <EOL> self . debug ( "<STR_LIT>" + bucket . name ) <EOL> except S3ResponseError as e : <EOL> raise S3opsException ( "<STR_LIT>" ) <EOL> def get_canned_acl ( self , canned_acl = None , bucket_owner_id = None , bucket_owner_display_name = None ) : <EOL> '''<STR_LIT>''' <EOL> if bucket_owner_id == None or canned_acl == None or bucket_owner_display_name == None : <EOL> raise S3opsException ( "<STR_LIT>" ) <EOL> built_acl = ACL ( ) <EOL> built_acl . add_user_grant ( permission = '<STR_LIT>' , user_id = bucket_owner_id , display_name = bucket_owner_display_name ) <EOL> if canned_acl == "<STR_LIT>" : <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , type = '<STR_LIT>' , uri = self . s3_groups [ "<STR_LIT>" ] ) ) <EOL> elif canned_acl == "<STR_LIT>" : <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , type = '<STR_LIT>' , uri = self . s3_groups [ "<STR_LIT>" ] ) ) <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , type = '<STR_LIT>' , uri = self . s3_groups [ "<STR_LIT>" ] ) ) <EOL> elif canned_acl == "<STR_LIT>" : <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , type = '<STR_LIT>' , uri = self . s3_groups [ "<STR_LIT>" ] ) ) <EOL> elif canned_acl == "<STR_LIT>" : <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , type = '<STR_LIT>' , uri = self . s3_groups [ "<STR_LIT>" ] ) ) <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , type = '<STR_LIT>' , uri = self . s3_groups [ "<STR_LIT>" ] ) ) <EOL> elif canned_acl == "<STR_LIT>" : <EOL> if bucket_owner_id is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , id = bucket_owner_id ) ) <EOL> elif canned_acl == "<STR_LIT>" : <EOL> if bucket_owner_id is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> built_acl . add_grant ( Grant ( permission = "<STR_LIT>" , id = bucket_owner_id ) ) <EOL> return built_acl <EOL> def check_acl_equivalence ( self , acl1 = None , acl2 = None ) : <EOL> '''<STR_LIT>''' <EOL> if acl1 == None or acl2 == None : <EOL> return None <EOL> acl1grants = set ( ) <EOL> acl2grants = set ( ) <EOL> for val in acl1 . grants : <EOL> acl1grants . add ( val . to_xml ( ) ) <EOL> for val in acl2 . grants : <EOL> acl2grants . add ( val . to_xml ( ) ) <EOL> return not len ( acl1grants . symmetric_difference ( acl2grants ) ) > <NUM_LIT:0> <EOL> def check_md5 ( self , eTag = None , data = None ) : <EOL> hasher = hashlib . md5 ( ) <EOL> hasher . update ( data ) <EOL> data_hash = "<STR_LIT>" + hasher . hexdigest ( ) + "<STR_LIT>" <EOL> if data_hash != eTag : <EOL> raise Exception ( "<STR_LIT>" + data_hash + "<STR_LIT>" + eTag ) <EOL> def show_bucket_summary ( self , bucket , showkeys = True , format_size = True , <EOL> force_refresh = False , printme = True ) : <EOL> if isinstance ( bucket , str ) : <EOL> bucket = self . get_bucket_by_name ( bucket ) <EOL> if not bucket : <EOL> raise ValueError ( '<STR_LIT>' . format ( bucket ) ) <EOL> if not isinstance ( bucket , Bucket ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> . format ( bucket , type ( bucket ) ) ) <EOL> ret_table = None <EOL> kb = <NUM_LIT:1000> <EOL> mb = <NUM_LIT> <EOL> gb = <NUM_LIT> <EOL> DELETED = self . markup ( "<STR_LIT>" , [ <NUM_LIT:1> , <NUM_LIT> ] ) <EOL> def get_size_string ( bytes ) : <EOL> if not format_size or bytes == DELETED : <EOL> return str ( bytes ) <EOL> if bytes < kb : <EOL> ret_bytes = "<STR_LIT>" . format ( bytes ) <EOL> elif bytes < mb : <EOL> ret_bytes = "<STR_LIT>" . format ( round ( float ( bytes / float ( kb ) ) , <NUM_LIT:2> ) ) <EOL> elif bytes < gb : <EOL> ret_bytes = "<STR_LIT>" . format ( round ( float ( bytes / float ( mb ) ) , <NUM_LIT:2> ) ) <EOL> else : <EOL> ret_bytes = "<STR_LIT>" . format ( round ( float ( bytes / float ( gb ) ) , <NUM_LIT:2> ) ) <EOL> return ret_bytes <EOL> bk_name_col = ( '<STR_LIT>' , <NUM_LIT:64> ) <EOL> bk_ver_col = ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> bk_keys_col = ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> bk_size_col = ( '<STR_LIT>' , <NUM_LIT:16> ) <EOL> key_name_col = ( '<STR_LIT>' , <NUM_LIT> ) <EOL> key_size_col = ( '<STR_LIT>' , <NUM_LIT:12> ) <EOL> key_ver_col = ( '<STR_LIT>' , <NUM_LIT> ) <EOL> key_mod_col = ( '<STR_LIT>' , <NUM_LIT> ) <EOL> bucket_pt = PrettyTable ( [ self . markup ( bk_name_col [ <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:4> ] ) , self . markup ( bk_ver_col [ <NUM_LIT:0> ] ) , <EOL> self . markup ( bk_keys_col [ <NUM_LIT:0> ] ) , self . markup ( bk_size_col [ <NUM_LIT:0> ] ) ] ) <EOL> bucket_pt . max_width [ bk_name_col [ <NUM_LIT:0> ] ] = bk_name_col [ <NUM_LIT:1> ] <EOL> bucket_pt . max_width [ bk_ver_col [ <NUM_LIT:0> ] ] = bk_ver_col [ <NUM_LIT:1> ] <EOL> bucket_pt . max_width [ bk_keys_col [ <NUM_LIT:0> ] ] = bk_keys_col [ <NUM_LIT:1> ] <EOL> bucket_pt . max_width [ bk_size_col [ <NUM_LIT:0> ] ] = bk_size_col [ <NUM_LIT:1> ] <EOL> if showkeys : <EOL> bucket_pt . align [ bk_name_col [ <NUM_LIT:0> ] ] = '<STR_LIT:c>' <EOL> else : <EOL> bucket_pt . align [ bk_name_col [ <NUM_LIT:0> ] ] = '<STR_LIT:l>' <EOL> bucket_pt . align [ bk_size_col [ <NUM_LIT:0> ] ] = '<STR_LIT:r>' <EOL> bucket_pt . align [ bk_keys_col [ <NUM_LIT:0> ] ] = '<STR_LIT:l>' <EOL> bucket_pt . align [ bk_ver_col [ <NUM_LIT:0> ] ] = '<STR_LIT:l>' <EOL> bucket_pt . right_padding_width = <NUM_LIT:0> <EOL> bucket_pt . left_padding_width = <NUM_LIT:1> <EOL> if showkeys : <EOL> key_pt = PrettyTable ( [ self . markup ( key_name_col [ <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:4> ] ) , self . markup ( key_size_col [ <NUM_LIT:0> ] ) , <EOL> self . markup ( key_ver_col [ <NUM_LIT:0> ] ) , self . markup ( key_mod_col [ <NUM_LIT:0> ] ) ] ) <EOL> key_pt . max_width [ key_ver_col [ <NUM_LIT:0> ] ] = key_ver_col [ <NUM_LIT:1> ] <EOL> key_pt . max_width [ key_name_col [ <NUM_LIT:0> ] ] = key_name_col [ <NUM_LIT:1> ] <EOL> key_pt . max_width [ key_size_col [ <NUM_LIT:0> ] ] = key_size_col [ <NUM_LIT:1> ] <EOL> key_pt . max_width [ key_mod_col [ <NUM_LIT:0> ] ] = key_mod_col [ <NUM_LIT:1> ] <EOL> key_pt . hrules = ALL <EOL> key_pt . align [ key_ver_col [ <NUM_LIT:0> ] ] = '<STR_LIT:l>' <EOL> key_pt . align [ key_name_col [ <NUM_LIT:0> ] ] = '<STR_LIT:l>' <EOL> key_pt . align [ key_size_col [ <NUM_LIT:0> ] ] = '<STR_LIT:r>' <EOL> key_pt . align [ key_mod_col [ <NUM_LIT:0> ] ] = '<STR_LIT:c>' <EOL> key_pt . right_padding_width = <NUM_LIT:0> <EOL> key_pt . left_padding_width = <NUM_LIT:1> <EOL> else : <EOL> key_pt = None <EOL> total_size = <NUM_LIT:0> <EOL> total_keys = <NUM_LIT:0> <EOL> last_key = None <EOL> last_key_sizes = [ ] <EOL> last_key_versions = [ ] <EOL> last_key_mods = [ ] <EOL> last_key_del_marker = None <EOL> last_written = None <EOL> def add_last_key_info_to_table ( ) : <EOL> if last_key_del_marker : <EOL> last_key_versions . insert ( <NUM_LIT:0> , self . markup ( last_key_del_marker . version_id , <EOL> [ <NUM_LIT:1> , <NUM_LIT> ] ) ) <EOL> last_key_sizes . insert ( <NUM_LIT:0> , DELETED ) <EOL> last_key_mods . insert ( <NUM_LIT:0> , self . markup ( last_key_del_marker . last_modified , <EOL> [ <NUM_LIT:1> , <NUM_LIT> ] ) ) <EOL> keyname = str ( self . markup ( '<STR_LIT>' + last_key . name , [ <NUM_LIT:1> , <NUM_LIT> ] ) ) . ljust ( key_name_col [ <NUM_LIT:1> ] ) <EOL> else : <EOL> keyname = str ( self . markup ( '<STR_LIT>' + last_key . name ) ) . ljust ( key_name_col [ <NUM_LIT:1> ] ) <EOL> ver_string = ( "<STR_LIT:\n>" . join ( '<STR_LIT>' . format ( x ) . ljust ( key_ver_col [ <NUM_LIT:1> ] ) for x in <EOL> last_key_versions ) ) <EOL> size_string = ( "<STR_LIT:\n>" . join ( '<STR_LIT>' . format ( get_size_string ( x ) ) . rjust ( key_size_col [ <NUM_LIT:1> ] ) <EOL> for x in last_key_sizes ) ) <EOL> mod_string = ( "<STR_LIT:\n>" . join ( '<STR_LIT>' . format ( x ) . center ( key_mod_col [ <NUM_LIT:1> ] ) <EOL> for x in last_key_mods ) ) <EOL> key_pt . add_row ( [ <EOL> keyname , <EOL> str ( size_string ) . ljust ( key_size_col [ <NUM_LIT:1> ] ) , <EOL> ver_string , <EOL> mod_string ] ) <EOL> for key in bucket . list_versions ( ) : <EOL> if isinstance ( key , DeleteMarker ) : <EOL> current_ver = None <EOL> current_size = None <EOL> current_name = key . name <EOL> current_del_marker = key <EOL> else : <EOL> current_ver = key . version_id <EOL> current_size = key . size <EOL> current_name = key . name <EOL> current_del_marker = None <EOL> total_size += current_size <EOL> total_keys += <NUM_LIT:1> <EOL> if last_key and last_key . name != current_name : <EOL> if key_pt : <EOL> add_last_key_info_to_table ( ) <EOL> last_written = last_key <EOL> last_key = key <EOL> if current_size is None : <EOL> last_key_sizes = [ ] <EOL> else : <EOL> last_key_sizes = [ current_size ] <EOL> if current_ver : <EOL> last_key_versions = [ current_ver ] <EOL> else : <EOL> last_key_versions = [ ] <EOL> if not isinstance ( key , DeleteMarker ) : <EOL> last_key_mods = [ key . last_modified ] <EOL> else : <EOL> last_key_mods = [ ] <EOL> last_key_del_marker = current_del_marker <EOL> else : <EOL> if current_size is not None : <EOL> last_key_sizes . append ( current_size ) <EOL> if current_ver : <EOL> last_key_versions . append ( current_ver ) <EOL> last_key = key <EOL> last_key_del_marker = last_key_del_marker or current_del_marker <EOL> if not isinstance ( key , DeleteMarker ) : <EOL> last_key_mods . append ( key . last_modified ) <EOL> if last_key != last_written : <EOL> if key_pt : <EOL> add_last_key_info_to_table ( ) <EOL> version_enabled = bool ( '<STR_LIT>' == bucket . get_versioning_status ( ) . get ( '<STR_LIT>' ) ) <EOL> if showkeys : <EOL> bucket_name = str ( self . markup ( bucket . name , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> ] ) ) . center ( bk_name_col [ <NUM_LIT:1> ] ) <EOL> else : <EOL> bucket_name = str ( self . markup ( bucket . name , [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> ] ) ) . ljust ( bk_name_col [ <NUM_LIT:1> ] ) <EOL> bucket_pt . add_row ( [ bucket_name , <EOL> str ( version_enabled ) . ljust ( bk_ver_col [ <NUM_LIT:1> ] ) , <EOL> str ( total_keys ) . ljust ( bk_keys_col [ <NUM_LIT:1> ] ) , <EOL> str ( get_size_string ( total_size ) ) . rjust ( bk_size_col [ <NUM_LIT:1> ] ) ] ) <EOL> if not showkeys : <EOL> ret_table = bucket_pt <EOL> else : <EOL> main_pt = PrettyTable ( [ "<STR_LIT>" ] ) <EOL> main_pt . header = False <EOL> main_pt . align = '<STR_LIT:l>' <EOL> main_pt . add_row ( [ str ( bucket_pt ) ] ) <EOL> main_pt . add_row ( [ str ( key_pt ) ] ) <EOL> ret_table = main_pt <EOL> if printme : <EOL> self . debug ( "<STR_LIT>" . format ( ret_table ) ) <EOL> else : <EOL> return ret_table <EOL> def show_buckets ( self , buckets = None , format_size = True , printme = True ) : <EOL> if not buckets : <EOL> buckets = self . s3 . get_all_buckets ( ) <EOL> elif isinstance ( buckets , str ) or isinstance ( buckets , unicode ) : <EOL> buckets = self . get_bucket_by_name ( str ( buckets ) ) <EOL> if isinstance ( buckets , Bucket ) : <EOL> buckets = [ buckets ] <EOL> if not isinstance ( buckets , list ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( buckets , type ( buckets ) ) ) <EOL> first = buckets . pop ( <NUM_LIT:0> ) <EOL> main_table = self . show_bucket_summary ( bucket = first , showkeys = False , <EOL> format_size = format_size , printme = False ) <EOL> main_table . hrules = ALL <EOL> main_table . vrules = ALL <EOL> for field in main_table . field_names : <EOL> main_table . align [ field ] = '<STR_LIT:l>' <EOL> for bucket in buckets : <EOL> bucket_table = self . show_bucket_summary ( bucket = bucket , showkeys = False , <EOL> format_size = format_size , printme = False ) <EOL> if hasattr ( bucket_table , '<STR_LIT>' ) and bucket_table . _rows : <EOL> main_table . add_row ( bucket_table . _rows [ <NUM_LIT:0> ] ) <EOL> if printme : <EOL> self . debug ( "<STR_LIT>" . format ( str ( main_table ) ) ) <EOL> else : <EOL> return main_table </s>
