summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-31 04:35:03 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-31 04:35:03 +0000
commitd09d1428f885ce4686dfe6fc20b091f3b8e66de7 (patch)
tree8e8a8b4e04a5415584bd96206bcbd247a46ba411
parent33ab65dd1e004ebc8fb4d85d8c2ded2187b7c961 (diff)
Fixed #5307 -- startproject/startapp now makes sure all files it creates are writeable. Thanks, Thomas Stromberg
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6028 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--AUTHORS1
-rw-r--r--django/core/management/base.py12
-rw-r--r--django/core/management/commands/startproject.py5
3 files changed, 12 insertions, 6 deletions
diff --git a/AUTHORS b/AUTHORS
index 311c96c8ea..554f8325a7 100644
--- a/AUTHORS
+++ b/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/>
diff --git a/django/core/management/base.py b/django/core/management/base.py
index 173850716c..978aa7902a 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 0d9e4bd381..ab4f409f15 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)