Ticket #5943: django-admin-settings-7229.diff

File django-admin-settings-7229.diff, 4.4 KB (added by jkocherhans, 16 years ago)
  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index d78e2ed..77511e7 100644
    a b def load_command_class(app_name, name):  
    5252    return getattr(__import__('%s.management.commands.%s' % (app_name, name),
    5353                   {}, {}, ['Command']), 'Command')()
    5454
    55 def get_commands(load_user_commands=True, project_directory=None):
     55def get_commands():
    5656    """
    5757    Returns a dictionary mapping command names to their callback applications.
    5858
    def get_commands(load_user_commands=True, project_directory=None):  
    6060    in each installed application -- if a commands package exists, all commands
    6161    in that package are registered.
    6262
    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
     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 
    6666    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
    def get_commands(load_user_commands=True, project_directory=None):  
    8080    if _commands is None:
    8181        _commands = dict([(name, 'django.core') for name in find_commands(__path__[0])])
    8282
    83         if load_user_commands:
     83        # Get commands from all installed apps.
     84        try:
    8485            # Get commands from all installed apps.
    8586            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) for name in find_commands(path)]))
    90                 except ImportError:
    91                     pass # No management module -- ignore this app.
     87            apps = settings.INSTALLED_APPS
     88        except (AttributeError, EnvironmentError):
     89            apps = []
     90        try:
     91            from django.conf import settings
     92            project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
     93        except (AttributeError, EnvironmentError, ImportError):
     94            project_directory = None
     95        for app_name in apps:
     96            try:
     97                path = find_management_module(app_name)
     98                _commands.update(dict([(name, app_name)
     99                                       for name in find_commands(path)]))
     100            except ImportError:
     101                pass # No management module - ignore this app
    92102
    93103        if project_directory:
    94104            # Remove the "startproject" command from self.commands, because
    class ManagementUtility(object):  
    145155    def __init__(self, argv=None):
    146156        self.argv = argv or sys.argv[:]
    147157        self.prog_name = os.path.basename(self.argv[0])
    148         self.project_directory = None
    149         self.user_commands = False
    150158
    151159    def main_help_text(self):
    152160        """
    class ManagementUtility(object):  
    156164        usage.append('Django command line tool, version %s' % django.get_version())
    157165        usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name)
    158166        usage.append('Available subcommands:')
    159         commands = get_commands(self.user_commands, self.project_directory).keys()
     167        commands = get_commands().keys()
    160168        commands.sort()
    161169        for cmd in commands:
    162170            usage.append('  %s' % cmd)
    class ManagementUtility(object):  
    169177        "django-admin.py" or "manage.py") if it can't be found.
    170178        """
    171179        try:
    172             app_name = get_commands(self.user_commands, self.project_directory)[subcommand]
     180            app_name = get_commands()[subcommand]
    173181            if isinstance(app_name, BaseCommand):
    174182                # If the command is already loaded, use it directly.
    175183                klass = app_name
    class ProjectManagementUtility(ManagementUtility):  
    229237    """
    230238    def __init__(self, argv, project_directory):
    231239        super(ProjectManagementUtility, self).__init__(argv)
    232         self.project_directory = project_directory
    233         self.user_commands = True
    234240
    235241def setup_environ(settings_mod):
    236242    """
Back to Top