<s> """<STR_LIT>""" <EOL> import optparse <EOL> from django . core . management . base import BaseCommand , CommandError <EOL> from os import makedirs , remove <EOL> from os . path import abspath , dirname , join , exists <EOL> from sys import argv <EOL> import urllib2 <EOL> CACHE_DIR = "<STR_LIT>" <EOL> MANIFEST_FILENAME = "<STR_LIT>" <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> optparse . make_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , default = False , <EOL> help = "<STR_LIT>" ) , <EOL> ) <EOL> help = '<STR_LIT>' <EOL> args = '<STR_LIT>' <EOL> can_import_settings = True <EOL> def handle ( self , * args , ** options ) : <EOL> from django . conf import settings <EOL> if not hasattr ( settings , '<STR_LIT>' ) or not hasattr ( settings , '<STR_LIT>' ) : <EOL> raise CommandError ( '<STR_LIT>' + '<STR_LIT>' ) <EOL> else : <EOL> self . AWS_ACCESS_KEY_ID = settings . AWS_ACCESS_KEY_ID <EOL> self . AWS_SECRET_ACCESS_KEY = settings . AWS_SECRET_ACCESS_KEY <EOL> if not hasattr ( settings , '<STR_LIT>' ) : <EOL> raise CommandError ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> else : <EOL> if not settings . AWS_STORAGE_BUCKET_NAME : <EOL> raise CommandError ( '<STR_LIT>' ) <EOL> self . AWS_STORAGE_BUCKET_NAME = settings . AWS_STORAGE_BUCKET_NAME <EOL> cache_root = join ( abspath ( dirname ( argv [ <NUM_LIT:0> ] ) ) , settings . STATIC_ROOT , CACHE_DIR ) <EOL> if not exists ( cache_root ) : <EOL> makedirs ( cache_root ) <EOL> do_download = options . get ( '<STR_LIT>' ) <EOL> try : <EOL> open ( join ( cache_root , MANIFEST_FILENAME ) ) <EOL> print "<STR_LIT>" <EOL> except IOError : <EOL> do_download = True <EOL> if do_download : <EOL> print "<STR_LIT>" <EOL> u = urllib2 . urlopen ( "<STR_LIT>" % ( settings . STATIC_URL , CACHE_DIR , MANIFEST_FILENAME ) ) <EOL> manifest_path = join ( cache_root , MANIFEST_FILENAME ) <EOL> try : <EOL> remove ( manifest_path ) <EOL> except : <EOL> pass <EOL> localFile = open ( manifest_path , '<STR_LIT>' ) <EOL> localFile . write ( u . read ( ) ) <EOL> print "<STR_LIT>" <EOL> localFile . close ( ) </s>
