<s> from __future__ import unicode_literals <EOL> import logging <EOL> import os <EOL> import re <EOL> from django . conf import settings , global_settings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . utils import six <EOL> from djblets . log import restart_logging , siteconfig as log_siteconfig <EOL> from djblets . recaptcha import siteconfig as recaptcha_siteconfig <EOL> from djblets . siteconfig . django_settings import ( apply_django_settings , <EOL> get_django_defaults , <EOL> get_django_settings_map ) <EOL> from djblets . siteconfig . models import SiteConfiguration <EOL> from haystack import connections <EOL> from reviewboard . accounts . backends import get_registered_auth_backend <EOL> from reviewboard . signals import site_settings_loaded <EOL> storage_backend_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> settings_map = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> settings_map . update ( get_django_settings_map ( ) ) <EOL> settings_map . update ( log_siteconfig . settings_map ) <EOL> settings_map . update ( recaptcha_siteconfig . settings_map ) <EOL> settings_map . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> defaults = get_django_defaults ( ) <EOL> defaults . update ( log_siteconfig . defaults ) <EOL> defaults . update ( recaptcha_siteconfig . defaults ) <EOL> defaults . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT:http>' , <EOL> '<STR_LIT>' : os . path . join ( settings . SITE_DATA_DIR , <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT>' : settings . SITE_ROOT + "<STR_LIT>" , <EOL> } ) <EOL> defaults . update ( { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> def load_site_config ( full_reload = False ) : <EOL> """<STR_LIT>""" <EOL> def apply_setting ( settings_key , db_key , default = None ) : <EOL> """<STR_LIT>""" <EOL> db_value = siteconfig . settings . get ( db_key ) <EOL> if db_value : <EOL> setattr ( settings , settings_key , db_value ) <EOL> elif default : <EOL> setattr ( settings , settings_key , default ) <EOL> def update_haystack_settings ( ) : <EOL> """<STR_LIT>""" <EOL> apply_setting ( "<STR_LIT>" , None , { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : settings . HAYSTACK_CONNECTIONS [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : ( siteconfig . get ( '<STR_LIT>' ) or <EOL> defaults [ '<STR_LIT>' ] ) , <EOL> } , <EOL> } ) <EOL> connections . connections_info = settings . HAYSTACK_CONNECTIONS <EOL> connections . _connections = { } <EOL> dirty = False <EOL> try : <EOL> siteconfig = SiteConfiguration . objects . get_current ( ) <EOL> except SiteConfiguration . DoesNotExist : <EOL> raise ImproperlyConfigured ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except Exception as e : <EOL> logging . error ( '<STR_LIT>' % e ) <EOL> return <EOL> if not siteconfig . get_defaults ( ) : <EOL> siteconfig . add_defaults ( defaults ) <EOL> mail_default_from = siteconfig . settings . get ( '<STR_LIT>' , <EOL> global_settings . DEFAULT_FROM_EMAIL ) <EOL> if ( not mail_default_from or <EOL> mail_default_from == global_settings . DEFAULT_FROM_EMAIL ) : <EOL> domain = siteconfig . site . domain . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> siteconfig . set ( '<STR_LIT>' , '<STR_LIT>' + domain ) <EOL> site_static_root = siteconfig . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> site_media_root = siteconfig . settings . get ( '<STR_LIT>' ) <EOL> if site_static_root == '<STR_LIT>' or site_static_root == site_media_root : <EOL> siteconfig . set ( '<STR_LIT>' , settings . STATIC_ROOT ) <EOL> site_static_url = siteconfig . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> site_media_url = siteconfig . settings . get ( '<STR_LIT>' ) <EOL> if site_static_url == '<STR_LIT>' or site_static_url == site_media_url : <EOL> siteconfig . set ( '<STR_LIT>' , settings . STATIC_URL ) <EOL> apply_django_settings ( siteconfig , settings_map ) <EOL> if full_reload and not getattr ( settings , '<STR_LIT>' , False ) : <EOL> restart_logging ( ) <EOL> update_haystack_settings ( ) <EOL> apply_setting ( "<STR_LIT>" , None , ( <EOL> ( siteconfig . get ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> siteconfig . get ( "<STR_LIT>" , "<STR_LIT>" ) ) , <EOL> ) ) <EOL> apply_setting ( "<STR_LIT>" , None , settings . ADMINS ) <EOL> apply_setting ( "<STR_LIT>" , None , settings . STATIC_URL + "<STR_LIT>" ) <EOL> auth_backend_id = siteconfig . settings . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> builtin_backend_obj = get_registered_auth_backend ( '<STR_LIT>' ) <EOL> builtin_backend = "<STR_LIT>" % ( builtin_backend_obj . __module__ , <EOL> builtin_backend_obj . __name__ ) <EOL> if auth_backend_id == "<STR_LIT>" : <EOL> custom_backends = siteconfig . settings . get ( "<STR_LIT>" ) <EOL> if isinstance ( custom_backends , six . string_types ) : <EOL> custom_backends = ( custom_backends , ) <EOL> elif isinstance ( custom_backends , list ) : <EOL> custom_backends = tuple ( custom_backends ) <EOL> settings . AUTHENTICATION_BACKENDS = custom_backends <EOL> if builtin_backend not in custom_backends : <EOL> settings . AUTHENTICATION_BACKENDS += ( builtin_backend , ) <EOL> else : <EOL> backend = get_registered_auth_backend ( auth_backend_id ) <EOL> if backend and backend is not builtin_backend_obj : <EOL> settings . AUTHENTICATION_BACKENDS = ( "<STR_LIT>" % ( backend . __module__ , backend . __name__ ) , <EOL> builtin_backend ) <EOL> else : <EOL> settings . AUTHENTICATION_BACKENDS = ( builtin_backend , ) <EOL> if auth_backend_id == "<STR_LIT>" : <EOL> if not hasattr ( settings , '<STR_LIT>' ) : <EOL> if hasattr ( settings , '<STR_LIT>' ) : <EOL> m = re . search ( "<STR_LIT>" , <EOL> settings . LDAP_UID_MASK ) <EOL> if m : <EOL> settings . LDAP_UID = m . group ( <NUM_LIT:1> ) <EOL> else : <EOL> settings . LDAP_UID = '<STR_LIT>' <EOL> else : <EOL> settings . LDAP_UID = '<STR_LIT>' <EOL> settings . LDAP_UID_MASK = None <EOL> siteconfig . set ( '<STR_LIT>' , settings . LDAP_UID ) <EOL> siteconfig . set ( '<STR_LIT>' , settings . LDAP_UID_MASK ) <EOL> dirty = True <EOL> settings . AUTHENTICATION_BACKENDS += ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> storage_backend = siteconfig . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if storage_backend in storage_backend_map : <EOL> settings . DEFAULT_FILE_STORAGE = storage_backend_map [ storage_backend ] <EOL> else : <EOL> settings . DEFAULT_FILE_STORAGE = storage_backend_map [ '<STR_LIT>' ] <EOL> settings . AWS_QUERYSTRING_AUTH = siteconfig . get ( '<STR_LIT>' ) <EOL> settings . AWS_ACCESS_KEY_ID = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> settings . AWS_SECRET_ACCESS_KEY = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> settings . AWS_STORAGE_BUCKET_NAME = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> try : <EOL> settings . AWS_CALLING_FORMAT = int ( siteconfig . get ( '<STR_LIT>' ) ) <EOL> except ValueError : <EOL> settings . AWS_CALLING_FORMAT = <NUM_LIT:0> <EOL> settings . SWIFT_AUTH_URL = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> settings . SWIFT_USERNAME = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> settings . SWIFT_KEY = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> try : <EOL> settings . SWIFT_AUTH_VERSION = int ( siteconfig . get ( '<STR_LIT>' ) ) <EOL> except : <EOL> settings . SWIFT_AUTH_VERSION = <NUM_LIT:1> <EOL> settings . SWIFT_CONTAINER_NAME = six . text_type ( <EOL> siteconfig . get ( '<STR_LIT>' ) ) <EOL> if siteconfig . settings . get ( '<STR_LIT>' , '<STR_LIT:http>' ) == '<STR_LIT>' : <EOL> os . environ [ b'<STR_LIT>' ] = b'<STR_LIT>' <EOL> else : <EOL> os . environ [ b'<STR_LIT>' ] = b'<STR_LIT>' <EOL> if dirty : <EOL> siteconfig . save ( ) <EOL> site_settings_loaded . send ( sender = None ) <EOL> return siteconfig </s>
