#NEWLINE# def command_copy( args ) : #NEWLINE# #INDENT# '\n    Copy one or more source-files(s) to a destpath (destfile or destdir).\n    Destdir mode is used if:\n      * More than one srcfile is provided\n      * Last parameter ends with a slash ("/").\n      * Last parameter is an existing directory\n\n    Destination directory path is created if needed.\n    Similar to the UNIX command: \'cp srcfile... destpath\'\n    ' #NEWLINE# sources = args . sources #NEWLINE# destpath = args . destpath #NEWLINE# source_files = [ ] #NEWLINE# for file_ in sources : #NEWLINE# #INDENT# if ( '*' in file_ ) : #NEWLINE# #INDENT# selected = glob ( file_ ) #NEWLINE# source_files . extend ( selected ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . isfile ( file_ ) : #NEWLINE# #INDENT# source_files . append ( file_ ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( destpath . endswith ( '/' ) or os . path . isdir ( destpath ) or ( len ( sources ) > 1 ) ) : #NEWLINE# #INDENT# destdir = destpath #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( len ( source_files ) == 1 ) #NEWLINE# destdir = os . path . dirname ( destpath ) #NEWLINE# #UNINDENT# if ( not os . path . isdir ( destdir ) ) : #NEWLINE# #INDENT# sys . stdout . write ( ( 'copy: Create dir %s\n' % destdir ) ) #NEWLINE# os . makedirs ( destdir ) #NEWLINE# #UNINDENT# for source in source_files : #NEWLINE# #INDENT# destname = os . path . join ( destdir , os . path . basename ( source ) ) #NEWLINE# sys . stdout . write ( ( 'copy: %s => %s\n' % ( source , destname ) ) ) #NEWLINE# shutil . copy ( source , destname ) #NEWLINE# #UNINDENT# return 0