mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #15372 -- Switched to a startproject default layout that allows us to avoid sys.path hacks.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16964 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import sys
|
||||
from optparse import OptionParser, NO_DEFAULT
|
||||
import imp
|
||||
import warnings
|
||||
|
||||
import django
|
||||
from django.core.management.base import BaseCommand, CommandError, handle_default_options
|
||||
@@ -102,14 +103,6 @@ def get_commands():
|
||||
except (AttributeError, EnvironmentError, ImportError):
|
||||
apps = []
|
||||
|
||||
# Find the project directory
|
||||
try:
|
||||
from django.conf import settings
|
||||
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.
|
||||
for app_name in apps:
|
||||
try:
|
||||
@@ -119,17 +112,6 @@ def get_commands():
|
||||
except ImportError:
|
||||
pass # No management module - ignore this app
|
||||
|
||||
if project_directory:
|
||||
# Remove the "startproject" command from self.commands, because
|
||||
# that's a django-admin.py command, not a manage.py command.
|
||||
del _commands['startproject']
|
||||
|
||||
# Override the startapp command so that it always uses the
|
||||
# project_directory, not the current working directory
|
||||
# (which is default).
|
||||
from django.core.management.commands.startapp import ProjectCommand
|
||||
_commands['startapp'] = ProjectCommand(project_directory)
|
||||
|
||||
return _commands
|
||||
|
||||
def call_command(name, *args, **options):
|
||||
@@ -388,6 +370,13 @@ def setup_environ(settings_mod, original_settings_path=None):
|
||||
The "original_settings_path" parameter is optional, but recommended, since
|
||||
trying to work out the original path from the module can be problematic.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'setup_environ' function is deprecated, "
|
||||
"you likely need to update your 'manage.py'; "
|
||||
"please see the Django 1.4 release notes "
|
||||
"(https://docs.djangoproject.com/en/dev/releases/1.4/).",
|
||||
PendingDeprecationWarning)
|
||||
|
||||
# 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.
|
||||
@@ -437,6 +426,13 @@ def execute_manager(settings_mod, argv=None):
|
||||
Like execute_from_command_line(), but for use by manage.py, a
|
||||
project-specific django-admin.py utility.
|
||||
"""
|
||||
warnings.warn(
|
||||
"The 'execute_manager' function is deprecated, "
|
||||
"you likely need to update your 'manage.py'; "
|
||||
"please see the Django 1.4 release notes "
|
||||
"(https://docs.djangoproject.com/en/dev/releases/1.4/).",
|
||||
PendingDeprecationWarning)
|
||||
|
||||
setup_environ(settings_mod)
|
||||
utility = ManagementUtility(argv)
|
||||
utility.execute()
|
||||
|
||||
@@ -15,8 +15,6 @@ class Command(LabelCommand):
|
||||
can_import_settings = False
|
||||
|
||||
def handle_label(self, project_name, **options):
|
||||
# Determine the project_name a bit naively -- by looking at the name of
|
||||
# the parent directory.
|
||||
directory = os.getcwd()
|
||||
|
||||
# Check that the project_name cannot be imported.
|
||||
@@ -30,7 +28,7 @@ class Command(LabelCommand):
|
||||
copy_helper(self.style, 'project', project_name, directory)
|
||||
|
||||
# Create a random SECRET_KEY hash, and put it in the main settings.
|
||||
main_settings_file = os.path.join(directory, project_name, 'settings.py')
|
||||
main_settings_file = os.path.join(directory, project_name, project_name, 'settings.py')
|
||||
settings_contents = open(main_settings_file, 'r').read()
|
||||
fp = open(main_settings_file, 'w')
|
||||
secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
|
||||
|
||||
Reference in New Issue
Block a user