<s> import tempfile <EOL> import Image <EOL> import shutil <EOL> import sys <EOL> from boto . s3 . connection import S3Connection <EOL> from boto . s3 . key import Key <EOL> IMAGE_SIZES = [ <EOL> ( <NUM_LIT> , <NUM_LIT> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> ) <EOL> ] <EOL> bucket_name = sys . argv [ <NUM_LIT:1> ] <EOL> tmpdir = tempfile . mkdtemp ( ) <EOL> conn = S3Connection ( ) <EOL> bucket = conn . get_bucket ( bucket_name ) <EOL> for key in bucket . list ( prefix = '<STR_LIT>' ) : <EOL> filename = key . key . strip ( '<STR_LIT>' ) <EOL> print '<STR_LIT>' % filename <EOL> tmpfile = '<STR_LIT>' % ( tmpdir , filename ) <EOL> key . get_contents_to_filename ( tmpfile ) <EOL> orig_image = Image . open ( tmpfile ) <EOL> file_ext = filename . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> for resolution in IMAGE_SIZES : <EOL> resized_name = '<STR_LIT>' % ( filename . rstrip ( file_ext ) , resolution [ <NUM_LIT:0> ] , resolution [ <NUM_LIT:1> ] , file_ext ) <EOL> print '<STR_LIT>' % resized_name <EOL> resized_tmpfile = '<STR_LIT>' % ( tmpdir , resized_name ) <EOL> resized_image = orig_image . resize ( resolution ) <EOL> resized_image . save ( resized_tmpfile ) <EOL> resized_key = Key ( bucket ) <EOL> resized_key . key = '<STR_LIT>' % resized_name <EOL> resized_key . set_contents_from_filename ( resized_tmpfile ) <EOL> key . delete ( ) <EOL> shutil . rmtree ( tmpdir ) </s>
