zoukankan      html  css  js  c++  java
  • 基于windows使用fabric将gitlab的文件远程同步到服务器(本地)

    # -*- 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()
    

      

    黑发不知勤学早
  • 相关阅读:
    8.Eclipse中创建Maven Web项目
    spin_lock & mutex_lock的差别?
    如花搞笑图片集锦(转贴)
    二分查找
    WebStorm 7.0 注冊码
    Sphinx/Coreseek 4.1 跑 buildconf.sh 一个错误,无法生成configure档
    可变长度结构
    于linux已安装moodle
    采用WindowManager添加您自己的自定义视图
    mysql1130远程连接没有权限解决方法
  • 原文地址:https://www.cnblogs.com/bqwzx/p/10289948.html
Copyright © 2011-2022 走看看