I'd like to create a file with the name passenger_wsgi.py on a remote host. I'd like to use the following string to create the file's content:
'''
import sys, os
sys.path.insert(0, "/ruby/%s/www/%s/django-projects")
sys.path.insert(0, "/ruby/%s/www/%s/django-projects/project")
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
application = django.core.handlers.wsgi.WSGIHandler()
''' % (user,host,user,host)
The user and host variables would be parameters of the fabric function.
I'm a total newbie to any sort of file manipulation in python, but also I'm not really sure what the procedure should be in fabric. Should I be creating the file locally and then uploading it with fabric's put command (and removing the local version afterwards)? Should I be creating the file on the remote host with an appropriate bash command (using fabric's run)? If so, then how is it best to deal with all the " and ' in the string - will fabric escape it? Or should I be tackling this in some different manner?
You could use append()
or upload_template()
functions from fabric.contrib.files