Django

Code

Changeset 6871

Show
Ignore:
Timestamp:
12/03/07 23:53:33 (9 months ago)
Author:
adrian
Message:

Undid [6718], as it broke 'django-admin.py runserver' for a reason I haven't figured out yet

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/__init__.py

    r6870 r6871  
    5353                   {}, {}, ['Command']), 'Command')() 
    5454 
    55 def get_commands(): 
     55def get_commands(load_user_commands=True, project_directory=None): 
    5656    """ 
    5757    Returns a dictionary mapping command names to their callback applications. 
     
    8080    if _commands is None: 
    8181        _commands = dict([(name, 'django.core') for name in find_commands(__path__[0])]) 
    82         # Get commands from all installed apps. 
    83         try: 
     82 
     83        if load_user_commands: 
     84            # Get commands from all installed apps. 
    8485            from django.conf import settings 
    85             apps = settings.INSTALLED_APPS 
    86         except (AttributeError, ImportError): 
    87             apps = [] 
    88  
    89         for app_name in apps: 
    90             try: 
    91                 path = find_management_module(app_name) 
    92                 _commands.update(dict([(name, app_name) for name in find_commands(path)])) 
    93             except ImportError: 
    94                 pass # No management module - ignore this app 
    95  
    96         # Try to determine the project directory 
    97         try: 
    98             from django.conf import settings 
    99             project_directory = setup_environ(__import__(settings.SETTINGS_MODULE)) 
    100         except (AttributeError, ImportError): 
    101             project_directory = None 
     86            for app_name in settings.INSTALLED_APPS: 
     87                try: 
     88                    path = find_management_module(app_name) 
     89                    _commands.update(dict([(name, app_name) for name in find_commands(path)])) 
     90                except ImportError: 
     91                    pass # No management module -- ignore this app. 
    10292 
    10393        if project_directory: 
     
    156146        self.argv = argv or sys.argv[:] 
    157147        self.prog_name = os.path.basename(self.argv[0]) 
     148        self.project_directory = None 
     149        self.user_commands = False 
    158150 
    159151    def main_help_text(self): 
     
    165157        usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name) 
    166158        usage.append('Available subcommands:') 
    167         commands = get_commands().keys() 
     159        commands = get_commands(self.user_commands, self.project_directory).keys() 
    168160        commands.sort() 
    169161        for cmd in commands: 
     
    178170        """ 
    179171        try: 
    180             app_name = get_commands()[subcommand] 
     172            app_name = get_commands(self.user_commands, self.project_directory)[subcommand] 
    181173            if isinstance(app_name, BaseCommand): 
    182174                # If the command is already loaded, use it directly. 
     
    238230    def __init__(self, argv, project_directory): 
    239231        super(ProjectManagementUtility, self).__init__(argv) 
     232        self.project_directory = project_directory 
     233        self.user_commands = True 
    240234 
    241235def setup_environ(settings_mod):