def dump_json(obj: Any, pretty=False) -> str: # There's a nicer way to do this in python, I'm sure. if pretty: return bytes.decode( orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SORT_KEYS | orjson.OPT_INDENT_2)) else: return bytes.decode(orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS))
def execute_application(executable, params, process, raw_input_line): cmd = [" ".join(["./" + executable])] debug("Command: " + str(cmd)) process[0] = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) start = time.time() debug("Waiting for termination") out, err = process[0].communicate(str.encode(raw_input_line)) end = time.time() debug("Execution time: %s seconds" % (end - start)) raw_policy = bytes.decode(out).split("\n") return read_solution(raw_policy)
def onFinished(self, exitCode, status): if not self.isBatchEnabled(): BasePluginWidget.onFinished(self, exitCode, status) return msg = bytes.decode(bytes(self.base.process.readAllStandardError())) if msg != '': self.errors.append(">> " + self.inFiles[self.batchIndex] + "<br>" + msg.replace("\n", "<br>")) self.base.process.close() # overwrite existent files inDir = self.getInputFileName() outDir = self.getOutputFileName() if outDir is None or inDir == outDir: oldFile = QFile(self.inFiles[self.batchIndex]) newFile = QFile(self.outFiles[self.batchIndex]) if oldFile.remove(): newFile.rename(self.inFiles[self.batchIndex]) self.batchIndex += 1 self.runItem(self.batchIndex, self.batchTotal)