Property changes on: .
___________________________________________________________________
Name: svn:ignore
- build
dist
*.egg-info
MANIFEST
*.pyc
+ build
dist
*.egg-info
MANIFEST
*.pyc
.settings
.project
.pydevproject
|
|
|
|
| 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 of commands against the application in which |
| 58 | 58 | those commands can be found. This works by looking for a |
| … |
… |
|
| 60 | 60 | application -- if a commands package exists, all commands in that |
| 61 | 61 | package are registered. |
| 62 | 62 | |
| 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. |
| 67 | 67 | |
| 68 | 68 | The dictionary is in the format {command_name: app_name}. Key-value |
| 69 | 69 | pairs from this dictionary can then be used in calls to |
| … |
… |
|
| 80 | 80 | if _commands is None: |
| 81 | 81 | _commands = dict([(name, 'django.core') |
| 82 | 82 | 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: |
| 85 | 85 | 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 |
| 93 | 101 | |
| 94 | 102 | if project_directory: |
| 95 | 103 | # Remove the "startproject" command from self.commands, because |
| … |
… |
|
| 146 | 154 | def __init__(self, argv=None): |
| 147 | 155 | self.argv = argv or sys.argv[:] |
| 148 | 156 | self.prog_name = os.path.basename(self.argv[0]) |
| 149 | | self.project_directory = None |
| 150 | | self.user_commands = False |
| 151 | 157 | |
| 152 | 158 | def main_help_text(self): |
| 153 | 159 | """ |
| … |
… |
|
| 159 | 165 | usage.append("Type '%s help <subcommand>' for help on a specific" |
| 160 | 166 | " subcommand." % self.prog_name) |
| 161 | 167 | usage.append('Available subcommands:') |
| 162 | | commands = get_commands(self.user_commands, |
| 163 | | self.project_directory).keys() |
| | 168 | commands = get_commands().keys() |
| 164 | 169 | commands.sort() |
| 165 | 170 | for cmd in commands: |
| 166 | 171 | usage.append(' %s' % cmd) |
| … |
… |
|
| 173 | 178 | django-admin.py or manage.py) if it can't be found. |
| 174 | 179 | """ |
| 175 | 180 | try: |
| 176 | | app_name = get_commands(self.user_commands, |
| 177 | | self.project_directory)[subcommand] |
| | 181 | app_name = get_commands()[subcommand] |
| 178 | 182 | if isinstance(app_name, BaseCommand): |
| 179 | 183 | # If the command is already loaded, use it directly. |
| 180 | 184 | klass = app_name |
| … |
… |
|
| 235 | 239 | """ |
| 236 | 240 | def __init__(self, argv, project_directory): |
| 237 | 241 | super(ProjectManagementUtility, self).__init__(argv) |
| 238 | | self.project_directory = project_directory |
| 239 | | self.user_commands = True |
| 240 | 242 | |
| 241 | 243 | def setup_environ(settings_mod): |
| 242 | 244 | """ |