def __init__(self, nodeController): self.idGenerator = IdGenerator() self.fileManager = FileManager() self.nodeController = nodeController self.clusterController = ClusterController() self.urlManager = UrlManager() self.clusterPort = 81
def on_btn_clicked(self): sender = self._dialog.sender() if sender == self._dialog.btn_addselect: file_model: FileModel = self._dialog.file_model # 判断是否需要删除原文件 if self._dialog.index: FileManager().delete_file(self._dialog.index) # 文件模型中填充标签 for index in self._dialog.lv_label.selectedIndexes(): data = index.data() file_model.add_file_label(data) # 写到文件配置项 if not FileManager().add_file(self._dialog.file_model): print('文件{}已添加'.format(file_model.file_name)) return #关闭弹窗 self._dialog.close() elif sender == self._dialog.btn_newlabel: new_label, ok = QInputDialog.getText(None, "新增标签", "请输入新标签名:") if ok: if FileLabelManager().add_label(new_label): print('添加标签成功') elif sender == self._dialog.btn_removelabel: FileLabelManager().remove_labels( self._dialog.lv_label.selectedIndexes())
def __init__(self): self._root_abs_path = GlobalVarManager.root_abs_path self._lattice_edt = GlobalVarManager.lattice_edt self._file_mgr = FileManager() # 用于充当ListView数据源 self._cat_list_model = QStandardItemModel() # 初始化目录 self.init_catalogue()
def process_trigger(self, act): if act == self.act_open_file: abs_path = FileManager().get_abs_path(self._index.data()) os.system("\"{}\"".format(abs_path)) elif act == self.act_del_file: FileManager().delete_file(self._index) elif act == self.act_edit_label: abs_path = FileManager().get_abs_path(self._index.data()) file_model = FileModel() file_model.abs_path = abs_path AddFileDialog(file_model=file_model, index=self._index).exec_()
class CatalogueManager: """ 单例化,管理目录结构 """ def __init__(self): self._root_abs_path = GlobalVarManager.root_abs_path self._lattice_edt = GlobalVarManager.lattice_edt self._file_mgr = FileManager() # 用于充当ListView数据源 self._cat_list_model = QStandardItemModel() # 初始化目录 self.init_catalogue() def init_catalogue(self): """从图数据库中读取路径用于填充""" self._cat_list_model.clear() self._cat_list_model.setHorizontalHeaderLabels(['节点名', '路径', '备注']) root_item: QStandardItem = self._cat_list_model.invisibleRootItem() parent_item = QStandardItem(QIcon(self._root_abs_path + "\\resources\\go-home.png"), "root") root_item.appendRow(parent_item) for path in self._lattice_edt.tree_model.get_root2leaf_path(): print(path) depth = 1 self._add_path(path, depth, parent_item, "root", len(path)) def _add_path(self, path: List[str], depth: int, parent_item: QStandardItem, path_str: str, path_len: int): is_file = False if depth == path_len: return if depth == path_len - 1: # 为文件 is_file = True node_name_list = path[depth] for node_name in node_name_list: # 检查节点名在是否重复 index = 0 child_item = parent_item.child(index) while child_item: child_name = child_item.index().data() if child_name == node_name: node_item = child_item break index += 1 child_item = parent_item.child(index) else: note_str = "文件" if is_file else "文件夹" icon = QIcon(self._root_abs_path + "\\resources\\folder.png") if not is_file else IconExtractor( self._file_mgr.get_abs_path(node_name)).get_icon() node_item = QStandardItem(icon, node_name) path_str += "\\" + node_name path_item = QStandardItem(path_str) note_item = QStandardItem(note_str) parent_item.appendRow([node_item, path_item, note_item]) self._add_path(path, depth + 1, node_item, path_str, path_len) @property def cat_list_model(self): return self._cat_list_model
def on_selected_changed(self, selected: QItemSelection, deselected: QItemSelection): if not selected.indexes(): return sender = self._window.sender() if sender == self._window.lv_file.selectionModel(): file_name = selected.indexes()[0].data() label_list = FileManager().get_label_list(file_name) self.show_message("{}:标签为{}".format(file_name, str(label_list))) elif sender == self._window.lv_label.selectionModel(): label_name = selected.indexes()[0].data() file_name_list = FileLabelManager().get_file_name_list(label_name) self.show_message("{}:文件为{}".format(label_name, str(file_name_list))) elif sender == self._window.tv_catalogue.selectionModel(): path = selected.indexes()[1].data() if not path: path = "root" self._window.le_path.setText(path)
class ClusterCreator(): idGenerator = None fileManager = None nodeController = None clusterController = None clusterCurrentPort = None haProxyManager = None urlManager = None clusterPort = 0 serverPointer = 0 def __init__(self, nodeController): self.idGenerator = IdGenerator() self.fileManager = FileManager() self.nodeController = nodeController self.clusterController = ClusterController() self.urlManager = UrlManager() self.clusterPort = 81 def createCluster(self, clusterController, cluster_name, dockerfile, instances, package, mem, port): cluster_id = self.idGenerator.getId() self.fileManager.set_dockerfile_path(cluster_id) self.fileManager.deploy_files(cluster_id, package, dockerfile_data) available_nodes = nodeController.getAvailableNodes() data = self.fileManager.getData(self.fileManager.getDockerfileDir(cluster_id)) self.sendImageDataToNodes(availableNodes, cluster_id, cluster_name, dockerfile, data) clusterController.createCluster(cluster_id, cluster_name) LoadBalancerManager.addClusterFrontendToMain(self.clusterPort, cluster_id) self.createNetwork(cluster_id) nodes_addresess = self.sendClusterParametersToNodes(instances, available_nodes, cluster_id, mem, port) LoadBalancerManager.addNodesAddressesToLoadBalancer(nodes_addresses) return True def sendImageDataToNodes(self, available_nodes, cluster_id, cluster_name, dockerfile, data): success = True for node in available_nodes: url = urlManager.assembleBuildURL(node.getIp()) form_data = {'cluster_id': cluster_id, 'cluster_name': cluster_name, 'dockerfile': dockerfile, 'data': data)} datagen, headers = multipart_encode(form_data) request = urllib2.Request(url, datagen, headers) response = urllib2.urlopen(request) result = response.read() if not result: success = False return success def createNetwork(self, cluster_id): return True def sendClusterParametersToNodes(self, instances, available_nodes, cluster_id, mem, port): nodes_addresses = {} available_nodes_amount = len(available_nodes) for instance in range(instances): instance_address = self.sendInstanceParameterToNode(cluster_id, mem, port) nodes_addresses[instance_address['node_ip']] = instance_address['cluster_port_in_node'] return nodes_addresses def addInstanceToCluster(self, cluster_id, mem, port): node_address_dict = self.sendInstanceParameterToNode(self, cluster_id, mem, port) node_address = {} node_address[node_address_dict['node_ip']] = node_address_dict['cluster_port_in_node'] self.LoadBalancerManager.addNodesAddressesToLoadBalancer(node_address) def sendInstanceParamenterToNode(self, cluster_id, mem, port): node_ip = nodeManager.getNextNode().getIp() url = self.urlManager.assembleRunURL(node_ip) form_data = {'cluster_id' : cluster_id, 'mem' : mem, 'port' : port} params = urllib.urlencode(form_data) response = urllib2.urlopen(url, params) result = json.load(response) ips = result['result'] cluster_port_in_node = ips['lb_port'] return {'node_ip': node_ip, 'cluster_port_in_node': cluster_port_in_node}
def init_lv_file(self): self.lv_file.setModel(FileManager().file_list_model) self.lv_file.selectionModel().selectionChanged.connect(self._controller.on_selected_changed) self.lv_file.customContextMenuRequested[QPoint].connect(self._controller.on_menu_requested)