<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import logging <EOL> import Bcfg2 . Logger <EOL> import Bcfg2 . Options <EOL> try : <EOL> import django <EOL> import django . core . management <EOL> import django . conf <EOL> HAS_DJANGO = True <EOL> except ImportError : <EOL> HAS_DJANGO = False <EOL> try : <EOL> import south <EOL> HAS_SOUTH = True <EOL> except ImportError : <EOL> HAS_SOUTH = False <EOL> settings = dict ( <EOL> TIME_ZONE = None , <EOL> TEMPLATE_DEBUG = False , <EOL> DEBUG = False , <EOL> ALLOWED_HOSTS = [ '<STR_LIT:*>' ] , <EOL> MEDIA_URL = '<STR_LIT>' , <EOL> MANAGERS = ( ( '<STR_LIT>' , '<STR_LIT:root>' ) , ) , <EOL> ADMINS = ( ( '<STR_LIT>' , '<STR_LIT:root>' ) , ) , <EOL> LANGUAGE_CODE = '<STR_LIT>' , <EOL> SITE_ID = <NUM_LIT:1> , <EOL> INSTALLED_APPS = ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> MEDIA_ROOT = '<STR_LIT>' , <EOL> STATIC_URL = '<STR_LIT>' , <EOL> SECRET_KEY = '<STR_LIT>' , <EOL> TEMPLATE_LOADERS = ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> MIDDLEWARE_CLASSES = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ROOT_URLCONF = '<STR_LIT>' , <EOL> AUTHENTICATION_BACKENDS = ( '<STR_LIT>' ) , <EOL> LOGIN_URL = '<STR_LIT>' , <EOL> SESSION_EXPIRE_AT_BROWSER_CLOSE = True , <EOL> TEMPLATE_DIRS = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> TEMPLATE_CONTEXT_PROCESSORS = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> DATABASE_ROUTERS = [ '<STR_LIT>' ] , <EOL> TEST_RUNNER = '<STR_LIT>' ) <EOL> if HAS_DJANGO and django . VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and django . VERSION [ <NUM_LIT:1> ] >= <NUM_LIT:6> : <EOL> settings [ '<STR_LIT>' ] += ( '<STR_LIT>' , ) <EOL> elif HAS_SOUTH : <EOL> settings [ '<STR_LIT>' ] += ( '<STR_LIT>' , ) <EOL> if HAS_DJANGO and django . VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and django . VERSION [ <NUM_LIT:1> ] >= <NUM_LIT:7> : <EOL> settings [ '<STR_LIT>' ] += ( '<STR_LIT>' , ) <EOL> elif HAS_SOUTH : <EOL> settings [ '<STR_LIT>' ] += ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> settings [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> if '<STR_LIT>' in os . environ : <EOL> settings [ '<STR_LIT>' ] += ( '<STR_LIT>' , ) <EOL> if HAS_DJANGO and django . VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and django . VERSION [ <NUM_LIT:1> ] < <NUM_LIT:3> : <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> settings [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> def finalize_django_config ( opts = None , silent = False ) : <EOL> """<STR_LIT>""" <EOL> if opts is None : <EOL> opts = Bcfg2 . Options . setup <EOL> settings [ '<STR_LIT>' ] = dict ( <EOL> default = dict ( <EOL> ENGINE = "<STR_LIT>" % opts . db_engine , <EOL> NAME = opts . db_name , <EOL> USER = opts . db_user , <EOL> PASSWORD = opts . db_password , <EOL> HOST = opts . db_host , <EOL> PORT = opts . db_port , <EOL> OPTIONS = opts . db_opts , <EOL> SCHEMA = opts . db_schema ) ) <EOL> if hasattr ( opts , "<STR_LIT>" ) and opts . reporting_db_engine is not None : <EOL> settings [ '<STR_LIT>' ] [ '<STR_LIT>' ] = dict ( <EOL> ENGINE = "<STR_LIT>" % opts . reporting_db_engine , <EOL> NAME = opts . reporting_db_name , <EOL> USER = opts . reporting_db_user , <EOL> PASSWORD = opts . reporting_db_password , <EOL> HOST = opts . reporting_db_host , <EOL> PORT = opts . reporting_db_port , <EOL> OPTIONS = opts . reporting_db_opts , <EOL> SCHEMA = opts . reporting_db_schema ) <EOL> settings [ '<STR_LIT>' ] = opts . time_zone <EOL> settings [ '<STR_LIT>' ] = settings [ '<STR_LIT>' ] = opts . web_debug <EOL> if opts . web_debug : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if opts . web_prefix : <EOL> settings [ '<STR_LIT>' ] = opts . web_prefix . rstrip ( '<STR_LIT:/>' ) + settings [ '<STR_LIT>' ] <EOL> if opts . django_settings : <EOL> settings . update ( opts . django_settings ) <EOL> logger = logging . getLogger ( ) <EOL> logger . debug ( "<STR_LIT>" % settings ) <EOL> module = sys . modules [ __name__ ] <EOL> for name , value in settings . items ( ) : <EOL> setattr ( module , name , value ) <EOL> try : <EOL> django . conf . settings . configure ( ** settings ) <EOL> except RuntimeError : <EOL> if not silent : <EOL> logger . warning ( "<STR_LIT>" % <EOL> sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> def sync_databases ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if django . VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and django . VERSION [ <NUM_LIT:1> ] >= <NUM_LIT:7> : <EOL> return <EOL> logger = logging . getLogger ( ) <EOL> for database in settings [ '<STR_LIT>' ] : <EOL> logger . debug ( "<STR_LIT>" % ( database ) ) <EOL> django . core . management . call_command ( "<STR_LIT>" , database = database , <EOL> ** kwargs ) <EOL> def upgrade_to_django_migrations ( database , logger ) : <EOL> """<STR_LIT>""" <EOL> last_migration = None <EOL> try : <EOL> cursor = django . db . connections [ database ] . cursor ( ) <EOL> cursor . cursor . execute ( '<STR_LIT>' ) <EOL> applied_migrations = [ name for ( name , ) in cursor . fetchall ( ) ] <EOL> last_migration = sorted ( applied_migrations ) . pop ( ) <EOL> except : <EOL> logger . debug ( "<STR_LIT>" % <EOL> database ) <EOL> if last_migration is not None : <EOL> django . core . management . call_command ( <EOL> "<STR_LIT>" , '<STR_LIT>' , last_migration , <EOL> database = database , fake = True ) <EOL> def initial_django_migration ( database ) : <EOL> """<STR_LIT>""" <EOL> from django . db . migrations import loader <EOL> loader = loader . MigrationLoader ( django . db . connections [ database ] ) <EOL> return len ( loader . applied_migrations ) == <NUM_LIT:0> <EOL> def migrate_databases ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> logger = logging . getLogger ( ) <EOL> for database in settings [ '<STR_LIT>' ] : <EOL> logger . debug ( "<STR_LIT>" % ( database ) ) <EOL> if django . VERSION [ <NUM_LIT:0> ] == <NUM_LIT:1> and django . VERSION [ <NUM_LIT:1> ] >= <NUM_LIT:7> : <EOL> django . setup ( ) <EOL> if initial_django_migration ( database ) : <EOL> logger . warning ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % database ) <EOL> upgrade_to_django_migrations ( database , logger ) <EOL> django . core . management . call_command ( "<STR_LIT>" , database = database , <EOL> ** kwargs ) <EOL> def get_db_label ( application ) : <EOL> """<STR_LIT>""" <EOL> if application in settings [ '<STR_LIT>' ] : <EOL> return application <EOL> return '<STR_LIT:default>' <EOL> class PerApplicationRouter ( object ) : <EOL> """<STR_LIT>""" <EOL> def _db_per_app ( self , model , ** _ ) : <EOL> """<STR_LIT>""" <EOL> return get_db_label ( model . _meta . app_label ) <EOL> def db_for_read ( self , model , ** hints ) : <EOL> """<STR_LIT>""" <EOL> return self . _db_per_app ( model , ** hints ) <EOL> def db_for_write ( self , model , ** hints ) : <EOL> """<STR_LIT>""" <EOL> return self . _db_per_app ( model , ** hints ) <EOL> def allow_relation ( self , obj1 , obj2 , ** _ ) : <EOL> """<STR_LIT>""" <EOL> return obj1 . _meta . app_label == obj2 . _meta . app_label <EOL> def allow_syncdb ( self , * _ ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def allow_migrate ( self , * _args , ** _kwargs ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> class _OptionContainer ( object ) : <EOL> """<STR_LIT>""" <EOL> parse_first = True <EOL> options = [ <EOL> Bcfg2 . Options . Common . repository , <EOL> Bcfg2 . Options . PathOption ( <EOL> '<STR_LIT>' , '<STR_LIT>' , cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> default = "<STR_LIT>" , <EOL> action = Bcfg2 . Options . ConfigFileAction , <EOL> help = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . RepositoryMacroOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT:name>' ) , default = '<STR_LIT>' , <EOL> help = "<STR_LIT>" , dest = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT:user>' ) , help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT:password>' ) , help = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT:host>' ) , help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT:port>' ) , help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , help = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , default = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , help = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , type = Bcfg2 . Options . Types . literal_dict , <EOL> default = dict ( ) ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> default = '<STR_LIT>' , <EOL> help = "<STR_LIT>" , dest = "<STR_LIT>" ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> default = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> type = Bcfg2 . Options . Types . literal_dict , default = dict ( ) ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , help = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . BooleanOption ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , help = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , help = '<STR_LIT>' ) , <EOL> Bcfg2 . Options . Option ( <EOL> cf = ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' , <EOL> type = Bcfg2 . Options . Types . literal_dict , default = dict ( ) ) ] <EOL> @ staticmethod <EOL> def component_parsed_hook ( opts ) : <EOL> """<STR_LIT>""" <EOL> if HAS_DJANGO : <EOL> finalize_django_config ( opts = opts ) <EOL> @ staticmethod <EOL> def options_parsed_hook ( ) : <EOL> """<STR_LIT>""" <EOL> if HAS_DJANGO : <EOL> finalize_django_config ( silent = True ) <EOL> Bcfg2 . Options . get_parser ( ) . add_component ( _OptionContainer ) </s>
