Ticket #5307: patch.trunk

File patch.trunk, 2.2 KB (added by Thomas Stromberg <tstromberg@…>, 17 years ago)

Patch to implement said changes, including addition of _make_writeable()

Line 
1Index: core/management/commands/startproject.py
2===================================================================
3--- core/management/commands/startproject.py (revision 6026)
4+++ core/management/commands/startproject.py (working copy)
5@@ -28,11 +28,6 @@
6 # Create a random SECRET_KEY hash, and put it in the main settings.
7 main_settings_file = os.path.join(directory, project_name, 'settings.py')
8 settings_contents = open(main_settings_file, 'r').read()
9-
10- # If settings.py was copied from a read-only source, make it writeable.
11- if not os.access(main_settings_file, os.W_OK):
12- os.chmod(main_settings_file, 0600)
13-
14 fp = open(main_settings_file, 'w')
15 secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
16 settings_contents = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", settings_contents)
17Index: core/management/base.py
18===================================================================
19--- core/management/base.py (revision 6026)
20+++ core/management/base.py (working copy)
21@@ -1,6 +1,7 @@
22 from django.core.exceptions import ImproperlyConfigured
23 from django.core.management.color import color_style
24 import sys
25+import os
26
27 class CommandError(Exception):
28 pass
29@@ -121,7 +122,6 @@
30
31 def copy_helper(style, app_or_project, name, directory, other_name=''):
32 import django
33- import os
34 import re
35 import shutil
36 other = {'project': 'app', 'app': 'project'}[app_or_project]
37@@ -157,5 +157,15 @@
38 fp_new.close()
39 try:
40 shutil.copymode(path_old, path_new)
41+ _make_writeable(path_new)
42 except OSError:
43 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))
44+
45+def _make_writeable(filename):
46+ "Make sure that the file is writeable. Useful if our source is read-only"
47+ import stat
48+ if not os.access(filename, os.W_OK):
49+ st = os.stat(filename)
50+ new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
51+ os.chmod(filename, new_permissions)
52+
Back to Top