2017-05-04 49 views
0

我想寫一個啓動腳本到我有的python qt應用程序。這個想法是,它會運行git pull,pip install -r要求,啓動真正的應用程序,然後退出。運行git pull然後啓動真實應用程序的Python啓動程序

我知道如何做所有的git/pip的東西,我知道一些啓動應用程序的方法,但是這裏最好的做法是更新應用程序然後運行它,而不必讓用戶做任何事情。

應用程序安裝在我們辦公室的工作站上,所有工作站都運行安裝了python的窗口。他們使用的應用程序是否與在virtualenv中運行的git一起安裝。

我過去所做的是在db中檢查版本,如果版本不正確,然後運行git/pip進程並退出並向用戶發送消息以重新啓動應用程序。我寧願重新啓動應用程序。

TIA

回答

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」後,從終端到該目錄caontaining此腳本:

  • 運行fab bootstrap_local運行作業本地
  • 或者運行fab bootstrap_remote運行作業遠程
+1

感謝的人,我不知道這存在。 – Ominus

+1

在這裏我做了一個非常簡單的例子,你可以用fabtools製作很多非常可愛的東西,非常簡單而且非常有效!例如:安裝和配置主管,postgrest,git操作......所有準備使用;-) –