项目同步函数

# -*- encoding: utf-8 -*-
'''
@File    :   project_synchronization_tools.py
@Time    :   2020/10/29 21:40:58
@Author  :   DataMagician 
@Version :   1.0
@Contact :   408903228@qq.com
'''

# here put the import lib
from subprocess import getoutput
from os import path,listdir,system,getcwd,sep
import logging 
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(filename='my.log', level=logging.DEBUG, format=LOG_FORMAT)

# TODO 大文件同步
def synchronize_files_to_remote_servers_function(
                            local_path=getcwd()    
                            ,user="root"
                            ,port="22"
                            ,ip="0.0.0.0"
                            ,service_path=""):
    """
    '同步文件到远程服务器'
    """
    project_name = local_path.split(sep)[-1]
    synchronize_command_keywords="rsync -avP -e 'ssh -p "+port+"' "
    home_path = path.expanduser("~/")
    locathost_information_keyword = synchronize_command_keywords+home_path+local_path.replace(home_path,"")
    symbolic_link = "@"

    server_information_keyword = user+symbolic_link+ip
    print("请输入目标服务器密码,以获得路径,如已配置私钥则掠过此项:",sep='\n')
    server_home_path = getoutput("ssh -p "+port+" "+server_information_keyword + " pwd").replace("Permission denied, please try again.\n","")
    print("目标服务器主路径为:",server_home_path,sep='\t:\t')

    synchronization_command = locathost_information_keyword+" "+server_information_keyword+":"+server_home_path+service_path+sep
    return synchronization_command


    pass

def synchronize_files_to_local_servers_function():
    """
    同步文件到本地服务器 
    """
    pass
if __name__ == "__main__":
    '''
    修改为服务器参数即可
    '''
    print(getoutput(synchronize_files_to_remote_servers_function(local_path=getcwd(),user="root",ip="0000.0000.0000.0000",port="8888")))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值