<s> import os <EOL> from optparse import make_option , OptionError <EOL> from django . conf import settings <EOL> from django . core . management . base import BaseCommand <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from compressor import CssCompressor <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) , <EOL> ) <EOL> help = '<STR_LIT>' <EOL> def handle ( self , * args , ** options ) : <EOL> uid = - <NUM_LIT:1> <EOL> gid = - <NUM_LIT:1> <EOL> chown = options . get ( '<STR_LIT>' , None ) <EOL> chgrp = options . get ( '<STR_LIT>' , None ) <EOL> verbosity = int ( options . get ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> if chown or chgrp : <EOL> try : <EOL> import pwd <EOL> except ImportError : <EOL> raise OptionError ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> if chown : <EOL> uid = pwd . getpwnam ( chown ) . pw_uid <EOL> if chgrp : <EOL> gid = pwd . getpwnam ( chgrp ) . pw_gid <EOL> except ( KeyError , TypeError ) : <EOL> raise OptionError ( '<STR_LIT>' % chown , '<STR_LIT>' ) <EOL> if not hasattr ( os , '<STR_LIT>' ) : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> if not hasattr ( settings , '<STR_LIT>' ) or not settings . COMPILER_FORMATS : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' ) <EOL> if verbosity : <EOL> print '<STR_LIT>' % settings . MEDIA_ROOT <EOL> files_to_compile = [ ] <EOL> for root , dirs , files in os . walk ( settings . MEDIA_ROOT ) : <EOL> for _dir in dirs : <EOL> for _file in files : <EOL> name , ext = os . path . splitext ( _file ) <EOL> if ext in settings . COMPILER_FORMATS : <EOL> files_to_compile . append ( ( os . path . join ( root , name ) , ext ) ) <EOL> if verbosity : <EOL> print '<STR_LIT>' % len ( files_to_compile ) <EOL> for filename , extension in files_to_compile : <EOL> if verbosity > <NUM_LIT:1> : <EOL> print '<STR_LIT>' % ( filename , extension ) <EOL> CssCompressor . compile ( filename , settings . COMPILER_FORMATS [ extension ] ) <EOL> css_file = '<STR_LIT>' % filename <EOL> if chown or chgrp : <EOL> os . chown ( css_file , uid , gid ) <EOL> os . chmod ( css_file , <NUM_LIT:0> <NUM_LIT> ) <EOL> else : <EOL> os . chmod ( css_file , <NUM_LIT:0> <NUM_LIT> ) <EOL> if verbosity : <EOL> print '<STR_LIT>' </s>
