<s> from __future__ import with_statement <EOL> import io <EOL> import os <EOL> from optparse import make_option <EOL> from django . core . management . base import NoArgsCommand <EOL> from django . utils . translation import to_locale , activate <EOL> from django . utils . encoding import force_text <EOL> from statici18n . conf import settings <EOL> from statici18n . utils import get_filename <EOL> import django <EOL> if django . VERSION >= ( <NUM_LIT:1> , <NUM_LIT:6> ) : <EOL> from django . views . i18n import ( get_javascript_catalog , <EOL> render_javascript_catalog ) <EOL> else : <EOL> from statici18n . compat import ( get_javascript_catalog , <EOL> render_javascript_catalog ) <EOL> class Command ( NoArgsCommand ) : <EOL> option_list = NoArgsCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , default = settings . STATICI18N_DOMAIN , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT>' , default = [ ] , <EOL> dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> make_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> help = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> super ( NoArgsCommand , self ) . __init__ ( ) <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . requires_system_checks = False <EOL> def handle_noargs ( self , ** options ) : <EOL> locale = options . get ( '<STR_LIT>' ) <EOL> domain = options [ '<STR_LIT>' ] <EOL> packages = options [ '<STR_LIT>' ] or settings . STATICI18N_PACKAGES <EOL> outputdir = options [ '<STR_LIT>' ] <EOL> verbosity = int ( options . get ( '<STR_LIT>' ) ) <EOL> if locale is not None : <EOL> languages = [ locale ] <EOL> else : <EOL> languages = [ to_locale ( lang_code ) <EOL> for ( lang_code , lang_name ) in settings . LANGUAGES ] <EOL> if outputdir is None : <EOL> outputdir = os . path . join ( settings . STATICI18N_ROOT , <EOL> settings . STATICI18N_OUTPUT_DIR ) <EOL> for locale in languages : <EOL> if verbosity > <NUM_LIT:0> : <EOL> self . stdout . write ( "<STR_LIT>" % locale ) <EOL> jsfile = os . path . join ( outputdir , get_filename ( locale , domain ) ) <EOL> basedir = os . path . dirname ( jsfile ) <EOL> if not os . path . isdir ( basedir ) : <EOL> os . makedirs ( basedir ) <EOL> activate ( locale ) <EOL> catalog , plural = get_javascript_catalog ( locale , domain , packages ) <EOL> response = render_javascript_catalog ( catalog , plural ) <EOL> with io . open ( jsfile , "<STR_LIT:w>" , encoding = "<STR_LIT:utf-8>" ) as fp : <EOL> fp . write ( force_text ( response . content ) ) </s>
