Changeset 6870
- Timestamp:
- 12/03/07 23:46:46 (1 year ago)
- Files:
-
- django/trunk/django/core/management/__init__.py (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/management/__init__.py
r6853 r6870 11 11 12 12 # A cache of loaded commands, so that call_command 13 # doesn't have to reload every time it is called13 # doesn't have to reload every time it's called. 14 14 _commands = None 15 15 … … 30 30 def find_management_module(app_name): 31 31 """ 32 Determines the path to the management module for the application named,33 without ac utally importing the application or the management module.32 Determines the path to the management module for the given app_name, 33 without actually importing the application or the management module. 34 34 35 35 Raises ImportError if the management module cannot be found for any reason. … … 47 47 """ 48 48 Given a command name and an application name, returns the Command 49 class instance. All errors raised by the import ationprocess49 class instance. All errors raised by the import process 50 50 (ImportError, AttributeError) are allowed to propagate. 51 51 """ … … 55 55 def get_commands(): 56 56 """ 57 Returns a dictionary of commands against the application in which58 those commands can be found. This works by looking for a 59 management.commands package in django.core, and in each installed60 application -- if a commands package exists, all commands in that61 package are registered.57 Returns a dictionary mapping command names to their callback applications. 58 59 This works by looking for a management.commands package in django.core, and 60 in each installed application -- if a commands package exists, all commands 61 in that package are registered. 62 62 63 63 Core commands are always included. If a settings module has been … … 74 74 dictionary in place of the application name. 75 75 76 The dictionary is cached on the first call ,and reused on subsequent76 The dictionary is cached on the first call and reused on subsequent 77 77 calls. 78 78 """ 79 79 global _commands 80 80 if _commands is None: 81 _commands = dict([(name, 'django.core') 82 for name in find_commands(__path__[0])]) 81 _commands = dict([(name, 'django.core') for name in find_commands(__path__[0])]) 83 82 # Get commands from all installed apps. 84 83 try: … … 91 90 try: 92 91 path = find_management_module(app_name) 93 _commands.update(dict([(name, app_name) 94 for name in find_commands(path)])) 92 _commands.update(dict([(name, app_name) for name in find_commands(path)])) 95 93 except ImportError: 96 94 pass # No management module - ignore this app … … 164 162 """ 165 163 usage = ['%s <subcommand> [options] [args]' % self.prog_name] 166 usage.append('Django command line tool,' 167 ' version %s' % django.get_version()) 168 usage.append("Type '%s help <subcommand>' for help on a specific" 169 " subcommand." % self.prog_name) 164 usage.append('Django command line tool, version %s' % django.get_version()) 165 usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name) 170 166 usage.append('Available subcommands:') 171 167 commands = get_commands().keys() … … 179 175 Tries to fetch the given subcommand, printing a message with the 180 176 appropriate command called from the command line (usually 181 django-admin.py or manage.py) if it can't be found.177 "django-admin.py" or "manage.py") if it can't be found. 182 178 """ 183 179 try: … … 189 185 klass = load_command_class(app_name, subcommand) 190 186 except KeyError: 191 sys.stderr.write("Unknown command: %r\nType '%s help' for "192 " usage.\n" %(subcommand, self.prog_name))187 sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % \ 188 (subcommand, self.prog_name)) 193 189 sys.exit(1) 194 190 return klass … … 202 198 # These options could affect the commands that are available, so they 203 199 # must be processed early. 204 parser = LaxOptionParser(version=get_version(), 205 option_list=BaseCommand.option_list) 200 parser = LaxOptionParser(version=get_version(), option_list=BaseCommand.option_list) 206 201 try: 207 202 options, args = parser.parse_args(self.argv) … … 264 259 265 260 # Set DJANGO_SETTINGS_MODULE appropriately. 266 os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, 267 settings_name) 261 os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) 268 262 return project_directory 269 263
