1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #5516 -- Added the ability for applications to define their own management commands. Pieces of this patch taken from a contribution by Todd O'Bryan. Thanks Todd.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6400 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2007-09-21 16:19:20 +00:00
parent 2570954a9a
commit 302eeaf190
8 changed files with 203 additions and 40 deletions

View File

@@ -9,6 +9,17 @@ import os
class CommandError(Exception):
pass
def handle_default_options(options):
"""
Include any default options that all commands should accept
here so that ManagementUtility can handle them before searching
for user commands.
"""
if options.settings:
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
if options.pythonpath:
sys.path.insert(0, options.pythonpath)
class BaseCommand(object):
# Metadata about this command.
option_list = (
@@ -55,10 +66,7 @@ class BaseCommand(object):
def run_from_argv(self, argv):
parser = self.create_parser(argv[0], argv[1])
options, args = parser.parse_args(argv[2:])
if options.settings:
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
if options.pythonpath:
sys.path.insert(0, options.pythonpath)
handle_default_options(options)
self.execute(*args, **options.__dict__)
def execute(self, *args, **options):