2018-09-08 12:14:56 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
import toml
|
|
|
|
|
|
|
|
|
|
|
|
def quote(s: str) -> str:
|
|
|
|
escaped = s.replace('"', r"\"").replace("\n", r"\n").replace("\\", "\\\\")
|
|
|
|
return '"{}"'.format(escaped)
|
|
|
|
|
2018-09-08 12:14:56 +00:00
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
def main() -> None:
|
|
|
|
data = toml.load(sys.stdin)
|
2018-09-08 12:14:56 +00:00
|
|
|
|
2022-06-26 05:07:01 +00:00
|
|
|
# There is no dependency to vendor in this project.
|
|
|
|
if not list(data.keys()) == ["source"]:
|
|
|
|
return
|
2018-09-08 12:14:56 +00:00
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
# this value is non deterministic
|
|
|
|
data["source"]["vendored-sources"]["directory"] = "@vendor@"
|
2018-09-08 12:14:56 +00:00
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
lines = []
|
|
|
|
inner = data["source"]
|
|
|
|
for source, attrs in sorted(inner.items()):
|
|
|
|
lines.append("[source.{}]".format(quote(source)))
|
|
|
|
if source == "vendored-sources":
|
|
|
|
lines.append('"directory" = "@vendor@"\n')
|
|
|
|
else:
|
|
|
|
for key, value in sorted(attrs.items()):
|
|
|
|
attr = "{} = {}".format(quote(key), quote(value))
|
|
|
|
lines.append(attr)
|
|
|
|
lines.append("")
|
2018-09-08 12:14:56 +00:00
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
result = "\n".join(lines)
|
|
|
|
real = toml.loads(result)
|
|
|
|
assert real == data, "output = {} while input = {}".format(real, data)
|
2018-09-08 12:14:56 +00:00
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
print(result)
|
2018-09-08 12:14:56 +00:00
|
|
|
|
|
|
|
|
2018-09-11 20:49:16 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|