1. 程式人生 > >Python一鍵部署文件

Python一鍵部署文件

main xxxx .com epo import 2-0 start walk for

第一步:先從git clone 文件

https://www.cnblogs.com/wanglan/p/10718876.html#autoid-2-0-0

from git import Repo

#
to_path ="E:\zsyec"
url=***.git
#git clone
clone = Repo.clone_from(url,to_path)

第二步:文件壓縮

import os
import zipfile

def zipDir(dirpath,outFullName):
    """
    壓縮指定文件夾
    :param dirpath: 目標文件夾路徑
    :param outFullName: 壓縮文件保存路徑+xxxx.zip
    :return: 無
    
""" zip = zipfile.ZipFile(outFullName,"w",zipfile.ZIP_DEFLATED) for path,dirnames,filenames in os.walk(dirpath): # 去掉目標跟路徑,只對目標文件夾下邊的文件及文件夾進行壓縮 fpath = path.replace(dirpath,‘‘) for filename in filenames: zip.write(os.path.join(path,filename),os.path.join(fpath,filename)) zip.close()
if __name__ == "__main__": startdir = "E:\econtract\src" #要壓縮的文件夾路徑 file_news = startdir +.zip # 壓縮後文件夾的名字 zip_ya(startdir,file_news)

Python一鍵部署文件