def fileExists(filename): try: os.stat(misc.toPath(filename)) except OSError: return False return True
def createBackup(filename): try: f = open(misc.toPath(filename), "r") try: data = f.read() finally: f.close() f = open(misc.toPath(filename + ".bak"), "w+") try: f.write(data) finally: f.close() return True except IOError, (errno, strerror): #wx.MessageBox("Error writing file '%s': %s" % (filename, strerror), "Error", wx.OK, "") return False
def loadFile(filename, frame, maxSize=-1): ret = None try: f = open(misc.toPath(filename), "rb") try: ret = f.read(maxSize) finally: f.close() except IOError, (errno, strerror): wx.MessageBox("Error loading file '%s': %s" % (filename, strerror), "Error", wx.OK, frame) ret = None
def loadFile(filename, frame, maxSize = -1): ret = None try: f = open(misc.toPath(filename), "rb") try: ret = f.read(maxSize) finally: f.close() except IOError, (errno, strerror): wx.MessageBox("Error loading file '%s': %s" % ( filename, strerror), "Error", wx.OK, frame) ret = None
def writeToFile(filename, data, frame): try: f = open(misc.toPath(filename), "wb") try: f.write(data) finally: f.close() return True except IOError, (errno, strerror): wx.MessageBox("Error writing file '%s': %s" % (filename, strerror), "Error", wx.OK, frame) return False
def writeToFile(filename, data, frame): try: f = open(misc.toPath(filename), "wb") try: f.write(data) finally: f.close() return True except IOError, (errno, strerror): wx.MessageBox("Error writing file '%s': %s" % ( filename, strerror), "Error", wx.OK, frame) return False
def loadFile(filename, frame, maxSize=-1): ret = None try: f = open(misc.toPath(filename), "r", encoding='UTF-8') try: ret = f.read(maxSize) finally: f.close() except IOError as xxx_todo_changeme: (errno, strerror) = xxx_todo_changeme.args wx.MessageBox("Error loading file '%s': %s" % (filename, strerror), "Error", wx.OK, frame) ret = None return ret
def writeToFile(filename, data, frame): try: f = open(misc.toPath(filename), "wb") try: if isinstance(data, str): f.write(data.encode("UTF-8")) else: f.write(data) finally: f.close() return True except IOError as xxx_todo_changeme1: (errno, strerror) = xxx_todo_changeme1.args wx.MessageBox("Error writing file '%s': %s" % (filename, strerror), "Error", wx.OK, frame) return False