def save(toml_config): """ :param toml_config: TOML configuration object :type toml_config: MutableToml or Toml """ serial = toml.dumps(toml_config._dictionary) path = get_config_path() util.ensure_file_exists(path) util.enforce_file_permissions(path) with util.open_file(path, 'w') as config_file: config_file.write(serial)
def save(toml_config, config_path=None): """ :param toml_config: TOML configuration object :type toml_config: MutableToml or Toml :param config_path: path to config to use :type config_path: str """ serial = toml.dumps(toml_config._dictionary) if config_path is None: config_path = get_config_path() util.ensure_file_exists(config_path) util.enforce_file_permissions(config_path) with util.open_file(config_path, 'w') as config_file: config_file.write(serial)
def load_from_path(path, mutable=False): """Loads a TOML file from the path :param path: Path to the TOML file :type path: str :param mutable: True if the returned Toml object should be mutable :type mutable: boolean :returns: Map for the configuration file :rtype: Toml | MutableToml """ util.ensure_file_exists(path) util.enforce_file_permissions(path) with util.open_file(path, 'r') as config_file: try: toml_obj = toml.loads(config_file.read()) except Exception as e: raise DCOSException('Error parsing config file at [{}]: {}'.format( path, e)) return (MutableToml if mutable else Toml)(toml_obj)
def load_from_path(path, mutable=False): """Loads a TOML file from the path :param path: Path to the TOML file :type path: str :param mutable: True if the returned Toml object should be mutable :type mutable: boolean :returns: Map for the configuration file :rtype: Toml | MutableToml """ util.ensure_file_exists(path) util.enforce_file_permissions(path) with util.open_file(path, 'r') as config_file: try: toml_obj = toml.loads(config_file.read()) except Exception as e: raise DCOSException( 'Error parsing config file at [{}]: {}'.format(path, e)) return (MutableToml if mutable else Toml)(toml_obj)