Skip to content

Commit

Permalink
Fixed #5307 -- startproject/startapp now makes sure all files it crea…
Browse files Browse the repository at this point in the history
…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
adrianholovaty committed Aug 31, 2007
1 parent 33ab65d commit d09d142
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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/>
Expand Down
12 changes: 11 additions & 1 deletion django/core/management/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)

5 changes: 0 additions & 5 deletions django/core/management/commands/startproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d09d142

Please sign in to comment.