コード例 #1
0
ファイル: config.py プロジェクト: rlaphoenix/pynfogen
def config(ctx: click.Context, key: Optional[str], value: Optional[str],
           unset: bool, list_: bool) -> None:
    """Manage configuration."""
    if not key and not value and not list_:
        return click.echo(config.get_help(ctx))

    log = logging.getLogger("config")

    if list_:
        print(pytomlpp.dumps(data).rstrip())
        return

    tree = key.split(".")
    temp = data
    for t in tree[:-1]:
        if temp.get(t) is None:
            temp[t] = {}
        temp = temp[t]

    if unset:
        if tree[-1] in temp:
            del temp[tree[-1]]
        log.info(f"Unset {key}")
    else:
        if value is None:
            if tree[-1] not in temp:
                raise click.ClickException(
                    f"Key {key} does not exist in the config.")
            print(f"{key}: {temp[tree[-1]]}")
        else:
            temp[tree[-1]] = value
            log.info(f"Set {key} to {repr(value)}")
            Files.config.parent.mkdir(parents=True, exist_ok=True)
            pytomlpp.dump(data, Files.config)
コード例 #2
0
def test_round_trip_for_valid_toml_files(toml_file):
    with open(str(toml_file), "r") as f:
        text = f.read()
    print(text.strip(), end="\n\n")
    table = pytomlpp.loads(text)
    print(table, end="\n\n")

    text2 = pytomlpp.dumps(table)
    print(text2, end="\n\n")
    table2 = pytomlpp.loads(text2)
    assert table == table2
コード例 #3
0
def updateTotalOccurences(total_occurences):
    with open(path + "/~temp-powersearch-config.toml", "w+") as file:
        try:
            file.write(
                pytomlpp.dumps({
                    "path": path,
                    "keyword": keyword,
                    "encoding": encoding,
                    "include_dot_dirs": include_dot_dirs,
                    "include_dot_files": include_dot_files,
                    "include_no_ext": include_no_ext,
                    "show_errors": show_errors,
                    "show_received": show_received,
                    "show_read": show_read,
                    "show_skipped": show_skipped,
                    "case_sensitive": case_sensitive,
                    "save_temp_config": save_temp_config,
                    "total_occurences": total_occurences,
                }))
        except Exception as e:
            print("ERROR: Failed to update ~temp-powersearch-config.toml")
コード例 #4
0
 def dumps(self, obj):
     refactor_object(obj)
     ready_obj = TomlSerializer.restructure_primitives(refactor_object(obj))
     return toml.dumps(ready_obj)
コード例 #5
0
ファイル: parser.py プロジェクト: Dezorgon/ISP_lab2
 def dumps(self, obj) -> str:
     return pytomlpp.dumps(serialize(obj))
コード例 #6
0
def test_invalid_encode():
    class A:
        pass
    with pytest.raises(TypeError):
        pytomlpp.dumps({'a': A()})
コード例 #7
0
 def dumps(self, obj: object) -> str:
     return pytomlpp.dumps(to_dict(obj))
コード例 #8
0
ファイル: iuninertoml.py プロジェクト: IUniner/isp-lp2
def dump(s, fp):
    replace_values(s, None, NULL_STRING)
    pp = toml.dumps(s)
    fp.write(pp)
コード例 #9
0
ファイル: iuninertoml.py プロジェクト: IUniner/isp-lp2
def dumps(d: dict):
    replace_values(d, None, NULL_STRING)
    return toml.dumps(d)
コード例 #10
0
ファイル: filesystem.py プロジェクト: alexrutar/texproject
 def dump(self, target: Path) -> None:
     target.write_text(toml.dumps(self))
コード例 #11
0
 def dumps(obj):
     packed = convert(obj)
     return pytomlpp.dumps(packed)