def add_node(self, node, x, y): logger.debug('Add node #%i %s' % (node.index(), node.label.replace('\n', ' '))) self.addItem(node) self.nodes[node.index()] = node self.adj_list[node.index()] = set() self.nb_nodes += 1 node.moveBy(x, y)
def load(self, options): logger.debug('Calling WriteLandXMLNode.load with options:') logger.debug(options) success, (suffix, in_source_folder, dir_path, double_name, overwrite) = validate_output_options(options) if success: self.state = Node.READY self.suffix, self.in_source_folder, self.dir_path, self.double_name, self.overwrite = \ suffix, in_source_folder, dir_path, double_name, overwrite
def load(self, filename): logger.debug('Loading project in MONO: %s' % filename) self.project_path = filename self.clear() self._add_current_line() self._init_without_node() try: with open(filename, 'r') as f: self.language, self.csv_separator = f.readline().rstrip( ).split('.') nb_nodes, nb_links = map(int, f.readline().split()) for i in range(nb_nodes): line = f.readline().rstrip().split('|') category, name, index, x, y = line[:5] node = NODES[category][name](int(index)) node.load(line[5:]) self.add_node(node, float(x), float(y)) for i in range(nb_links): from_node_index, from_port_index, \ to_node_index, to_port_index = map(int, f.readline().rstrip().split('|')) from_node = self.nodes[from_node_index] to_node = self.nodes[to_node_index] from_port = from_node.ports[from_port_index] to_port = to_node.ports[to_port_index] _, _ = add_link(from_port, to_port) link = Link(from_port, to_port) from_node.add_link(link) to_node.add_link(link) self.addItem(link) link.setZValue(-1) self.adj_list[from_node_index].add(to_node_index) self.adj_list[to_node_index].add(from_node_index) self.update() return True except (IndexError, ValueError, KeyError): logger.error("An exception occured while loading project in MONO.") self.reinit() return False
def run(self): logger.debug('Start running project') start_time = time() if not self.scene.all_configured(): QMessageBox.critical(None, 'Error', 'Configure all nodes first!', QMessageBox.Ok) return self.scene.prepare_to_run() if self.parent: self.parent.save() self.setEnabled(False) csv_separator = self.scene.csv_separator format_string = '{0:.%df}' % self.scene.digits # first get auxiliary tasks done success = self._prepare_auxiliary_tasks() if not success: self.worker.stop() self.message_box.appendPlainText('Done!') self.setEnabled(True) self.worker = worker.Workers(self.ncsize) return # prepare slf input tasks nb_tasks = self._prepare_input_tasks() while not self.worker.stopped: nb_tasks = self._listen(nb_tasks, csv_separator, format_string) if nb_tasks == 0: self.worker.stop() self.message_box.appendPlainText('Done!') self.setEnabled(True) self.worker = worker.Workers(self.ncsize) logger.debug('Execution time %f s' % (time() - start_time))
def run_all(self): logger.debug('Start running project') start_time = time() self.view.scene().run_all() self.view.scene().update() logger.debug('Execution time %f s' % (time() - start_time))
def load(self, filename): logger.debug('Loading project in MULTI: %s' % filename) self.clear() self.has_input = False self.inputs = {} self.nodes = {} self.adj_list = {} self.ordered_input_indices = [] self.auxiliary_input_nodes = [] try: with open(filename, 'r') as f: self.language, self.csv_separator = f.readline().rstrip().split('.') nb_nodes, nb_links = map(int, f.readline().split()) # load nodes for i in range(nb_nodes): line = f.readline().rstrip().split('|') category, name, index, x, y = line[:5] if category == 'Visualization': # ignore all visualization nodes continue index = int(index) node = NODES[category][name](index) node.load(line[5:]) self.add_node(node, float(x), float(y)) # load edges for i in range(nb_links): from_node_index, from_port_index, \ to_node_index, to_port_index = map(int, f.readline().rstrip().split('|')) if to_node_index not in self.nodes: # visualization nodes continue from_node = self.nodes[from_node_index] to_node = self.nodes[to_node_index] from_port = from_node.ports[from_port_index] to_port = to_node.ports[to_port_index] from_port.connect(to_port) to_port.connect(from_port) link = MultiLink(from_port, to_port) link.setZValue(-1) self.addItem(link) self.adj_list[from_node_index].add(to_node_index) # mark nodes with input for input_index in self.inputs: downstream_nodes = visit(self.adj_list, input_index) for u in downstream_nodes: self.nodes[u].mark(input_index) # remove orphan auxiliary nodes to_remove = [] for u in self.auxiliary_input_nodes: if not self.adj_list[u]: to_remove.append(u) del self.adj_list[u] self.removeItem(self.nodes[u]) del self.nodes[u] self.auxiliary_input_nodes = [u for u in self.auxiliary_input_nodes if u not in to_remove] self.update() # update status table ordered_nodes = topological_ordering(self.adj_list) self.table.update_rows(self.nodes, [u for u in ordered_nodes if u not in self.auxiliary_input_nodes]) QApplication.processEvents() # load input information next_line = f.readline() if next_line: nb_inputs = int(next_line) for i in range(nb_inputs): line = f.readline() split_line = line.rstrip().split('|') node_index = int(split_line[0]) nb_files = int(split_line[1]) slf_name = split_line[2] paths = split_line[3:3+nb_files] job_ids = split_line[3+nb_files:] # check if file exists: for path in paths: if not os.path.exists(os.path.join(path, slf_name)): for node_index in self.inputs: self.inputs[node_index] = [] self.has_input = False self.update() QApplication.processEvents() return True self.inputs[node_index] = [paths, slf_name, job_ids] self._handle_load_input(node_index) self.update() self.has_input = True QApplication.processEvents() return True except (IndexError, ValueError, KeyError): logger.error("An exception occured while loading project in MULTI.") self.reinit() self.table.reinit() return False