Ticket #5212: apps_command_management.diff
File apps_command_management.diff, 3.8 KB (added by , 17 years ago) |
---|
-
AUTHORS
294 294 ymasuda@ethercube.com 295 295 Jarek Zgoda <jarek.zgoda@gmail.com> 296 296 Cheng Zhang 297 Alberto Paro <alberto@ingparo.it> 297 298 298 299 A big THANK YOU goes to: 299 300 -
django/core/management/__init__.py
13 13 ImportError if it doesn't exist. 14 14 """ 15 15 # Let the ImportError propogate. 16 return getattr(__import__( 'django.core.management.commands.%s' %name, {}, {}, ['Command']), 'Command')()16 return getattr(__import__(name, {}, {}, ['Command']), 'Command')() 17 17 18 18 def call_command(name, *args, **options): 19 19 """ … … 26 26 call_command('shell', plain=True) 27 27 call_command('sqlall', 'myapp') 28 28 """ 29 klass = load_command_class( name)29 klass = load_command_class('django.core.management.commands.%s' % name) 30 30 return klass.execute(*args, **options) 31 31 32 32 class ManagementUtility(object): … … 50 50 """ 51 51 command_dir = os.path.join(__path__[0], 'commands') 52 52 names = [f[:-3] for f in os.listdir(command_dir) if not f.startswith('_') and f.endswith('.py')] 53 return dict([(name, load_command_class( name)) for name in names])53 return dict([(name, load_command_class('django.core.management.commands.%s' % name)) for name in names]) 54 54 55 def add_app_commands(self, appname): 56 """ 57 Populate the commands dictionary of all instances of all available Command classes in an application. 58 59 This works by looking for and loading all Python modules in the 60 applicatication management.commands package. 61 62 In a command with the same name is present an ApplicationException occurs. 63 """ 64 def get_app_commands_dir(command_module,file_scope): 65 """ Detect the path from the module name""" 66 module_pos=command_module 67 for attr in file_scope.split('.')[1:]: 68 module_pos=getattr(module_pos,attr) 69 return os.path.split(module_pos.__file__)[0] 70 71 # Search in the app for commands 72 try: 73 command_module = __import__('%s.management.commands' % appname, {}, {}) 74 except ImportError: 75 return 76 command_dir = get_app_commands_dir(command_module,'%s.management.commands' % appname) 77 names = [f[:-3] for f in os.listdir(command_dir) if not f.startswith('_') and f.endswith('.py')] 78 79 # Load the commands for the app 80 for name in names: 81 if name in self.commands: 82 raise ApplicationException('The command "" defined in already exist. '\ 83 'You cannot override an existing command' %\ 84 (name, '%s.management.commands.%s' % (appname, name))) 85 else: 86 self.commands[name] = load_command_class('%s.management.commands.%s' % (appname, name)) 87 55 88 def usage(self): 56 89 """ 57 90 Returns a usage string, for use with optparse. … … 143 176 # project_directory, not the current working directory (which is default). 144 177 from django.core.management.commands.startapp import ProjectCommand 145 178 self.commands['startapp'] = ProjectCommand(project_directory) 179 180 # Import project management commands from installed apps 181 for app in django.conf.settings.INSTALLED_APPS: 182 self.add_app_commands(app) 146 183 184 147 185 def setup_environ(settings_mod): 148 186 """ 149 187 Configure the runtime environment. This can also be used by external