Beispiel #1
0
def write(settings_path, settings_data, merge=True):
    """Write data to a settings file.

    :param settings_path: the filepath
    :param settings_data: a dictionary with data
    :param merge: boolean if existing file should be merged with new data
    """

    if settings_path.exists() and merge:  # pragma: no cover
        settings_data = dictmerge(
            json.load(
                io.open(
                    str(settings_path),
                    encoding=default_settings.ENCODING_FOR_DYNACONF
                )
            ),
            settings_data
        )

    json.dump(
        settings_data,
        io.open(
            str(settings_path), 'w',
            encoding=default_settings.ENCODING_FOR_DYNACONF
        )
    )
Beispiel #2
0
def write(settings_path, settings_data, merge=True):
    """Write data to a settings file.

    :param settings_path: the filepath
    :param settings_data: a dictionary with data
    :param merge: boolean if existing file should be merged with new data
    """
    if settings_path.exists() and merge:  # pragma: no cover
        settings_data = dictmerge(json.load(open(str(settings_path))),
                                  settings_data)
    json.dump(settings_data, open(str(settings_path), 'w'))
Beispiel #3
0
def write(settings_path, settings_data, merge=True):
    """Write data to a settings file.

    :param settings_path: the filepath
    :param settings_data: a dictionary with data
    :param merge: boolean if existing file should be merged with new data
    """
    if settings_path.exists() and merge:  # pragma: no cover
        settings_data = dictmerge(
            ConfigObj(open(str(settings_path))).dict(),
            settings_data
        )
    new = ConfigObj()
    new.update(settings_data)
    new.write(open(str(settings_path), 'bw'))
Beispiel #4
0
def write(settings_path, settings_data, merge=True):
    """Write data to a settings file.

    :param settings_path: the filepath
    :param settings_data: a dictionary with data
    :param merge: boolean if existing file should be merged with new data
    """
    if settings_path.exists() and merge:  # pragma: no cover
        existing = DynaconfDict()
        load(existing, str(settings_path))
        settings_data = dictmerge(existing, settings_data)
    with open(str(settings_path), 'w') as f:
        f.writelines([
            "{} = {}\n".format(k.upper(), repr(v))
            for k, v in settings_data.items()
        ])