Django

Code

Changeset 6718

Show
Ignore:
Timestamp:
11/26/07 06:32:57 (1 year ago)
Author:
russellm
Message:

Fixed #5943 -- Modified django-admin.py to work like manage.py whenever a --settings option is provided. Thanksfor the patch, Todd O'Bryan.

Files:

Legend:

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

    r6620 r6718  
    5353                   {}, {}, ['Command']), 'Command')() 
    5454 
    55 def get_commands(load_user_commands=True, project_directory=None): 
     55def get_commands(): 
    5656    """ 
    5757    Returns a dictionary of commands against the application in which 
     
    6161    package are registered. 
    6262 
    63     Core commands are always included; user-defined commands will also 
    64     be included if ``load_user_commands`` is True. If a project directory 
    65     is provided, the startproject command will be disabled, and the 
    66     startapp command will be modified to use that directory
     63    Core commands are always included. If a settings module has been 
     64    specified, user-defined commands will also be included, the 
     65    startproject command will be disabled, and the startapp command 
     66    will be modified to use the directory in which that module appears
    6767 
    6868    The dictionary is in the format {command_name: app_name}. Key-value 
     
    8181        _commands = dict([(name, 'django.core') 
    8282                          for name in find_commands(__path__[0])]) 
    83         if load_user_commands: 
    84             # Get commands from all installed apps. 
     83        # Get commands from all installed apps. 
     84        try: 
    8585            from django.conf import settings 
    86             for app_name in settings.INSTALLED_APPS: 
    87                 try: 
    88                     path = find_management_module(app_name) 
    89                     _commands.update(dict([(name, app_name) 
    90                                            for name in find_commands(path)])) 
    91                 except ImportError: 
    92                     pass # No management module - ignore this app 
     86            apps = settings.INSTALLED_APPS 
     87        except (AttributeError, EnvironmentError): 
     88            apps = [] 
     89 
     90        for app_name in apps: 
     91            try: 
     92                path = find_management_module(app_name) 
     93                _commands.update(dict([(name, app_name) 
     94                                       for name in find_commands(path)])) 
     95            except ImportError: 
     96                pass # No management module - ignore this app 
     97 
     98        # Try to determine the project directory 
     99        try: 
     100            from django.conf import settings 
     101            project_directory = setup_environ(__import__(settings.SETTINGS_MODULE)) 
     102        except (AttributeError, EnvironmentError, ImportError): 
     103            project_directory = None 
    93104 
    94105        if project_directory: 
     
    147158        self.argv = argv or sys.argv[:] 
    148159        self.prog_name = os.path.basename(self.argv[0]) 
    149         self.project_directory = None 
    150         self.user_commands = False 
    151160 
    152161    def main_help_text(self): 
     
    160169                     " subcommand." % self.prog_name) 
    161170        usage.append('Available subcommands:') 
    162         commands = get_commands(self.user_commands, 
    163                                 self.project_directory).keys() 
     171        commands = get_commands().keys() 
    164172        commands.sort() 
    165173        for cmd in commands: 
     
    174182        """ 
    175183        try: 
    176             app_name = get_commands(self.user_commands, 
    177                                     self.project_directory)[subcommand] 
     184            app_name = get_commands()[subcommand] 
    178185            if isinstance(app_name, BaseCommand): 
    179186                # If the command is already loaded, use it directly. 
     
    236243    def __init__(self, argv, project_directory): 
    237244        super(ProjectManagementUtility, self).__init__(argv) 
    238         self.project_directory = project_directory 
    239         self.user_commands = True 
    240245 
    241246def setup_environ(settings_mod):