# -*- encoding: utf-8 -*-
'''
@File : project_synchronization_tools.py
@Time : 2020/10/29 21:40:58
@Author : DataMagician
@Version : 1.0
@Contact : [email protected]
'''
# 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")))
项目同步函数
猜你喜欢
转载自blog.csdn.net/weixin_43069769/article/details/109385826
今日推荐
周排行