def execute_handle(self, data): oper, ips, opts = data if not ips: WidgetTip.warn("请选择IP地址") return root, delay, loop = opts script = self.page_args[3] if oper == 'stop': view_gate.stop_exec_data.set_data([ips, script]) return params = self.page_inst.combine_input(ips) if not params: return scripts_args, upload_list = params #upload_gui = False #for ip, up_list in upload_list.items(): # for file in up_list: # if Common.file_size(file) > 10485760: # 10MB以下文件不显示上传进度窗 # upload_gui = True # break # if upload_gui: # break #if upload_gui: # self.upload_inst = UploadProgress(ips) exec_data = [ips, script, root, delay, loop, scripts_args, upload_list] view_gate.start_exec_data.set_data(exec_data)
def combine_input(self, ips): if not ips: WidgetTip.warn("请勾选IP地址") return None not_set = self.exist_not_set_combox() if not_set: WidgetTip.warn("请设置夏令时参数:%s" % not_set[0]) return None params_dict, upload_dict, param_str = {}, {}, self.options_combine() for ip in ips: params_dict[ip] = [param_str] upload_dict[ip] = [] return [params_dict, upload_dict]
def combine_input(self, ips): def get_widget_input(): if widget == 'Combobox': # 默认选择了第一个 #[shell_params[ip].append(str(instance.current())) for ip in ips] [shell_params[ip].append(instance.get()) for ip in ips] elif widget == 'MultiCombobox': # 默认选择第一个,但可能是”“ for ip, inst in instance: if ip not in ips: continue _v = inst.get() if not _v and not can_be_null: return False shell_params[ip].append(_v) elif widget == 'Checkbox': # 默认无勾选 choose = [str(_v.get()) for _v in instance] # 未选择任意一项 if not can_be_null and len( set(choose)) == 1 and choose[0] == '0': return False [shell_params[ip].append('@'.join(choose)) for ip in ips] elif widget == 'Entry': # 默认为空 for ip in ips: _v = instance.get() if not _v and not can_be_null: return False shell_params[ip].append(_v) elif widget == 'Text': _v = instance.get('1.0', 'end').strip() if not _v and not can_be_null: return False f = '{0}\\__{1}_{2}__.txt'.format(pid_dir, widget, index) Common.write_to_file(f, _v) [shell_params[ip].append(f) for ip in ips] return True 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 ''' 1. 校验控件输入并组装脚本参数 ''' pid_dir = view_gate.query_env_define_data('G_PID_DIR') shell_params, prev_uploads, index = defaultdict(list), defaultdict( list), 0 for item in self.page_instance: widget, instance = item[0] can_be_null, show_result = item[1] actions = item[2] index += 1 if not get_widget_input(): WidgetTip.warn("第{0}个必要控件{1}输入为空 !".format(index, widget)) return None parser_widget_actions() # 解析actions if self.ploter == 'ManualPlot': # 手动触发型可视化界面 PlotMaker.manual(shell_params) return None if self.ploter == '': # 任务型事件 if self.window: # 开启Top窗体显示执行结果 TopNotebook.pack(ips) return [shell_params, prev_uploads]