예제 #1
0
    def upload_file(self, ssh, ip, uploads, offset):
        # 不直接在上传的callback中调用更新状态的Caller,因为会影响上传的速度,
        # callback中只更新内存,状态更新在一个线程中定时去调用
        def upload_back(current, total):
            size[0] = current
            size[1] = total

        def get_progress():
            return int(size[0] / size[1] * offset)

        def update_thread():
            while not is_done:
                self.return_exec_start_result(ip, get_progress(), '', True)
                Common.sleep(0.2)

        size, is_done = [0, 1], False
        server_upload = Global.G_SERVER_UPLOAD % model_gate.settings_data.server_dir
        for local in uploads:
            remote = "{0}/{1}".format(server_upload, Common.basename(local))
            Common.create_thread(func=update_thread, args=())
            self.insert_text_info(ip, get_progress(),
                                  'Uploading {}'.format(local))
            ret, err = SSHUtil.upload_file(ssh, local, remote, upload_back)
            is_done = True
            if not ret:
                self.insert_text_info(
                    ip, get_progress(),
                    'Upload {} failed: {}'.format(local, err), 'ERROR')
                self.return_exec_start_result(ip, get_progress(), '', False)
                return False
            self.return_exec_start_result(ip, get_progress(), '', True)
        return True
예제 #2
0
 def parser_widget_actions():
     for act in actions:
         if act == 'UploadFile':
             for ip in ips:
                 # 本地的文件路径传给上传列表,同时修改脚本参数为文件名
                 _local_f = shell_params[ip][-1]
                 prev_uploads[ip].append(_local_f)
                 shell_params[ip][-1] = Common.basename(_local_f)
         else:
             WidgetTip.error("Not support WidgetAction: {}".format(act))
             continue
예제 #3
0
 def download_file(self, ssh, ip, file):
     if file in ["", "NULL"]:
         self.insert_text_info(ip, 100, 'Success')
         return True
     download_dir = "{0}\\{1}".format(Global.G_DOWNLOAD_DIR, ip)
     filename = "{0}\\{1}".format(download_dir, Common.basename(file))
     Common.mkdir(download_dir)
     self.insert_text_info(ip, 100, 'Downloading to {}'.format(filename))
     if not SSHUtil.download_file(ssh, remote=file, local=filename):
         return False
     self.insert_text_info(ip, 100, "Download success")
     return True