mirror of https://github.com/openspug/spug
U 优化文件分发兼容性
parent
5d849fc93d
commit
7878aa918f
|
@ -10,6 +10,7 @@ from apps.account.utils import has_host_perm
|
||||||
from apps.host.models import Host
|
from apps.host.models import Host
|
||||||
from apps.setting.utils import AppSetting
|
from apps.setting.utils import AppSetting
|
||||||
from libs import json_response, JsonParser, Argument, auth
|
from libs import json_response, JsonParser, Argument, auth
|
||||||
|
from libs.utils import str_decode
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -96,7 +97,7 @@ def _dispatch_sync(task):
|
||||||
for t in futures.as_completed(threads):
|
for t in futures.as_completed(threads):
|
||||||
exc = t.exception()
|
exc = t.exception()
|
||||||
if exc:
|
if exc:
|
||||||
rds.publish(t.token, json.dumps({'key': t.key, 'status': -1, 'data': f'Exception: {exc}'}))
|
rds.publish(t.token, json.dumps({'key': t.key, 'status': -1, 'data': f'\x1b[31mException: {exc}\x1b[0m'}))
|
||||||
if task.host_id:
|
if task.host_id:
|
||||||
command = f'umount -f {task.src_dir} && rm -rf {task.src_dir}'
|
command = f'umount -f {task.src_dir} && rm -rf {task.src_dir}'
|
||||||
else:
|
else:
|
||||||
|
@ -120,7 +121,7 @@ def _do_sync(rds, task, host):
|
||||||
message = task.stdout.readline()
|
message = task.stdout.readline()
|
||||||
if not message:
|
if not message:
|
||||||
break
|
break
|
||||||
message = message.decode().rstrip('\r\n')
|
message = str_decode(message).rstrip('\r\n')
|
||||||
if 'rsync: command not found' in message:
|
if 'rsync: command not found' in message:
|
||||||
data = '\r\n\x1b[31m检测到该主机未安装rsync,可通过批量执行/执行任务模块进行以下命令批量安装\x1b[0m'
|
data = '\r\n\x1b[31m检测到该主机未安装rsync,可通过批量执行/执行任务模块进行以下命令批量安装\x1b[0m'
|
||||||
data += '\r\nCentos/Redhat: yum install -y rsync'
|
data += '\r\nCentos/Redhat: yum install -y rsync'
|
||||||
|
|
|
@ -7,6 +7,7 @@ from asgiref.sync import async_to_sync
|
||||||
from apps.host.models import Host
|
from apps.host.models import Host
|
||||||
from consumer.utils import BaseConsumer
|
from consumer.utils import BaseConsumer
|
||||||
from apps.account.utils import has_host_perm
|
from apps.account.utils import has_host_perm
|
||||||
|
from libs.utils import str_decode
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
@ -64,10 +65,7 @@ class SSHConsumer(BaseConsumer):
|
||||||
if not data:
|
if not data:
|
||||||
self.close(3333)
|
self.close(3333)
|
||||||
break
|
break
|
||||||
try:
|
text = str_decode(data)
|
||||||
text = data.decode()
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
text = data.decode(encoding='GBK', errors='ignore')
|
|
||||||
if not is_ready:
|
if not is_ready:
|
||||||
self.send(text_data='\033[2J\033[3J\033[1;1H')
|
self.send(text_data='\033[2J\033[3J\033[1;1H')
|
||||||
is_ready = True
|
is_ready = True
|
||||||
|
@ -138,7 +136,7 @@ class PubSubConsumer(BaseConsumer):
|
||||||
def receive(self, **kwargs):
|
def receive(self, **kwargs):
|
||||||
response = self.p.get_message(timeout=10)
|
response = self.p.get_message(timeout=10)
|
||||||
while response:
|
while response:
|
||||||
data = response['data'].decode()
|
data = str_decode(response['data'])
|
||||||
self.send(text_data=data)
|
self.send(text_data=data)
|
||||||
response = self.p.get_message(timeout=10)
|
response = self.p.get_message(timeout=10)
|
||||||
self.send(text_data='pong')
|
self.send(text_data='pong')
|
||||||
|
|
|
@ -37,6 +37,14 @@ def human_time(date=None):
|
||||||
return date.strftime('%H:%M:%S')
|
return date.strftime('%H:%M:%S')
|
||||||
|
|
||||||
|
|
||||||
|
def str_decode(data):
|
||||||
|
try:
|
||||||
|
data = data.decode()
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
data = data.decode(encoding='GBK', errors='ignore')
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
# 解析时间类型的数据
|
# 解析时间类型的数据
|
||||||
def parse_time(value):
|
def parse_time(value):
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
|
|
Loading…
Reference in New Issue