Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5307 -- startproject/startapp now makes sure all files it crea…

…tes are writeable. Thanks, Thomas Stromberg

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6028 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d09d1428f885ce4686dfe6fc20b091f3b8e66de7 1 parent 33ab65d
@adrianholovaty adrianholovaty authored
View
1  AUTHORS
@@ -258,6 +258,7 @@ answer newbie questions, and generally made Django that much better:
Vasiliy Stavenko <stavenko@gmail.com>
Thomas Steinacher <http://www.eggdrop.ch/>
nowell strite
+ Thomas Stromberg <tstromberg@google.com>
Sundance
SuperJared
Radek Švarz <http://www.svarz.cz/translate/>
View
12 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 @@ def handle_noargs(self, **options):
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)
+
View
5 django/core/management/commands/startproject.py
@@ -28,11 +28,6 @@ def handle_label(self, project_name, **options):
# 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)
Please sign in to comment.
Something went wrong with that request. Please try again.