Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Undid [6718], as it broke 'django-admin.py runserver' for a reason I …

…haven't figured out yet

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6871 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0c8f8f27fb28343b958fd3f12ebd17060854c420 1 parent dca16b2
Adrian Holovaty authored December 04, 2007

Showing 1 changed file with 16 additions and 22 deletions. Show diff stats Hide diff stats

  1. 38  django/core/management/__init__.py
38  django/core/management/__init__.py
@@ -52,7 +52,7 @@ class instance. All errors raised by the import process
52 52
     return getattr(__import__('%s.management.commands.%s' % (app_name, name),
53 53
                    {}, {}, ['Command']), 'Command')()
54 54
 
55  
-def get_commands():
  55
+def get_commands(load_user_commands=True, project_directory=None):
56 56
     """
57 57
     Returns a dictionary mapping command names to their callback applications.
58 58
 
@@ -79,26 +79,16 @@ def get_commands():
79 79
     global _commands
80 80
     if _commands is None:
81 81
         _commands = dict([(name, 'django.core') for name in find_commands(__path__[0])])
82  
-        # Get commands from all installed apps.
83  
-        try:
84  
-            from django.conf import settings
85  
-            apps = settings.INSTALLED_APPS
86  
-        except (AttributeError, ImportError):
87  
-            apps = []
88  
-
89  
-        for app_name in apps:
90  
-            try:
91  
-                path = find_management_module(app_name)
92  
-                _commands.update(dict([(name, app_name) for name in find_commands(path)]))
93  
-            except ImportError:
94  
-                pass # No management module - ignore this app
95  
-
96  
-        # Try to determine the project directory
97  
-        try:
  82
+
  83
+        if load_user_commands:
  84
+            # Get commands from all installed apps.
98 85
             from django.conf import settings
99  
-            project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
100  
-        except (AttributeError, ImportError):
101  
-            project_directory = None
  86
+            for app_name in settings.INSTALLED_APPS:
  87
+                try:
  88
+                    path = find_management_module(app_name)
  89
+                    _commands.update(dict([(name, app_name) for name in find_commands(path)]))
  90
+                except ImportError:
  91
+                    pass # No management module -- ignore this app.
102 92
 
103 93
         if project_directory:
104 94
             # Remove the "startproject" command from self.commands, because
@@ -155,6 +145,8 @@ class ManagementUtility(object):
155 145
     def __init__(self, argv=None):
156 146
         self.argv = argv or sys.argv[:]
157 147
         self.prog_name = os.path.basename(self.argv[0])
  148
+        self.project_directory = None
  149
+        self.user_commands = False
158 150
 
159 151
     def main_help_text(self):
160 152
         """
@@ -164,7 +156,7 @@ def main_help_text(self):
164 156
         usage.append('Django command line tool, version %s' % django.get_version())
165 157
         usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name)
166 158
         usage.append('Available subcommands:')
167  
-        commands = get_commands().keys()
  159
+        commands = get_commands(self.user_commands, self.project_directory).keys()
168 160
         commands.sort()
169 161
         for cmd in commands:
170 162
             usage.append('  %s' % cmd)
@@ -177,7 +169,7 @@ def fetch_command(self, subcommand):
177 169
         "django-admin.py" or "manage.py") if it can't be found.
178 170
         """
179 171
         try:
180  
-            app_name = get_commands()[subcommand]
  172
+            app_name = get_commands(self.user_commands, self.project_directory)[subcommand]
181 173
             if isinstance(app_name, BaseCommand):
182 174
                 # If the command is already loaded, use it directly.
183 175
                 klass = app_name
@@ -237,6 +229,8 @@ class ProjectManagementUtility(ManagementUtility):
237 229
     """
238 230
     def __init__(self, argv, project_directory):
239 231
         super(ProjectManagementUtility, self).__init__(argv)
  232
+        self.project_directory = project_directory
  233
+        self.user_commands = True
240 234
 
241 235
 def setup_environ(settings_mod):
242 236
     """

0 notes on commit 0c8f8f2

Please sign in to comment.
Something went wrong with that request. Please try again.