# -*- coding: utf-8 -*- from fabric.api import env, run, local, put from fabric.operations import sudo import tarfile import os import string # GIT_REPO = "git地址" env.user = ‘账号‘ env.password = ‘密码‘ env.hosts = [‘IP地址‘] env.port = ‘22‘ exclude_names = [‘fabfile.py‘, ‘venv‘] def filter_func(tarinfo): # if tarinfo in exclude_names and tarinfo.isdir(): if tarinfo in exclude_names: return True elif tarinfo.endswith(‘fabfile.py‘): return True elif tarinfo.endswith(‘venv‘): return True # elif tarinfo.startswith(‘venv‘): # return True elif tarinfo.startswith(‘.‘): return True # elif tarinfo.endswith(‘.git‘): # return True # elif tarinfo.endswith(‘.idea‘): # return True elif tarinfo.endswith(‘.html‘): return True elif tarinfo.endswith(‘.pyc‘): return True else: return False # 本地压缩到服务器 def deploy(): # local basedir = os.getcwd() source_folder = ‘目标文件夹‘ tar = tarfile.open(‘the_tar.gz‘, ‘w:gz‘) tar.add(basedir, exclude=filter_func) # for root, dirs, files in os.walk(basedir): # fullpath = os.path.join(root, file) # tar.add(fullpath) tar.close() put(os.path.join(basedir, ‘the_tar.gz‘), source_folder) run(""" cd {} && tar -xf the_tar.gz && rm -f the_tar.gz """.format(source_folder)) # sudo(‘supervisorctl restart 项目进程‘) # if __name__ == ‘__main__‘: # deploy()
原文地址:https://www.cnblogs.com/bqwzx/p/10289948.html
时间: 2024-10-13 18:33:27