基于windows使用fabric将gitlab的文件远程同步到服务器(本地)
2021-06-19 04:07
标签:repo rom ORC 使用 远程同步 进程 pre end file 基于windows使用fabric将gitlab的文件远程同步到服务器(本地) 标签:repo rom ORC 使用 远程同步 进程 pre end file 原文地址:https://www.cnblogs.com/bqwzx/p/10289948.html# -*- 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()
文章标题:基于windows使用fabric将gitlab的文件远程同步到服务器(本地)
文章链接:http://soscw.com/essay/95787.html