Author: russellm
Date: 2007-11-26 06:32:57 -0600 (Mon, 26 Nov 2007)
New Revision: 6718

Modified:
   django/trunk/django/core/management/__init__.py
Log:
Fixed #5943 -- Modified django-admin.py to work like manage.py whenever a 
--settings option is provided. Thanksfor the patch, Todd O'Bryan.


Modified: django/trunk/django/core/management/__init__.py
===================================================================
--- django/trunk/django/core/management/__init__.py     2007-11-26 02:39:48 UTC 
(rev 6717)
+++ django/trunk/django/core/management/__init__.py     2007-11-26 12:32:57 UTC 
(rev 6718)
@@ -52,7 +52,7 @@
     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 @@
     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,17 +80,28 @@
     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
-            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
+            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
+            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
             # that's a django-admin.py command, not a manage.py command.
@@ -146,8 +157,6 @@
     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 @@
         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 @@
         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 @@
     """
     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):
     """


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to