|
|
|
@ -1,6 +1,7 @@ |
|
|
|
import os |
|
|
|
import os |
|
|
|
import json |
|
|
|
import json |
|
|
|
import paramiko |
|
|
|
import paramiko |
|
|
|
|
|
|
|
import requests |
|
|
|
from smb.SMBConnection import SMBConnection |
|
|
|
from smb.SMBConnection import SMBConnection |
|
|
|
from update.models import ClientRelease, Cinema |
|
|
|
from update.models import ClientRelease, Cinema |
|
|
|
import pymysql |
|
|
|
import pymysql |
|
|
|
@ -23,6 +24,7 @@ class ClientUtilCustom: |
|
|
|
self.local_path = os.path.join(BASE_DIR, 'dx', 'client') |
|
|
|
self.local_path = os.path.join(BASE_DIR, 'dx', 'client') |
|
|
|
self.deploy_db_config = {'host': '10.10.0.80', 'port': 3306, 'user': 'cine_readonly', |
|
|
|
self.deploy_db_config = {'host': '10.10.0.80', 'port': 3306, 'user': 'cine_readonly', |
|
|
|
'password': 'IyzCtV11', 'database': 'yhz_tool'} |
|
|
|
'password': 'IyzCtV11', 'database': 'yhz_tool'} |
|
|
|
|
|
|
|
self.client_mirror = {'url': 'http://10.10.0.38:8989/upload/'} |
|
|
|
self.deploy_id = 0 |
|
|
|
self.deploy_id = 0 |
|
|
|
self.client_data = [] |
|
|
|
self.client_data = [] |
|
|
|
self.client_file_list = [] |
|
|
|
self.client_file_list = [] |
|
|
|
@ -135,7 +137,8 @@ class ClientUtilCustom: |
|
|
|
print('找到本地文件:', file['name']) |
|
|
|
print('找到本地文件:', file['name']) |
|
|
|
continue |
|
|
|
continue |
|
|
|
# 下载文件到本地 |
|
|
|
# 下载文件到本地 |
|
|
|
with open(os.path.join(self.local_path, file['name']), 'wb') as local_file: |
|
|
|
file_path = os.path.join(self.local_path, file['name']) |
|
|
|
|
|
|
|
with open(file_path, 'wb') as local_file: |
|
|
|
# 接收文件并写入本地文件 |
|
|
|
# 接收文件并写入本地文件 |
|
|
|
print('从共享下载客户端文件到服务器 共享路径:', rf"{file['path']}{file['name']}", '服务器路径:', |
|
|
|
print('从共享下载客户端文件到服务器 共享路径:', rf"{file['path']}{file['name']}", '服务器路径:', |
|
|
|
os.path.join(self.local_path, file['name'])) |
|
|
|
os.path.join(self.local_path, file['name'])) |
|
|
|
@ -145,26 +148,42 @@ class ClientUtilCustom: |
|
|
|
client['file_name'] = file['name'] |
|
|
|
client['file_name'] = file['name'] |
|
|
|
# 关闭本地文件 |
|
|
|
# 关闭本地文件 |
|
|
|
local_file.close() |
|
|
|
local_file.close() |
|
|
|
|
|
|
|
target_file = os.path.join('/home/client/', file['name']) |
|
|
|
|
|
|
|
self.upload(self.client_mirror['host'], file_path, target_file, self.client_mirror['username'], |
|
|
|
|
|
|
|
self.client_mirror['password']) |
|
|
|
|
|
|
|
print(f'完成客户端同步: {target_file}') |
|
|
|
|
|
|
|
|
|
|
|
print(self.client_data) |
|
|
|
print(self.client_data) |
|
|
|
|
|
|
|
|
|
|
|
# 传输客户端的方法 |
|
|
|
# 传输客户端的方法 |
|
|
|
|
|
|
|
|
|
|
|
def upload(self, cine_ip, origin, target): |
|
|
|
def upload(self, cine_ip: str, origin: str, target: str, user: str = 'root', pwd: str = 'cine123456') -> bool: |
|
|
|
print('upload', cine_ip, origin, target) |
|
|
|
print('upload', cine_ip, origin, target) |
|
|
|
# 创建Transport客户端 |
|
|
|
try: |
|
|
|
trans = paramiko.Transport((cine_ip, 22)) |
|
|
|
# 创建Transport客户端 |
|
|
|
# 使用密码连接服务器 |
|
|
|
trans = paramiko.Transport((cine_ip, 22)) |
|
|
|
trans.connect(username='root', password='cine123456') |
|
|
|
# 使用密码连接服务器 |
|
|
|
# 创建SFTP客户端 |
|
|
|
trans.connect(username=user, password=pwd) |
|
|
|
sftp = paramiko.SFTPClient.from_transport(trans) |
|
|
|
# 创建SFTP客户端 |
|
|
|
# 上传文件 参数(本地文件路径, 远程文件路径) |
|
|
|
sftp = paramiko.SFTPClient.from_transport(trans) |
|
|
|
sftp.put( |
|
|
|
# 上传文件 参数(本地文件路径, 远程文件路径) |
|
|
|
os.path.join(self.local_path, origin), |
|
|
|
sftp.put( |
|
|
|
f"/data0/cine/resource/upload/client/{target}") |
|
|
|
os.path.join(self.local_path, origin), |
|
|
|
# 关闭客户端 |
|
|
|
f"/data0/cine/resource/upload/client/{target}") |
|
|
|
print(f'完成上传,路径/data0/cine/resource/upload/client/{target}') |
|
|
|
# 关闭客户端 |
|
|
|
trans.close() |
|
|
|
print(f'完成上传,路径/data0/cine/resource/upload/client/{target}') |
|
|
|
|
|
|
|
trans.close() |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
print(e) |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upload_server_to_server(self, cine_ip: str, origin: str, target: str) -> bool: |
|
|
|
|
|
|
|
r = requests.get(self.client_mirror['url'], params={'cine_ip': cine_ip, 'origin': origin, 'target': target}).json() |
|
|
|
|
|
|
|
print(r) |
|
|
|
|
|
|
|
if r['result'] == 'success': |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def upload_client(self, cinema_ip, client_ver, server_release): |
|
|
|
def upload_client(self, cinema_ip, client_ver, server_release): |
|
|
|
print('upload_client', cinema_ip, client_ver, server_release) |
|
|
|
print('upload_client', cinema_ip, client_ver, server_release) |
|
|
|
@ -183,8 +202,12 @@ class ClientUtilCustom: |
|
|
|
print('最终上传版本:', client.file_name, client.upload_name) |
|
|
|
print('最终上传版本:', client.file_name, client.upload_name) |
|
|
|
if not client: |
|
|
|
if not client: |
|
|
|
return False |
|
|
|
return False |
|
|
|
self.upload(cinema_ip, client.file_name, client.upload_name) |
|
|
|
if cinema_ip.startswith('10.'): |
|
|
|
|
|
|
|
if not self.upload_server_to_server(cinema_ip, client.file_name, client.upload_name): |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
if not self.upload(cinema_ip, client.file_name, client.upload_name): |
|
|
|
|
|
|
|
return False |
|
|
|
# 更新数据库 |
|
|
|
# 更新数据库 |
|
|
|
cine = Cinema.objects.filter(ip=cinema_ip).first() |
|
|
|
cine = Cinema.objects.filter(ip=cinema_ip).first() |
|
|
|
db_config = { |
|
|
|
db_config = { |
|
|
|
|