如何创建织物(蟒蛇部署工具)远程主机上的一个新的文件? [英] How do I create a new file on a remote host in fabric (python deployment tool)?

查看:160
本文介绍了如何创建织物(蟒蛇部署工具)远程主机上的一个新的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在远程主机上创建一个名为passenger_wsgi.py的文件。我想用以下字符串创建该文件的内容:

 '''
进口SYS,OSsys.path.insert(0/红宝石/%S / WWW /%S / Django的项目)。
sys.path.insert(0/红宝石/%S / WWW /%S / Django的项目/工程)进口django.core.handlers.wsgi
os.environ ['DJANGO_SETTINGS_MODULE'] ='project.settings'
应用= django.core.handlers.wsgi.WSGIHandler()
'''%(用户,主机,用户,主机)

用户和主机变量是织物功能的参数。

我是一个总的新手到任何类型的python中的文件操作,还我真的不知道该程序应面料的东西。我应该本地创建该文件,然后用布的put命令上传(事后删除本地版本)?我应该是(用布的运行)用适当的bash命令创建远程主机上的文件吗?如果是这样,那么它是如何最好地处理所有的和字符串中 - ?将布逃脱它还是应该我在一些不同的方式来解决这个


解决方案

您可以使用追加() upload_template()通过 fabric.contrib.files

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

这篇关于如何创建织物(蟒蛇部署工具)远程主机上的一个新的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆