def _config_from_file(filename, config=None):
 if config:
  bravia_config = _config_from_file(filename)
  if (bravia_config is None):
   bravia_config = {}
  new_config = bravia_config.copy()
  new_config.update(config)
  try:
   with open(filename, 'w') as fdesc:
    fdesc.write(json.dumps(new_config))
  except IOError as error:
   _LOGGER.error('Saving config file failed: %s', error)
   return False
  return True
 elif os.path.isfile(filename):
  try:
   with open(filename, 'r') as fdesc:
    return json.loads(fdesc.read())
  except ValueError as error:
   return {}
  except IOError as error:
   _LOGGER.error('Reading config file failed: %s', error)
   return False
 else:
  return {}

def _config_from_file ( filename , config = None ) : if config : bravia_config = _config_from_file ( filename ) if ( bravia_config is None ) : bravia_config = { } new_config = bravia_config . copy ( ) new_config . update ( config ) try : with open ( filename , 'w' ) as fdesc : fdesc . write ( json . dumps ( new_config ) ) except IOError as error : _LOGGER . error ( 'Saving config file failed: %s' , error ) return False return True elif os . path . isfile ( filename ) : try : with open ( filename , 'r' ) as fdesc : return json . loads ( fdesc . read ( ) ) except ValueError as error : return { } except IOError as error : _LOGGER . error ( 'Reading config file failed: %s' , error ) return False else : return { }
create the configuration from a file .