Fixed #5943 -- Modified django-admin.py to work like manage.py whenever a --settings option is provided. Thanksfor the patch, Todd O'Bryan.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6718 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f110da91db
commit
6b626800f8
|
@ -52,7 +52,7 @@ def load_command_class(app_name, name):
|
||||||
return getattr(__import__('%s.management.commands.%s' % (app_name, name),
|
return getattr(__import__('%s.management.commands.%s' % (app_name, name),
|
||||||
{}, {}, ['Command']), 'Command')()
|
{}, {}, ['Command']), 'Command')()
|
||||||
|
|
||||||
def get_commands(load_user_commands=True, project_directory=None):
|
def get_commands():
|
||||||
"""
|
"""
|
||||||
Returns a dictionary of commands against the application in which
|
Returns a dictionary of commands against the application in which
|
||||||
those commands can be found. This works by looking for a
|
those commands can be found. This works by looking for a
|
||||||
|
@ -60,10 +60,10 @@ def get_commands(load_user_commands=True, project_directory=None):
|
||||||
application -- if a commands package exists, all commands in that
|
application -- if a commands package exists, all commands in that
|
||||||
package are registered.
|
package are registered.
|
||||||
|
|
||||||
Core commands are always included; user-defined commands will also
|
Core commands are always included. If a settings module has been
|
||||||
be included if ``load_user_commands`` is True. If a project directory
|
specified, user-defined commands will also be included, the
|
||||||
is provided, the startproject command will be disabled, and the
|
startproject command will be disabled, and the startapp command
|
||||||
startapp command will be modified to use that directory.
|
will be modified to use the directory in which that module appears.
|
||||||
|
|
||||||
The dictionary is in the format {command_name: app_name}. Key-value
|
The dictionary is in the format {command_name: app_name}. Key-value
|
||||||
pairs from this dictionary can then be used in calls to
|
pairs from this dictionary can then be used in calls to
|
||||||
|
@ -80,16 +80,27 @@ def get_commands(load_user_commands=True, project_directory=None):
|
||||||
if _commands is None:
|
if _commands is None:
|
||||||
_commands = dict([(name, 'django.core')
|
_commands = dict([(name, 'django.core')
|
||||||
for name in find_commands(__path__[0])])
|
for name in find_commands(__path__[0])])
|
||||||
if load_user_commands:
|
# Get commands from all installed apps.
|
||||||
# Get commands from all installed apps.
|
try:
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
for app_name in settings.INSTALLED_APPS:
|
apps = settings.INSTALLED_APPS
|
||||||
try:
|
except (AttributeError, EnvironmentError):
|
||||||
path = find_management_module(app_name)
|
apps = []
|
||||||
_commands.update(dict([(name, app_name)
|
|
||||||
for name in find_commands(path)]))
|
for app_name in apps:
|
||||||
except ImportError:
|
try:
|
||||||
pass # No management module - ignore this app
|
path = find_management_module(app_name)
|
||||||
|
_commands.update(dict([(name, app_name)
|
||||||
|
for name in find_commands(path)]))
|
||||||
|
except ImportError:
|
||||||
|
pass # No management module - ignore this app
|
||||||
|
|
||||||
|
# Try to determine the project directory
|
||||||
|
try:
|
||||||
|
from django.conf import settings
|
||||||
|
project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
|
||||||
|
except (AttributeError, EnvironmentError, ImportError):
|
||||||
|
project_directory = None
|
||||||
|
|
||||||
if project_directory:
|
if project_directory:
|
||||||
# Remove the "startproject" command from self.commands, because
|
# Remove the "startproject" command from self.commands, because
|
||||||
|
@ -146,8 +157,6 @@ class ManagementUtility(object):
|
||||||
def __init__(self, argv=None):
|
def __init__(self, argv=None):
|
||||||
self.argv = argv or sys.argv[:]
|
self.argv = argv or sys.argv[:]
|
||||||
self.prog_name = os.path.basename(self.argv[0])
|
self.prog_name = os.path.basename(self.argv[0])
|
||||||
self.project_directory = None
|
|
||||||
self.user_commands = False
|
|
||||||
|
|
||||||
def main_help_text(self):
|
def main_help_text(self):
|
||||||
"""
|
"""
|
||||||
|
@ -159,8 +168,7 @@ class ManagementUtility(object):
|
||||||
usage.append("Type '%s help <subcommand>' for help on a specific"
|
usage.append("Type '%s help <subcommand>' for help on a specific"
|
||||||
" subcommand." % self.prog_name)
|
" subcommand." % self.prog_name)
|
||||||
usage.append('Available subcommands:')
|
usage.append('Available subcommands:')
|
||||||
commands = get_commands(self.user_commands,
|
commands = get_commands().keys()
|
||||||
self.project_directory).keys()
|
|
||||||
commands.sort()
|
commands.sort()
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
usage.append(' %s' % cmd)
|
usage.append(' %s' % cmd)
|
||||||
|
@ -173,8 +181,7 @@ class ManagementUtility(object):
|
||||||
django-admin.py or manage.py) if it can't be found.
|
django-admin.py or manage.py) if it can't be found.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
app_name = get_commands(self.user_commands,
|
app_name = get_commands()[subcommand]
|
||||||
self.project_directory)[subcommand]
|
|
||||||
if isinstance(app_name, BaseCommand):
|
if isinstance(app_name, BaseCommand):
|
||||||
# If the command is already loaded, use it directly.
|
# If the command is already loaded, use it directly.
|
||||||
klass = app_name
|
klass = app_name
|
||||||
|
@ -235,8 +242,6 @@ class ProjectManagementUtility(ManagementUtility):
|
||||||
"""
|
"""
|
||||||
def __init__(self, argv, project_directory):
|
def __init__(self, argv, project_directory):
|
||||||
super(ProjectManagementUtility, self).__init__(argv)
|
super(ProjectManagementUtility, self).__init__(argv)
|
||||||
self.project_directory = project_directory
|
|
||||||
self.user_commands = True
|
|
||||||
|
|
||||||
def setup_environ(settings_mod):
|
def setup_environ(settings_mod):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue