Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rolled out [5923]-[5925] due to breaking call_command().

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5929 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 04c77db2c3c179b4d768c8809540768a81291457 1 parent 3b42139
Russell Keith-Magee authored August 18, 2007
52  django/core/management/__init__.py
@@ -7,25 +7,13 @@
7 7
 # For backwards compatibility: get_version() used to be in this module.
8 8
 get_version = django.get_version
9 9
 
10  
-def find_commands(path):
11  
-    """
12  
-    Given a path to a management directory, return a list of all the command names 
13  
-    that are available. Returns an empty list if no commands are defined.
14  
-    """
15  
-    command_dir = os.path.join(path, 'commands')
16  
-    try:
17  
-        return [f[:-3] for f in os.listdir(command_dir) if not f.startswith('_') and f.endswith('.py')]
18  
-    except OSError:
19  
-        return []
20  
-
21  
-def load_command_class(module, name):
  10
+def load_command_class(name):
22 11
     """
23 12
     Given a command name, returns the Command class instance. Raises
24  
-    Raises ImportError if a command module doesn't exist, or AttributeError
25  
-    if a command module doesn't contain a Command instance.
  13
+    ImportError if it doesn't exist.
26 14
     """
27  
-    # Let any errors propogate.
28  
-    return getattr(__import__('%s.management.commands.%s' % (module, name), {}, {}, ['Command']), 'Command')()
  15
+    # Let the ImportError propogate.
  16
+    return getattr(__import__('django.core.management.commands.%s' % name, {}, {}, ['Command']), 'Command')()
29 17
 
30 18
 def call_command(name, *args, **options):
31 19
     """
@@ -60,8 +48,9 @@ def default_commands(self):
60 48
 
61 49
         The dictionary is in the format {name: command_instance}.
62 50
         """
63  
-        return dict([(name, load_command_class('django.core',name)) 
64  
-                        for name in find_commands(__path__[0])])
  51
+        command_dir = os.path.join(__path__[0], 'commands')
  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])
65 54
 
66 55
     def usage(self):
67 56
         """
@@ -155,33 +144,6 @@ def __init__(self, project_directory):
155 144
         from django.core.management.commands.startapp import ProjectCommand
156 145
         self.commands['startapp'] = ProjectCommand(project_directory)
157 146
 
158  
-    def default_commands(self):
159  
-        """
160  
-        Returns a dictionary of instances of all available Command classes.
161  
-
162  
-        This works by looking for and loading all Python modules in the
163  
-        django.core.management.commands package. It also looks for a
164  
-        management.commands package in each installed application -- if
165  
-        a commands package exists, it loads all commands in that application.
166  
-
167  
-        The dictionary is in the format {name: command_instance}.
168  
-        """
169  
-        from django.db import models
170  
-
171  
-        # Base command set
172  
-        commands = super(ProjectManagementUtility, self).default_commands()
173  
-        
174  
-        # Get commands from all installed apps
175  
-        for app in models.get_apps():
176  
-            try:
177  
-                app_name = '.'.join(app.__name__.split('.')[:-1])
178  
-                path = os.path.join(os.path.dirname(app.__file__),'management')
179  
-                commands.update(dict([(name, load_command_class(app_name,name)) for name in find_commands(path)]))
180  
-            except AttributeError:
181  
-                sys.stderr.write("Management command '%s' in application '%s' doesn't contain a Command instance.\n" % (name, app_name))
182  
-                sys.exit(1)
183  
-        return commands
184  
-
185 147
 def setup_environ(settings_mod):
186 148
     """
187 149
     Configure the runtime environment. This can also be used by external
29  docs/django-admin.txt
@@ -603,32 +603,3 @@ distribution. It enables tab-completion of ``django-admin.py`` and
603 603
     * Press [TAB] to see all available options.
604 604
     * Type ``sql``, then [TAB], to see all available options whose names start
605 605
       with ``sql``.
606  
-
607  
-Customized actions
608  
-==================
609  
-
610  
-**New in Django development version**
611  
-
612  
-If you want to add an action of your own to ``manage.py``, you can.
613  
-Simply add a ``management/commands`` directory to your application.
614  
-Each python file in that directory will be discovered and registered as
615  
-a command that can be executed as an action when you run ``manage.py``::
616  
-
617  
-    /fancy_blog
618  
-        __init__.py
619  
-        models.py
620  
-        /management
621  
-            __init__.py
622  
-            /commands
623  
-                __init__.py
624  
-                explode.py
625  
-        views.py
626  
-        
627  
-In this example, ``explode`` command will be made available to any project
628  
-that includes the ``fancy_blog`` application in ``settings.INSTALLED_APPS``.
629  
-
630  
-The ``explode.py`` file has only one requirement -- it must define a class
631  
-called ``Command`` that extends ``django.core.management.base.BaseCommand``.
632  
-
633  
-For more details on how to define your own commands, look at the code for the
634  
-existing ``django-admin.py`` commands, in ``/django/core/management/commands``.

0 notes on commit 04c77db

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