mirror of https://github.com/openspug/spug
A 新增数据传输进度展示
parent
02261a7a6f
commit
981bda96d7
|
@ -1,9 +1,11 @@
|
|||
# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
|
||||
# Copyright: (c) <spug.dev@gmail.com>
|
||||
# Released under the AGPL-3.0 License.
|
||||
from django.template.defaultfilters import filesizeformat
|
||||
from libs.utils import human_datetime, render_str
|
||||
from libs.spug import Notification
|
||||
from apps.host.models import Host
|
||||
from functools import partial
|
||||
import subprocess
|
||||
import json
|
||||
import os
|
||||
|
@ -259,6 +261,14 @@ class Helper:
|
|||
for func in self.callback:
|
||||
func()
|
||||
|
||||
def progress_callback(self, key):
|
||||
def func(k, n, t):
|
||||
message = f'\r {filesizeformat(n):<8}/{filesizeformat(t):>8} '
|
||||
self.send_info(k, message)
|
||||
|
||||
self.send_info(key, '\r\n')
|
||||
return partial(func, key)
|
||||
|
||||
def local(self, command, env=None):
|
||||
if env:
|
||||
env = dict(env.items())
|
||||
|
|
|
@ -245,7 +245,12 @@ def _deploy_ext1_host(req, helper, h_id, env):
|
|||
# transfer files
|
||||
tar_gz_file = f'{req.spug_version}.tar.gz'
|
||||
try:
|
||||
ssh.put_file(os.path.join(REPOS_DIR, 'build', tar_gz_file), os.path.join(extend.dst_repo, tar_gz_file))
|
||||
callback = helper.progress_callback(host.id)
|
||||
ssh.put_file(
|
||||
os.path.join(REPOS_DIR, 'build', tar_gz_file),
|
||||
os.path.join(extend.dst_repo, tar_gz_file),
|
||||
callback
|
||||
)
|
||||
except Exception as e:
|
||||
helper.send_error(host.id, f'Exception: {e}')
|
||||
|
||||
|
@ -293,7 +298,8 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
|
|||
if not action.get('name'):
|
||||
raise RuntimeError('internal error 1002')
|
||||
dst = dst.rstrip('/') + '/' + action['name']
|
||||
ssh.put_file(os.path.join(REPOS_DIR, env.SPUG_DEPLOY_ID, spug_version), dst)
|
||||
callback = helper.progress_callback(host.id)
|
||||
ssh.put_file(os.path.join(REPOS_DIR, env.SPUG_DEPLOY_ID, spug_version), dst, callback)
|
||||
except Exception as e:
|
||||
helper.send_error(host.id, f'Exception: {e}')
|
||||
helper.send_info(host.id, 'transfer completed\r\n')
|
||||
|
@ -302,7 +308,8 @@ def _deploy_ext2_host(helper, h_id, actions, env, spug_version):
|
|||
sp_dir, sd_dst = os.path.split(action['src'])
|
||||
tar_gz_file = f'{spug_version}.tar.gz'
|
||||
try:
|
||||
ssh.put_file(os.path.join(sp_dir, tar_gz_file), f'/tmp/{tar_gz_file}')
|
||||
callback = helper.progress_callback(host.id)
|
||||
ssh.put_file(os.path.join(sp_dir, tar_gz_file), f'/tmp/{tar_gz_file}', callback)
|
||||
except Exception as e:
|
||||
helper.send_error(host.id, f'Exception: {e}')
|
||||
|
||||
|
|
Loading…
Reference in New Issue