<s> import os <EOL> import httplib <EOL> import requests <EOL> from lib . action import St2BaseAction <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> S3_BUCKET_URL = '<STR_LIT>' <EOL> class UploadToS3 ( St2BaseAction ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , bucket , file_name , remote_file = None ) : <EOL> if not remote_file : <EOL> remote_file = os . path . basename ( file_name ) <EOL> if not os . path . isfile ( file_name ) : <EOL> raise ValueError ( '<STR_LIT>' % ( file_name ) ) <EOL> url = S3_BUCKET_URL % { '<STR_LIT>' : bucket } <EOL> url = url + remote_file <EOL> files = { '<STR_LIT:file>' : open ( file_name , '<STR_LIT:rb>' ) } <EOL> response = requests . put ( url = url , files = files ) <EOL> if response . status_code in [ httplib . OK , httplib . CREATED ] : <EOL> status = '<STR_LIT>' <EOL> error = None <EOL> else : <EOL> status = '<STR_LIT>' <EOL> error = response . text <EOL> result = { <EOL> '<STR_LIT>' : response . status_code , <EOL> '<STR_LIT:status>' : status , <EOL> '<STR_LIT>' : remote_file , <EOL> } <EOL> if error : <EOL> result [ '<STR_LIT:error>' ] = error <EOL> return result </s>
