<s> import os <EOL> import sys <EOL> import argparse <EOL> from . commands . init import init <EOL> ENTRY_POINT = '<STR_LIT>' <EOL> CONFIGURATION_MODULE = "<STR_LIT>" <EOL> def in_armstrong_project ( some_path = None ) : <EOL> if some_path is None : <EOL> some_path = CWD <EOL> joined = os . path . join ( some_path , CONFIGURATION_MODULE ) <EOL> return os . path . isdir ( joined ) and os . path . exists ( os . path . join ( joined , '<STR_LIT>' ) ) <EOL> def find_project_dir ( path = os . getcwd ( ) ) : <EOL> """<STR_LIT>""" <EOL> path_split = os . path . split ( path ) <EOL> while path_split [ <NUM_LIT:1> ] : <EOL> if in_armstrong_project ( path ) : <EOL> return path <EOL> path = path_split [ <NUM_LIT:0> ] <EOL> path_split = os . path . split ( path ) <EOL> return None <EOL> CWD = find_project_dir ( ) or os . getcwd ( ) <EOL> def get_current_configuration ( ) : <EOL> """<STR_LIT>""" <EOL> type = "<STR_LIT>" if "<STR_LIT>" in sys . argv else "<STR_LIT>" <EOL> return "<STR_LIT>" % ( CONFIGURATION_MODULE , type ) <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> subparsers = parser . add_subparsers ( title = '<STR_LIT>' ) <EOL> from pkg_resources import iter_entry_points <EOL> loaded = { } <EOL> for ep in iter_entry_points ( group = ENTRY_POINT ) : <EOL> if ep . name in loaded : <EOL> continue <EOL> loaded [ ep . name ] = True <EOL> command = ep . load ( ) <EOL> if ( not in_armstrong_project ( ) and <EOL> getattr ( command , "<STR_LIT>" , False ) ) : <EOL> continue <EOL> armstrong_parser = subparsers . add_parser ( ep . name , <EOL> description = command . __doc__ , <EOL> help = command . __doc__ ) <EOL> if hasattr ( command , '<STR_LIT>' ) : <EOL> command . build_parser ( armstrong_parser ) <EOL> armstrong_parser . set_defaults ( func = command ) <EOL> if in_armstrong_project ( ) : <EOL> if CWD not in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , CWD ) <EOL> try : <EOL> settings_module = get_current_configuration ( ) <EOL> __import__ ( settings_module , globals ( ) , locals ( ) ) <EOL> from django . core . management import setup_environ <EOL> setup_environ ( sys . modules [ settings_module ] ) <EOL> except ImportError , e : <EOL> sys . stderr . write ( "<STR_LIT>" % <EOL> ( settings_module , e ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> from django . core . management import get_commands <EOL> django_commands = get_commands ( ) . keys ( ) <EOL> django_commands . sort ( ) <EOL> for command in django_commands : <EOL> dj_parser = subparsers . add_parser ( command , help = '<STR_LIT>' ) <EOL> dj_parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' % CONFIGURATION_MODULE ) <EOL> dj_parser . set_defaults ( func = call_django ) <EOL> args , argv = parser . parse_known_args ( ) <EOL> kwargs = vars ( args ) <EOL> func = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if argv : <EOL> func ( argv = argv , ** kwargs ) <EOL> else : <EOL> func ( ** kwargs ) <EOL> def call_django ( argv = [ ] , production = False ) : <EOL> if CWD not in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , CWD ) <EOL> settings_module = "<STR_LIT>" % CONFIGURATION_MODULE <EOL> if production : <EOL> settings_module = "<STR_LIT>" % CONFIGURATION_MODULE <EOL> settings = None <EOL> try : <EOL> __import__ ( settings_module , globals ( ) , locals ( ) ) <EOL> settings = sys . modules [ settings_module ] <EOL> except ImportError , e : <EOL> sys . stderr . write ( "<STR_LIT>" % ( settings_module , e ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> new_argv = sys . argv [ <NUM_LIT:0> : <NUM_LIT:2> ] + argv <EOL> from django . core . management import execute_manager <EOL> execute_manager ( settings , argv = new_argv ) </s>
