Code

Ticket #4688: django-core-management.patch

File django-core-management.patch, 850 bytes (added by tstromberg@…, 7 years ago)

Patch to check and fix permissions on settings.py if necessary

  • core/management.py

     
    835835    # Create a random SECRET_KEY hash, and put it in the main settings. 
    836836    main_settings_file = os.path.join(directory, project_name, 'settings.py') 
    837837    settings_contents = open(main_settings_file, 'r').read() 
     838      
     839    # We may have copied from a read-only source, so lets make settings.py writeable if so.  
     840    if not os.access(main_settings_file, os.W_OK): 
     841      os.chmod(main_settings_file, 0600) 
     842     
    838843    fp = open(main_settings_file, 'w') 
    839844    secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) 
    840845    settings_contents = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", settings_contents)