<s> import abc <EOL> from cloudferry . lib . utils import files <EOL> from cloudferry . lib . utils import remote_runner <EOL> from cloudferry . lib . copy_engines import base <EOL> class CopyFailed ( RuntimeError ) : <EOL> pass <EOL> class CopyMechanism ( object ) : <EOL> __metaclass__ = abc . ABCMeta <EOL> @ abc . abstractmethod <EOL> def copy ( self , context , source_object , destination_object ) : <EOL> raise NotImplementedError ( ) <EOL> class CopyObject ( object ) : <EOL> def __init__ ( self , host = None , path = None ) : <EOL> self . host = host <EOL> self . path = path <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( host = self . host , path = self . path ) <EOL> class RemoteFileCopy ( CopyMechanism ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self , context , source_object , destination_object ) : <EOL> data = { <EOL> '<STR_LIT>' : source_object . host , <EOL> '<STR_LIT>' : source_object . path , <EOL> '<STR_LIT>' : destination_object . host , <EOL> '<STR_LIT>' : destination_object . path <EOL> } <EOL> try : <EOL> copier = base . get_copier ( context . src_cloud , <EOL> context . dst_cloud , <EOL> data ) <EOL> copier . transfer ( data ) <EOL> except ( base . FileCopyError , <EOL> base . CopierCannotBeUsed , <EOL> base . CopierNotFound ) as e : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> src_host = source_object . host , <EOL> src_file = source_object . path , <EOL> dst_host = destination_object . host , <EOL> dst_file = destination_object . path , <EOL> err = e . message ) <EOL> raise CopyFailed ( msg ) <EOL> class CopyRegularFileToBlockDevice ( CopyMechanism ) : <EOL> """<STR_LIT>""" <EOL> def copy ( self , context , source_object , destination_object ) : <EOL> src_user = context . cfg . src . ssh_user <EOL> dst_user = context . cfg . dst . ssh_user <EOL> src_host = source_object . host <EOL> dst_host = destination_object . host <EOL> rr = remote_runner . RemoteRunner ( src_host , src_user ) <EOL> ssh_opts = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> try : <EOL> progress_view = "<STR_LIT>" <EOL> if files . is_installed ( rr , "<STR_LIT>" ) : <EOL> src_file_size = files . remote_file_size ( rr , source_object . path ) <EOL> progress_view = "<STR_LIT>" . format ( <EOL> size = src_file_size ) <EOL> copy = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> rr . run ( copy . format ( src_file = source_object . path , <EOL> dst_user = dst_user , <EOL> dst_host = dst_host , <EOL> ssh_opts = ssh_opts , <EOL> dst_device = destination_object . path , <EOL> progress_view = progress_view ) ) <EOL> except remote_runner . RemoteExecutionError as e : <EOL> msg = "<STR_LIT>" <EOL> msg = msg . format ( src_object = source_object , <EOL> dst_object = destination_object , <EOL> error = e . message ) <EOL> raise CopyFailed ( msg ) </s>
