Ticket #5943: django-admin-commands.diff
File django-admin-commands.diff, 3.9 KB (added by , 17 years ago) |
---|
-
django/core/management/__init__.py
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 … … 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 … … 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 = None149 self.user_commands = False150 158 151 159 def main_help_text(self): 152 160 """ … … 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) … … 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 … … 229 237 """ 230 238 def __init__(self, argv, project_directory): 231 239 super(ProjectManagementUtility, self).__init__(argv) 232 self.project_directory = project_directory233 self.user_commands = True234 240 235 241 def setup_environ(settings_mod): 236 242 """ … … 251 257 project_module = __import__(project_name, {}, {}, ['']) 252 258 sys.path.pop() 253 259 254 # Set DJANGO_SETTINGS_MODULE appropriately. 255 os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) 260 # Set DJANGO_SETTINGS_MODULE appropriately if it hasn't already been set. 261 if not os.environ.has_key('DJANGO_SETTINGS_MODULE'): 262 os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) 256 263 return project_directory 257 264 258 265 def execute_from_command_line(argv=None):