#NEWLINE# def upload_s3( self , arg , dirname , names ) : #NEWLINE# #INDENT# '\n        This is the callback to os.path.walk and where much of the work happens\n        ' #NEWLINE# ( bucket , key , bucket_name , root_dir ) = arg #NEWLINE# if ( os . path . basename ( dirname ) in self . FILTER_LIST ) : #NEWLINE# #INDENT# del names [ : ] #NEWLINE# return #NEWLINE# #UNINDENT# if ( not root_dir . endswith ( os . path . sep ) ) : #NEWLINE# #INDENT# root_dir = ( root_dir + os . path . sep ) #NEWLINE# #UNINDENT# for file in names : #NEWLINE# #INDENT# headers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( file in self . FILTER_LIST ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# filename = os . path . join ( dirname , file ) #NEWLINE# if os . path . isdir ( filename ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# file_key = filename [ len ( root_dir ) : ] #NEWLINE# if self . prefix : #NEWLINE# #INDENT# file_key = ( '%s/%s' % ( self . prefix , file_key ) ) #NEWLINE# #UNINDENT# if ( not self . do_force ) : #NEWLINE# #INDENT# s3_key = bucket . get_key ( file_key ) #NEWLINE# if s3_key : #NEWLINE# #INDENT# s3_datetime = datetime . datetime ( * time . strptime ( s3_key . last_modified , '%a, %d %b %Y %H:%M:%S %Z' ) [ 0 : 6 ] ) #NEWLINE# local_datetime = datetime . datetime . utcfromtimestamp ( os . stat ( filename ) . st_mtime ) #NEWLINE# if ( local_datetime < s3_datetime ) : #NEWLINE# #INDENT# self . skip_count += 1 #NEWLINE# if ( self . verbosity > 1 ) : #NEWLINE# #INDENT# print ( ( "File %s hasn't been modified since last being uploaded" % file_key ) ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( self . verbosity > 0 ) : #NEWLINE# #INDENT# print ( ( 'Uploading %s...' % file_key ) ) #NEWLINE# #UNINDENT# content_type = mimetypes . guess_type ( filename ) [ 0 ] #NEWLINE# if content_type : #NEWLINE# #INDENT# headers [ 'Content-Type' ] = content_type #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# headers [ 'Content-Type' ] = 'application/octet-stream' #NEWLINE# #UNINDENT# file_obj = open ( filename , 'rb' ) #NEWLINE# file_size = os . fstat ( file_obj . fileno ( ) ) . st_size #NEWLINE# filedata = file_obj . read ( ) #NEWLINE# if file_key . do_gzip : #NEWLINE# #INDENT# if ( ( file_size > 1024 ) and ( content_type in self . GZIP_CONTENT_TYPES ) ) : #NEWLINE# #INDENT# filedata = self . compress_string ( filedata ) #NEWLINE# if self . rename_gzip : #NEWLINE# #INDENT# file_key = ( '%s.%s' % ( file_key , self . SYNC_S3_RENAME_GZIP_EXT ) ) #NEWLINE# #UNINDENT# headers [ 'Content-Encoding' ] = 'gzip' #NEWLINE# if ( self . verbosity > 1 ) : #NEWLINE# #INDENT# print ( ( '\tgzipped: %dk to %dk' % ( ( file_size / 1024 ) , ( len ( filedata ) / 1024 ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if self . do_expires : #NEWLINE# #INDENT# headers [ 'Expires' ] = ( '%s GMT' % email . Utils . formatdate ( time . mktime ( ( datetime . datetime . now ( ) + datetime . timedelta ( days = ( 365 * 2 ) ) ) . timetuple ( ) ) ) ) #NEWLINE# headers [ 'Cache-Control' ] = ( 'max-age %d' % ( ( ( 3600 * 24 ) * 365 ) * 2 ) ) #NEWLINE# if ( self . verbosity > 1 ) : #NEWLINE# #INDENT# print ( ( '\texpires: %s' % headers [ 'Expires' ] ) ) #NEWLINE# print ( ( '\tcache-control: %s' % headers [ 'Cache-Control' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# key . name = file_key #NEWLINE# key . set_contents_from_string ( filedata , headers , replace = True , policy = self . default_acl ) #NEWLINE# #UNINDENT# except boto . exception . S3CreateError as e : #NEWLINE# #INDENT# print ( ( 'Failed: %s' % e ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# print ( e ) #NEWLINE# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . upload_count += 1 #NEWLINE# self . uploaded_files . append ( file_key ) #NEWLINE# #UNINDENT# file_obj . close ( )