示例#1
0
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")
 def dumps(self, obj):
     refactor_object(obj)
     ready_obj = TomlSerializer.restructure_primitives(refactor_object(obj))
     return toml.dumps(ready_obj)
示例#5
0
 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
def dump(s, fp):
    replace_values(s, None, NULL_STRING)
    pp = toml.dumps(s)
    fp.write(pp)
示例#9
0
def dumps(d: dict):
    replace_values(d, None, NULL_STRING)
    return toml.dumps(d)
示例#10
0
 def dump(self, target: Path) -> None:
     target.write_text(toml.dumps(self))
示例#11
0
 def dumps(obj):
     packed = convert(obj)
     return pytomlpp.dumps(packed)