diff --git a/AUTHORS b/AUTHORS index 311c96c8ea1..554f8325a71 100644 --- a/AUTHORS +++ b/AUTHORS @@ -258,6 +258,7 @@ answer newbie questions, and generally made Django that much better: Vasiliy Stavenko Thomas Steinacher nowell strite + Thomas Stromberg Sundance SuperJared Radek Švarz diff --git a/django/core/management/base.py b/django/core/management/base.py index 173850716cb..978aa7902a4 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -1,6 +1,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.management.color import color_style import sys +import os class CommandError(Exception): pass @@ -121,7 +122,6 @@ class NoArgsCommand(BaseCommand): def copy_helper(style, app_or_project, name, directory, other_name=''): import django - import os import re import shutil other = {'project': 'app', 'app': 'project'}[app_or_project] @@ -157,5 +157,15 @@ def copy_helper(style, app_or_project, name, directory, other_name=''): fp_new.close() try: shutil.copymode(path_old, path_new) + _make_writeable(path_new) except OSError: sys.stderr.write(style.NOTICE("Notice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.\n" % path_new)) + +def _make_writeable(filename): + "Makes sure that the file is writeable. Useful if our source is read-only." + import stat + if not os.access(filename, os.W_OK): + st = os.stat(filename) + new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR + os.chmod(filename, new_permissions) + diff --git a/django/core/management/commands/startproject.py b/django/core/management/commands/startproject.py index 0d9e4bd3818..ab4f409f150 100644 --- a/django/core/management/commands/startproject.py +++ b/django/core/management/commands/startproject.py @@ -28,11 +28,6 @@ class Command(LabelCommand): # Create a random SECRET_KEY hash, and put it in the main settings. main_settings_file = os.path.join(directory, project_name, 'settings.py') settings_contents = open(main_settings_file, 'r').read() - - # If settings.py was copied from a read-only source, make it writeable. - if not os.access(main_settings_file, os.W_OK): - os.chmod(main_settings_file, 0600) - fp = open(main_settings_file, 'w') secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) settings_contents = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", settings_contents)