<s> '''<STR_LIT>''' <EOL> from __future__ import print_function , unicode_literals , division , absolute_import <EOL> import dxpy <EOL> import requests <EOL> from . . utils . resolver import ( resolve_existing_path , resolve_path , is_hashid , get_last_pos_of_char ) <EOL> from . . exceptions import ( err_exit , DXCLIError ) <EOL> from . import try_call <EOL> from dxpy . utils . printing import ( fill ) <EOL> def cp_to_noexistent_destination ( args , dest_path , dx_dest , dest_proj ) : <EOL> '''<STR_LIT>''' <EOL> if len ( args . sources ) != <NUM_LIT:1> : <EOL> raise DXCLIError ( '<STR_LIT>' ) <EOL> last_slash_pos = get_last_pos_of_char ( '<STR_LIT:/>' , dest_path ) <EOL> if last_slash_pos == <NUM_LIT:0> : <EOL> dest_folder = '<STR_LIT:/>' <EOL> else : <EOL> dest_folder = dest_path [ : last_slash_pos ] <EOL> dest_name = dest_path [ last_slash_pos + <NUM_LIT:1> : ] . replace ( '<STR_LIT>' , '<STR_LIT:/>' ) <EOL> try : <EOL> dx_dest . list_folder ( folder = dest_folder , only = '<STR_LIT>' ) <EOL> except dxpy . DXAPIError as details : <EOL> if details . code == requests . codes [ '<STR_LIT>' ] : <EOL> raise DXCLIError ( '<STR_LIT>' ) <EOL> else : <EOL> raise <EOL> except : <EOL> err_exit ( ) <EOL> src_proj , src_path , src_results = try_call ( resolve_existing_path , <EOL> args . sources [ <NUM_LIT:0> ] , <EOL> allow_mult = True , all_mult = args . all ) <EOL> if src_proj == dest_proj : <EOL> if is_hashid ( args . sources [ <NUM_LIT:0> ] ) : <EOL> raise DXCLIError ( fill ( '<STR_LIT>' + args . sources [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> raise DXCLIError ( fill ( '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' ) + <EOL> '<STR_LIT>' ) <EOL> if src_results is None : <EOL> try : <EOL> contents = dxpy . api . project_list_folder ( src_proj , <EOL> { "<STR_LIT>" : src_path , "<STR_LIT>" : True } ) <EOL> dxpy . api . project_new_folder ( dest_proj , { "<STR_LIT>" : dest_path } ) <EOL> exists = dxpy . api . project_clone ( src_proj , <EOL> { "<STR_LIT>" : contents [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : [ result [ '<STR_LIT:id>' ] for result in contents [ '<STR_LIT>' ] ] , <EOL> "<STR_LIT>" : dest_proj , <EOL> "<STR_LIT>" : dest_path } ) [ '<STR_LIT>' ] <EOL> if len ( exists ) > <NUM_LIT:0> : <EOL> print ( fill ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) + '<STR_LIT>' + '<STR_LIT>' . join ( exists ) ) <EOL> return <EOL> except : <EOL> err_exit ( ) <EOL> else : <EOL> try : <EOL> exists = dxpy . api . project_clone ( src_proj , <EOL> { "<STR_LIT>" : [ result [ '<STR_LIT:id>' ] for result in src_results ] , <EOL> "<STR_LIT>" : dest_proj , <EOL> "<STR_LIT>" : dest_folder } ) [ '<STR_LIT>' ] <EOL> if len ( exists ) > <NUM_LIT:0> : <EOL> print ( fill ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) + '<STR_LIT>' + '<STR_LIT>' . join ( exists ) ) <EOL> for result in src_results : <EOL> if result [ '<STR_LIT:id>' ] not in exists : <EOL> dxpy . DXHTTPRequest ( '<STR_LIT:/>' + result [ '<STR_LIT:id>' ] + '<STR_LIT>' , <EOL> { "<STR_LIT>" : dest_proj , <EOL> "<STR_LIT:name>" : dest_name } ) <EOL> return <EOL> except : <EOL> err_exit ( ) <EOL> def cp ( args ) : <EOL> dest_proj , dest_path , _none = try_call ( resolve_path , args . destination , expected = '<STR_LIT>' ) <EOL> if dest_path is None : <EOL> raise DXCLIError ( '<STR_LIT>' ) <EOL> dx_dest = dxpy . get_handler ( dest_proj ) <EOL> try : <EOL> dx_dest . list_folder ( folder = dest_path , only = '<STR_LIT>' ) <EOL> except : <EOL> cp_to_noexistent_destination ( args , dest_path , dx_dest , dest_proj ) <EOL> return <EOL> if len ( args . sources ) == <NUM_LIT:0> : <EOL> raise DXCLIError ( '<STR_LIT>' ) <EOL> src_objects = [ ] <EOL> src_folders = [ ] <EOL> for source in args . sources : <EOL> src_proj , src_folderpath , src_results = try_call ( resolve_existing_path , <EOL> source , <EOL> allow_mult = True , all_mult = args . all ) <EOL> if src_proj == dest_proj : <EOL> if is_hashid ( source ) : <EOL> raise DXCLIError ( fill ( '<STR_LIT>' + source ) ) <EOL> else : <EOL> raise DXCLIError ( fill ( '<STR_LIT>' + <EOL> '<STR_LIT>' + <EOL> '<STR_LIT>' ) + <EOL> '<STR_LIT>' ) <EOL> if src_proj is None : <EOL> raise DXCLIError ( fill ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) ) <EOL> if src_results is None : <EOL> src_folders . append ( src_folderpath ) <EOL> else : <EOL> src_objects += [ result [ '<STR_LIT:id>' ] for result in src_results ] <EOL> try : <EOL> exists = dxpy . DXHTTPRequest ( '<STR_LIT:/>' + src_proj + '<STR_LIT>' , <EOL> { "<STR_LIT>" : src_objects , <EOL> "<STR_LIT>" : src_folders , <EOL> "<STR_LIT>" : dest_proj , <EOL> "<STR_LIT>" : dest_path } ) [ '<STR_LIT>' ] <EOL> if len ( exists ) > <NUM_LIT:0> : <EOL> print ( fill ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) + '<STR_LIT>' + '<STR_LIT>' . join ( exists ) ) <EOL> except : <EOL> err_exit ( ) </s>
