def __dump_file(self, temp = False):
# Clear out program data.......
pref_loc = self.__preferences
if temp:
try:
fd = tempfile.NamedTemporaryFile(dir=tempfile._get_default_tempdir(), delete=True)
except Exception as e:
logger.warn('[%s] Unable to create preferences temporary file. (%s)' % (self.chat_id, e))
raise Exception("Unable to create preferences temporary file. (%s)" % e)
else:
# try to open preferences file
try:
fd = open(self.fullpath, 'w', encoding='utf-8')
except Exception as e:
logger.warn('[%s] Unable to open preference file for writing. (%s)' % (self.chat_id, e))
raise Exception("Unable to open preferences file '%s." % self.fullpath)
try:
with fd:
json.dump(pref_loc, fd, indent=4, sort_keys=True, separators=(',', ':'))
except Exception as e:
logger.error('[%s] Unable to write to preferences file. (%s)' % (self.chat_id, e))
raise Exception("Unable to write preferences to file '%s."%self.fullpath)
# close file
fd.close()
评论列表
文章目录