Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5943 -- Modified django-admin.py to work like manage.py whenev…

…er 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
  • Loading branch information...
commit 6b626800f8b282fe025f0cbe23f70ac6fb7f7aab 1 parent f110da9
@freakboy3742 freakboy3742 authored
Showing with 27 additions and 22 deletions.
  1. +27 −22 django/core/management/__init__.py
View
49 django/core/management/__init__.py
@@ -52,7 +52,7 @@ class instance. All errors raised by the importation process
return getattr(__import__('%s.management.commands.%s' % (app_name, name),
{}, {}, ['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
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
package are registered.
- Core commands are always included; user-defined commands will also
- be included if ``load_user_commands`` is True. If a project directory
- is provided, the startproject command will be disabled, and the
- startapp command will be modified to use that directory.
+ Core commands are always included. If a settings module has been
+ specified, user-defined commands will also be included, the
+ startproject command will be disabled, and the startapp command
+ will be modified to use the directory in which that module appears.
The dictionary is in the format {command_name: app_name}. Key-value
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:
_commands = dict([(name, 'django.core')
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
+ apps = settings.INSTALLED_APPS
+ except (AttributeError, EnvironmentError):
+ apps = []
+
+ for app_name in apps:
+ try:
+ 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
- for app_name in settings.INSTALLED_APPS:
- try:
- 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
+ project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
+ except (AttributeError, EnvironmentError, ImportError):
+ project_directory = None
if project_directory:
# Remove the "startproject" command from self.commands, because
@@ -146,8 +157,6 @@ class ManagementUtility(object):
def __init__(self, argv=None):
self.argv = argv or sys.argv[:]
self.prog_name = os.path.basename(self.argv[0])
- self.project_directory = None
- self.user_commands = False
def main_help_text(self):
"""
@@ -159,8 +168,7 @@ def main_help_text(self):
usage.append("Type '%s help <subcommand>' for help on a specific"
" subcommand." % self.prog_name)
usage.append('Available subcommands:')
- commands = get_commands(self.user_commands,
- self.project_directory).keys()
+ commands = get_commands().keys()
commands.sort()
for cmd in commands:
usage.append(' %s' % cmd)
@@ -173,8 +181,7 @@ def fetch_command(self, subcommand):
django-admin.py or manage.py) if it can't be found.
"""
try:
- app_name = get_commands(self.user_commands,
- self.project_directory)[subcommand]
+ app_name = get_commands()[subcommand]
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
klass = app_name
@@ -235,8 +242,6 @@ class ProjectManagementUtility(ManagementUtility):
"""
def __init__(self, argv, project_directory):
super(ProjectManagementUtility, self).__init__(argv)
- self.project_directory = project_directory
- self.user_commands = True
def setup_environ(settings_mod):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.