<s> import imp <EOL> import os <EOL> import sys <EOL> import hashlib <EOL> import getpass <EOL> def bootstrap_script ( path , project_path_components ) : <EOL> project_path = os . path . join ( find_parent_path ( path , project_path_components ) , * project_path_components ) <EOL> bootstrap ( project_path ) <EOL> def bootstrap ( path ) : <EOL> path = find_settings_path ( path ) <EOL> from django . core import management <EOL> try : <EOL> settings = imp . load_source ( '<STR_LIT>' , os . path . join ( path , '<STR_LIT>' ) ) <EOL> except ImportError : <EOL> sys . stderr . write ( "<STR_LIT>" % __file__ ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> management . setup_environ ( settings ) <EOL> def find_settings_path ( path ) : <EOL> """<STR_LIT>""" <EOL> return find_parent_path ( path , [ '<STR_LIT>' ] ) <EOL> def find_parent_path ( path , child_path_components ) : <EOL> """<STR_LIT>""" <EOL> if os . path . isfile ( path ) : <EOL> path = os . path . dirname ( path ) <EOL> path = os . path . abspath ( path ) <EOL> parent_path = os . path . abspath ( os . path . join ( path , '<STR_LIT:..>' ) ) <EOL> target_path = os . path . join ( path , * child_path_components ) <EOL> if os . path . exists ( target_path ) : <EOL> return path <EOL> elif path != parent_path : <EOL> return find_parent_path ( parent_path , child_path_components ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def get_config_identifiers ( path ) : <EOL> config_dir = os . path . join ( find_settings_path ( path ) , '<STR_LIT>' ) <EOL> files = list ( os . walk ( config_dir ) ) <EOL> if not files : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> files = files [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] + files [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> identifiers = map ( lambda name : name . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] , filter ( lambda name : ( '<STR_LIT:.>' not in name or name . endswith ( "<STR_LIT>" ) ) and name not in ( '<STR_LIT>' , '<STR_LIT>' , ) , files ) ) <EOL> return [ ( i + <NUM_LIT:1> , x ) for i , x in enumerate ( identifiers ) ] <EOL> def setup_environment ( path ) : <EOL> IDENTIFIERS = get_config_identifiers ( path ) <EOL> CONFIG_IDENTIFIER = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if len ( sys . argv ) >= <NUM_LIT:2> and sys . argv [ <NUM_LIT:1> ] in ( '<STR_LIT>' , '<STR_LIT>' , ) : <EOL> if '<STR_LIT>' in os . environ and CONFIG_IDENTIFIER in [ name for id , name in IDENTIFIERS ] : <EOL> bootstrap ( path ) <EOL> return <EOL> IDENTIFIERS_LOOKUP = dict ( IDENTIFIERS ) <EOL> IDENTIFIERS_REVERSE_LOOKUP = dict ( [ [ name , id ] for id , name in IDENTIFIERS ] ) <EOL> CONFIG_IDENTIFIER_ID = IDENTIFIERS_REVERSE_LOOKUP . get ( CONFIG_IDENTIFIER , '<STR_LIT>' ) <EOL> CONFIG_IDENTIFIER_INTERACTIVE = os . environ . get ( '<STR_LIT>' , '<STR_LIT:True>' ) <EOL> if CONFIG_IDENTIFIER and CONFIG_IDENTIFIER_INTERACTIVE == '<STR_LIT:False>' : <EOL> print "<STR_LIT>" % CONFIG_IDENTIFIER . upper ( ) <EOL> return bootstrap ( path ) <EOL> while True : <EOL> print "<STR_LIT>" <EOL> for id , name in IDENTIFIERS : <EOL> print "<STR_LIT>" % ( id , name ) <EOL> try : <EOL> selection = raw_input ( "<STR_LIT>" % CONFIG_IDENTIFIER_ID ) <EOL> except : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> selection = selection . isdigit ( ) and int ( selection ) or ( selection and selection or CONFIG_IDENTIFIER_ID ) <EOL> if selection and IDENTIFIERS_LOOKUP . has_key ( selection ) : <EOL> identifier = dict ( IDENTIFIERS ) . get ( int ( selection ) ) <EOL> settings_path = find_settings_path ( path ) <EOL> os . environ [ '<STR_LIT>' ] = identifier <EOL> os . putenv ( '<STR_LIT>' , identifier ) <EOL> settings = imp . load_source ( '<STR_LIT>' , os . path . join ( settings_path , '<STR_LIT>' ) ) <EOL> os . putenv ( '<STR_LIT>' , CONFIG_IDENTIFIER ) <EOL> os . environ [ '<STR_LIT>' ] = CONFIG_IDENTIFIER <EOL> if getattr ( settings , '<STR_LIT>' , False ) and getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> password = getpass . getpass ( '<STR_LIT>' % identifier ) <EOL> except : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> if hashlib . md5 ( password ) . hexdigest ( ) != settings . PASSWORD_DIGEST : <EOL> print '<STR_LIT>' <EOL> continue <EOL> CONFIG_IDENTIFIER = identifier <EOL> break <EOL> os . environ [ '<STR_LIT>' ] = CONFIG_IDENTIFIER <EOL> os . putenv ( '<STR_LIT>' , CONFIG_IDENTIFIER ) <EOL> bootstrap ( path ) </s>
