我想将一个启动器脚本写入我的python qt应用程序。这个想法是它将运行git pull,pip install -r要求,启动真实应用程序然后退出。
我知道如何执行所有git / pip的东西,我知道有几种方法可以启动应用程序但是这里最好的做法是更新应用程序然后在不让用户做任何事情的情况下运行它。
应用程序安装在我们办公室的工作站上,所有工作站都运行安装了python的窗口。他们使用的应用程序是否使用在virtualenv中运行的git进行安装。
我过去所做的是检查db中的版本,如果版本不正确,那么运行git / pip进程并退出并向用户发送消息以重新启动应用程序。我宁愿只是重新启动应用程序。
TIA
答案 0 :(得分:1)
我建议使用项目自动设置工具,例如(fabric / fabtools):安装它们pip install fabric fabtools
在你的问题中,你没有指明你是想在本地运行这些东西,还是在远程服务器上运行,无论如何都可以找到以下两种情况:
from fabric.api import local, cd, run, env, roles
from fabric.context_managers import prefix
env.project_name = "project name"
env.repo = "your_repo.git"
REMOTEHOST = "Ip or domaine"
REMOTEUSER = "user"
REMOTEPASSWORD = "password"
env.roledefs.update({
"remote": [REMOTEHOST]
})
def remote():
"""Defines the Development Role
"""
env.user = REMOTEUSER
env.password = REMOTEPASSWORD
env.forward_agent = True # Your local machine has access, and the remote not, so you forward you identity to the
# remote, and then the remote gets access
def install_requirements(environment="local"):
"""Install the packages required by our each environment
"""
if environment == "local":
with cd("/your project/"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
run("pip install -r requirements/local.txt")
elif environment == "remote":
with cd("your project"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
run("pip install -r requirements/remote.txt")
def bootstrap_local():
"""Do your job locally
"""
env.warn_only = True
with cd("your directory"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
local("git checkout {0}".format("YOUR BRANCH"))
local("git pull origin {0}".format("YOUR BRANCH"))
install_requirements(environment="local")
local("the command line of the Application you wanna launch")
@roles('remote')
def bootstrap_remote():
"""do your job in the Remote server
"""
env.warn_only = True
remote()
with cd("your directory"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
run("git checkout {0}".format("YOUR BRANCH"))
run("git pull origin {0}".format("YOUR BRANCH"))
install_requirements(environment="remote")
run("the command line of the Application you wanna launch")
将此脚本写入“fabfile.py”后,从终端转到包含此脚本的目录,并执行以下操作:
fab bootstrap_local
以在本地运行作业fab bootstrap_remote
远程运行作业