如何从 PyCharm 在远程主机上运行部署命令?

发布于 2024-11-15 21:00:06 字数 163 浏览 3 评论 0原文

我正在寻找一种直接从 PyCharm 简化 django 应用程序远程部署的方法。

即使部署文件本身仅适用于远程主机的文件并上传,我也无法找到在服务器站点上运行其他命令的方法(例如manage.pysyncdb)。

我正在寻找一种完全自动化的解决方案,只需单击(或命令)即可工作。

I am looking for a way to simplify remote deployment of a django application directly from PyCharm.

Even if deploying the files itself works just file with the remote host and upload, I was not able to find a way to run the additional commands on the server site (like manage.py syncdb).

I am looking for a fully automated solution, one that would work at single click (or command).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

金兰素衣 2024-11-22 21:00:06

我对 PyCharm 不太了解,所以也许你可以从 IDE 做一些事情,但我想你可能想看看 Fabric 项目 (http://docs.fabfile.org/en/1.0.1 /index.html)

这是一个非常棒的Python部署自动化工具。

这是我的结构脚本文件之一。请注意,我做了很多假设(这是我自己使用的),这些假设完全取决于您想要如何设置项目,例如我使用 virtualenv、pip 和 South 以及我个人对如何设置的偏好部署以及部署到哪里。

您可能需要重新设计或简化它以满足您的需求。

I don't know much about PyCharm so maybe you could do something from the IDE, but I think you'll probably want to take a look at the fabric project (http://docs.fabfile.org/en/1.0.1/index.html)

It's a python deployment automation tool that's pretty great.

Here is one of my fabric script files. Note that I make a lot of assumptions (This is my own that I use) that completely depend on how you want to set up your project, such as I use virtualenv, pip, and south as well as my own personal preference for how to deploy and where to deploy to.

You'll likely want to rework or simplify it to meet your needs.

岛歌少女 2024-11-22 21:00:06

您可以使用文件>设置>工具>外部工具运行任意外部可执行文件。您可以编写一个小命令来通过 SSH 连接并发出一组命令。然后配置的工具将是可执行的

例如,在我基于 tornado 的项目中,我使用 supervisord,根据 在此处回答,代码更改后无法重新启动。

我最终在 paramiko 上编写了一个小工具,它通过 ssh 连接并运行 supervisorctl restart.代码如下:

import paramiko
from optparse import OptionParser


parser = OptionParser()
parser.add_option("-s",
                  action="store",
                  dest="server",
                  help="server where to execute the command")
parser.add_option("-u",
                  action="store",
                  dest="username")
parser.add_option("-p",
                  action="store",
                  dest="password")

(options, args) = parser.parse_args()

client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect(hostname=options.server, port=22, username=options.username, password=options.password)
command = "supervisorctl reload"
(stdin, stdout, stderr) = client.exec_command(command)
for line in stdout.readlines():
        print line
client.close()

Pycharm中的外部工具配置:

  • 程序:
  • 参数:-s <服务器名称> -u <用户名> -p <密码>

You may use File > Settings > Tools > External Tools to run arbitrary external executable files. You may write a small command that connects over SSH and issues a [set of] command. Then the configured tool would be executable

For example, in my project based on tornado, I run the instances using supervisord, which, according to answer here, cannot restart upon code change.

I ended up writing a small tool on paramiko, that connects via ssh and runs supervisorctl restart. The code is below:

import paramiko
from optparse import OptionParser


parser = OptionParser()
parser.add_option("-s",
                  action="store",
                  dest="server",
                  help="server where to execute the command")
parser.add_option("-u",
                  action="store",
                  dest="username")
parser.add_option("-p",
                  action="store",
                  dest="password")

(options, args) = parser.parse_args()

client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect(hostname=options.server, port=22, username=options.username, password=options.password)
command = "supervisorctl reload"
(stdin, stdout, stderr) = client.exec_command(command)
for line in stdout.readlines():
        print line
client.close()

External Tool configuration in Pycharm:

  • program: <PYTHON_INTERPRETER>
  • parameters: <PATH_TO_SCRIPT> -s <SERVERNAME> -u <USERNAME> -p <PASSWORD>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文