Changeset 6718
- Timestamp:
- 11/26/07 06:32:57 (1 year ago)
- Files:
-
- django/trunk/django/core/management/__init__.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management/__init__.py
r6620 r6718 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 … … 61 61 package are registered. 62 62 63 Core commands are always included ; user-defined commands will also64 be included if ``load_user_commands`` is True. If a project directory65 is provided, the startproject command will be disabled, and the66 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 … … 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 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 93 104 94 105 if project_directory: … … 147 158 self.argv = argv or sys.argv[:] 148 159 self.prog_name = os.path.basename(self.argv[0]) 149 self.project_directory = None150 self.user_commands = False151 160 152 161 def main_help_text(self): … … 160 169 " subcommand." % self.prog_name) 161 170 usage.append('Available subcommands:') 162 commands = get_commands(self.user_commands, 163 self.project_directory).keys() 171 commands = get_commands().keys() 164 172 commands.sort() 165 173 for cmd in commands: … … 174 182 """ 175 183 try: 176 app_name = get_commands(self.user_commands, 177 self.project_directory)[subcommand] 184 app_name = get_commands()[subcommand] 178 185 if isinstance(app_name, BaseCommand): 179 186 # If the command is already loaded, use it directly. … … 236 243 def __init__(self, argv, project_directory): 237 244 super(ProjectManagementUtility, self).__init__(argv) 238 self.project_directory = project_directory239 self.user_commands = True240 245 241 246 def setup_environ(settings_mod):
