Ticket #5943: django-admin-settings.patch

File django-admin-settings.patch, 4.5 KB (added by Todd O'Bryan, 17 years ago)
  • django/core/management/__init__.py

    Property changes on: .
    ___________________________________________________________________
    Name: svn:ignore
       - build
    dist
    *.egg-info
    MANIFEST
    *.pyc
    
       + build
    dist
    *.egg-info
    MANIFEST
    *.pyc
    .settings
    .project
    .pydevproject
    
    
     
    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 of commands against the application in which
    5858    those commands can be found. This works by looking for a
     
    6060    application -- if a commands package exists, all commands in that
    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
    6969    pairs from this dictionary can then be used in calls to
     
    8080    if _commands is None:
    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        try:
     90            from django.conf import settings
     91            project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
     92        except (AttributeError, EnvironmentError, ImportError):
     93            project_directory = None
     94        for app_name in apps:
     95            try:
     96                path = find_management_module(app_name)
     97                _commands.update(dict([(name, app_name)
     98                                       for name in find_commands(path)]))
     99            except ImportError:
     100                pass # No management module - ignore this app
    93101
    94102        if project_directory:
    95103            # Remove the "startproject" command from self.commands, because
     
    146154    def __init__(self, argv=None):
    147155        self.argv = argv or sys.argv[:]
    148156        self.prog_name = os.path.basename(self.argv[0])
    149         self.project_directory = None
    150         self.user_commands = False
    151157
    152158    def main_help_text(self):
    153159        """
     
    159165        usage.append("Type '%s help <subcommand>' for help on a specific"
    160166                     " subcommand." % self.prog_name)
    161167        usage.append('Available subcommands:')
    162         commands = get_commands(self.user_commands,
    163                                 self.project_directory).keys()
     168        commands = get_commands().keys()
    164169        commands.sort()
    165170        for cmd in commands:
    166171            usage.append('  %s' % cmd)
     
    173178        django-admin.py or manage.py) if it can't be found.
    174179        """
    175180        try:
    176             app_name = get_commands(self.user_commands,
    177                                     self.project_directory)[subcommand]
     181            app_name = get_commands()[subcommand]
    178182            if isinstance(app_name, BaseCommand):
    179183                # If the command is already loaded, use it directly.
    180184                klass = app_name
     
    235239    """
    236240    def __init__(self, argv, project_directory):
    237241        super(ProjectManagementUtility, self).__init__(argv)
    238         self.project_directory = project_directory
    239         self.user_commands = True
    240242
    241243def setup_environ(settings_mod):
    242244    """
Back to Top