def updateContracts(self): # if self.contracts == '' or self.contracts == []: # print_message("Contracts list is empty. Something went wrong.") # return path = os.path.join(self.topDir, 'contracts.txt') f = open(path, 'w') f.write(json_encode(self.contracts)) f.close()
def runCommand(self): command = self.getCommand() self.addToHistory(command) command = self.getConstruct(command) if command: tmp_stdout = sys.stdout class stdoutProxy(): def __init__(self, write_func): self.write_func = write_func self.skip = False def flush(self): pass def write(self, text): if not self.skip: stripped_text = text.rstrip('\n') self.write_func(stripped_text) QtCore.QCoreApplication.processEvents() self.skip = not self.skip if type(self.namespace.get(command)) == type(lambda: None): self.appendPlainText( "'{}' is a function. Type '{}()' to use it in the Python console." .format(command, command)) self.newPrompt() return sys.stdout = stdoutProxy(self.appendPlainText) try: try: # eval is generally considered bad practice. use it wisely! result = eval(command, self.namespace, self.namespace) if result != None: if self.is_json: util.print_msg(util.json_encode(result)) else: self.appendPlainText(repr(result)) except SyntaxError: # exec is generally considered bad practice. use it wisely! exec(command, self.namespace, self.namespace) except SystemExit: self.close() except (Exception, BaseException): # Catch errors in the network layer as well, as long as it uses BaseException. traceback_lines = traceback.format_exc().split('\n') # Remove traceback mentioning this file, and a linebreak for i in (3, 2, 1, -1): traceback_lines.pop(i) self.appendPlainText('\n'.join(traceback_lines)) sys.stdout = tmp_stdout self.newPrompt() self.set_json(False)
def backupContract(self, c): path = os.path.join(self.topDir, 'contracts-bkp.txt') f = open(path, 'a') f.write(json_encode(c)) f.close()