#NEWLINE# def config_from_file( filename , config = None ) : #NEWLINE# #INDENT# 'Small configuration file management function.' #NEWLINE# if config : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# with open ( filename , 'w' ) as fdesc : #NEWLINE# #INDENT# fdesc . write ( json . dumps ( config ) ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError as error : #NEWLINE# #INDENT# _LOGGER . error ( 'Saving config file failed: %s' , error ) #NEWLINE# return False #NEWLINE# #UNINDENT# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . isfile ( filename ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# with open ( filename , 'r' ) as fdesc : #NEWLINE# #INDENT# return json . loads ( fdesc . read ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# except IOError as error : #NEWLINE# #INDENT# _LOGGER . error ( 'Reading config file failed: %s' , config ) #NEWLINE# return False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# }