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):
|
| 52 | 52 | return getattr(__import__('%s.management.commands.%s' % (app_name, name), |
| 53 | 53 | {}, {}, ['Command']), 'Command')() |
| 54 | 54 | |
| 55 | | def get_commands(load_user_commands=True, project_directory=None): |
| | 55 | def get_commands(): |
| 56 | 56 | """ |
| 57 | 57 | Returns a dictionary mapping command names to their callback applications. |
| 58 | 58 | |
| … |
… |
def get_commands(load_user_commands=True, project_directory=None):
|
| 60 | 60 | in each installed application -- if a commands package exists, all commands |
| 61 | 61 | in that package are registered. |
| 62 | 62 | |
| 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 |
| 66 | 66 | will be modified to use the directory in which that module appears. |
| 67 | 67 | |
| 68 | 68 | The dictionary is in the format {command_name: app_name}. Key-value |
| … |
… |
def get_commands(load_user_commands=True, project_directory=None):
|
| 80 | 80 | if _commands is None: |
| 81 | 81 | _commands = dict([(name, 'django.core') for name in find_commands(__path__[0])]) |
| 82 | 82 | |
| 83 | | if load_user_commands: |
| | 83 | # Get commands from all installed apps. |
| | 84 | try: |
| 84 | 85 | # Get commands from all installed apps. |
| 85 | 86 | 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 |
| 92 | 102 | |
| 93 | 103 | if project_directory: |
| 94 | 104 | # Remove the "startproject" command from self.commands, because |
| … |
… |
class ManagementUtility(object):
|
| 145 | 155 | def __init__(self, argv=None): |
| 146 | 156 | self.argv = argv or sys.argv[:] |
| 147 | 157 | self.prog_name = os.path.basename(self.argv[0]) |
| 148 | | self.project_directory = None |
| 149 | | self.user_commands = False |
| 150 | 158 | |
| 151 | 159 | def main_help_text(self): |
| 152 | 160 | """ |
| … |
… |
class ManagementUtility(object):
|
| 156 | 164 | usage.append('Django command line tool, version %s' % django.get_version()) |
| 157 | 165 | usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name) |
| 158 | 166 | usage.append('Available subcommands:') |
| 159 | | commands = get_commands(self.user_commands, self.project_directory).keys() |
| | 167 | commands = get_commands().keys() |
| 160 | 168 | commands.sort() |
| 161 | 169 | for cmd in commands: |
| 162 | 170 | usage.append(' %s' % cmd) |
| … |
… |
class ManagementUtility(object):
|
| 169 | 177 | "django-admin.py" or "manage.py") if it can't be found. |
| 170 | 178 | """ |
| 171 | 179 | try: |
| 172 | | app_name = get_commands(self.user_commands, self.project_directory)[subcommand] |
| | 180 | app_name = get_commands()[subcommand] |
| 173 | 181 | if isinstance(app_name, BaseCommand): |
| 174 | 182 | # If the command is already loaded, use it directly. |
| 175 | 183 | klass = app_name |
| … |
… |
class ProjectManagementUtility(ManagementUtility):
|
| 229 | 237 | """ |
| 230 | 238 | def __init__(self, argv, project_directory): |
| 231 | 239 | super(ProjectManagementUtility, self).__init__(argv) |
| 232 | | self.project_directory = project_directory |
| 233 | | self.user_commands = True |
| 234 | 240 | |
| 235 | 241 | def setup_environ(settings_mod): |
| 236 | 242 | """ |