<s> from django . conf import settings <EOL> import os <EOL> import sys <EOL> import logging <EOL> from django_extensions . management . signals import pre_command , post_command <EOL> try : <EOL> from importlib import import_module <EOL> except ImportError : <EOL> try : <EOL> from django . utils . importlib import import_module <EOL> except ImportError : <EOL> def import_module ( module ) : <EOL> return __import__ ( module , { } , { } , [ '<STR_LIT>' ] ) <EOL> def get_project_root ( ) : <EOL> """<STR_LIT>""" <EOL> django_settings_module = os . environ . get ( '<STR_LIT>' ) <EOL> if not django_settings_module : <EOL> module_str = settings . SETTINGS_MODULE <EOL> else : <EOL> module_str = django_settings_module . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> mod = import_module ( module_str ) <EOL> return os . path . dirname ( os . path . abspath ( mod . __file__ ) ) <EOL> def _make_writeable ( filename ) : <EOL> """<STR_LIT>""" <EOL> import stat <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> return <EOL> if not os . access ( filename , os . W_OK ) : <EOL> st = os . stat ( filename ) <EOL> new_permissions = stat . S_IMODE ( st . st_mode ) | stat . S_IWUSR <EOL> os . chmod ( filename , new_permissions ) <EOL> def setup_logger ( logger , stream , filename = None , fmt = None ) : <EOL> """<STR_LIT>""" <EOL> if len ( logger . handlers ) < <NUM_LIT:1> : <EOL> console = logging . StreamHandler ( stream ) <EOL> console . setLevel ( logging . DEBUG ) <EOL> console . setFormatter ( logging . Formatter ( fmt ) ) <EOL> logger . addHandler ( console ) <EOL> logger . setLevel ( logging . DEBUG ) <EOL> if filename : <EOL> outfile = logging . FileHandler ( filename ) <EOL> outfile . setLevel ( logging . INFO ) <EOL> outfile . setFormatter ( logging . Formatter ( "<STR_LIT>" + ( fmt if fmt else '<STR_LIT>' ) ) ) <EOL> logger . addHandler ( outfile ) <EOL> class RedirectHandler ( logging . Handler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , level = logging . DEBUG ) : <EOL> logging . Handler . __init__ ( self , level ) <EOL> self . name = name <EOL> self . logger = logging . getLogger ( name ) <EOL> def emit ( self , record ) : <EOL> self . logger . handle ( record ) <EOL> def signalcommand ( func ) : <EOL> """<STR_LIT>""" <EOL> def inner ( self , * args , ** kwargs ) : <EOL> pre_command . send ( self . __class__ , args = args , kwargs = kwargs ) <EOL> ret = func ( self , * args , ** kwargs ) <EOL> post_command . send ( self . __class__ , args = args , kwargs = kwargs , outcome = ret ) <EOL> return ret <EOL> return inner </s>
