<s> import argparse <EOL> import cStringIO <EOL> import errno <EOL> import json <EOL> import logging <EOL> import os . path <EOL> import pkg_resources <EOL> import shutil <EOL> import time <EOL> import boto <EOL> from boto . s3 import key <EOL> from cassback import dt_util , file_util <EOL> def create_from_args ( args ) : <EOL> endpoint_name = args . endpoint <EOL> for entry_point in pkg_resources . iter_entry_points ( "<STR_LIT>" ) : <EOL> endpoint_class = entry_point . load ( ) <EOL> if endpoint_class . name == endpoint_name : <EOL> return endpoint_class ( args ) <EOL> raise RuntimeError ( "<STR_LIT>" % ( endpoint_name , ) ) <EOL> def validate_args ( args ) : <EOL> endpoint_name = args . endpoint <EOL> for entry_point in pkg_resources . iter_entry_points ( "<STR_LIT>" ) : <EOL> endpoint_class = entry_point . load ( ) <EOL> if endpoint_class . name == endpoint_name : <EOL> endpoint_class . validate_args ( args ) <EOL> return <EOL> raise RuntimeError ( "<STR_LIT>" % ( endpoint_name , ) ) <EOL> class EndpointBase ( object ) : <EOL> """<STR_LIT>""" <EOL> name = None <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def add_arg_group ( cls , main_parser ) : <EOL> """<STR_LIT:U+0020>""" <EOL> pass <EOL> @ classmethod <EOL> def validate_args ( cls , args ) : <EOL> pass <EOL> def backup_file ( self , backup_file ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def read_backup_file ( self , path ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def backup_keyspace ( self , ks_backup ) : <EOL> raise NotImplementedError ( ) <EOL> def read_keyspace ( self , path ) : <EOL> raise NotImplementedError ( ) <EOL> def restore_file ( self , backup_file , dest_prefix ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def exists ( self , relative_path ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def validate_checksum ( self , relative_path , expected_md5_hex ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def iter_dir ( self , relative_path , include_files = True , <EOL> include_dirs = False , recursive = False ) : <EOL> raise NotImplementedError ( ) <EOL> def remove_file ( self , relative_path , dry_run = False ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def remove_file_with_meta ( self , relative_path , dry_run ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> class TransferTiming ( object ) : <EOL> def __init__ ( self , logger , path , size ) : <EOL> self . log = logger <EOL> self . path = path <EOL> self . start_ms = int ( time . time ( ) * <NUM_LIT:1000> ) <EOL> self . size = size <EOL> mb = <NUM_LIT> ** <NUM_LIT:2> <EOL> pattern = [ <EOL> ( <NUM_LIT:1> * mb , <NUM_LIT:0> ) , <EOL> ( <NUM_LIT:10> * mb , <NUM_LIT:1> ) , <EOL> ( <NUM_LIT:100> * mb , <NUM_LIT:2> ) , <EOL> ( <NUM_LIT> * mb , <NUM_LIT:5> ) , <EOL> ( <NUM_LIT:10> * <NUM_LIT> * mb , <NUM_LIT:10> ) , <EOL> ] <EOL> self . num_callbacks = <NUM_LIT:20> <EOL> for i , j in pattern : <EOL> if self . size < i : <EOL> self . num_callbacks = j <EOL> break <EOL> def progress ( self , progress , total ) : <EOL> """<STR_LIT>""" <EOL> path = self . path <EOL> elapsed_ms = int ( time . time ( ) * <NUM_LIT:1000> ) - self . start_ms <EOL> throughput = ( ( progress * <NUM_LIT:1.0> ) / ( <NUM_LIT> ** <NUM_LIT:2> ) ) / ( ( elapsed_ms / <NUM_LIT:1000> ) or <NUM_LIT:1> ) <EOL> if progress == total : <EOL> pattern = "<STR_LIT>" "<STR_LIT>" <EOL> else : <EOL> pattern = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> self . log . info ( pattern . format ( ** vars ( ) ) ) <EOL> return <EOL> def __enter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_value , traceback ) : <EOL> if exc_value is not None : <EOL> return False <EOL> self . progress ( self . size , self . size ) <EOL> return False </s>
