From d20a0834ac344ee79880c353d2c40639ee3837da Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 12 May 2009 21:45:03 +0000 Subject: Fixed #9751: admin scripts now calculate the project directory correctly when the settings module is a directory with an ``__init__.py``. Thanks to Eric Holscher. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10751 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/management/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'django') diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index f1192fe768..026e426862 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -105,10 +105,9 @@ def get_commands(): # Find the project directory try: from django.conf import settings - module = import_module(settings.SETTINGS_MODULE.split('.', 1)[0]) - project_directory = setup_environ(module, - settings.SETTINGS_MODULE) - except (AttributeError, EnvironmentError, ImportError): + module = import_module(settings.SETTINGS_MODULE) + project_directory = setup_environ(module, settings.SETTINGS_MODULE) + except (AttributeError, EnvironmentError, ImportError, KeyError): project_directory = None # Find and load the management module for each installed app. @@ -156,11 +155,11 @@ def call_command(name, *args, **options): raise CommandError, "Unknown command: %r" % name # Grab out a list of defaults from the options. optparse does this for us - # when the script runs from the command line, but since call_command can + # when the script runs from the command line, but since call_command can # be called programatically, we need to simulate the loading and handling # of defaults (see #10080 for details). defaults = dict([(o.dest, o.default) - for o in klass.option_list + for o in klass.option_list if o.default is not NO_DEFAULT]) defaults.update(options) @@ -316,7 +315,11 @@ def setup_environ(settings_mod, original_settings_path=None): # Add this project to sys.path so that it's importable in the conventional # way. For example, if this file (manage.py) lives in a directory # "myproject", this code would add "/path/to/myproject" to sys.path. - project_directory, settings_filename = os.path.split(settings_mod.__file__) + if '__init__.py' in settings_mod.__file__: + p = os.path.dirname(settings_mod.__file__) + else: + p = settings_mod.__file__ + project_directory, settings_filename = os.path.split(p) if project_directory == os.curdir or not project_directory: project_directory = os.getcwd() project_name = os.path.basename(project_directory) -- cgit v1.3