64 lines
1 KiB
Python
64 lines
1 KiB
Python
|
import os as _os
|
||
|
import json as _json
|
||
|
import subprocess as _subprocess
|
||
|
import functools as _functools
|
||
|
|
||
|
|
||
|
def convey(
|
||
|
x,
|
||
|
fs
|
||
|
):
|
||
|
y = x
|
||
|
for f in fs:
|
||
|
y = f(y)
|
||
|
return y
|
||
|
|
||
|
|
||
|
def file_text_read(
|
||
|
path : str
|
||
|
) -> str:
|
||
|
handle = open(path, "r")
|
||
|
content = handle.read()
|
||
|
handle.close()
|
||
|
return content
|
||
|
|
||
|
|
||
|
def file_binary_read(
|
||
|
path : str
|
||
|
) -> str:
|
||
|
handle = open(path, "rb")
|
||
|
content = handle.read()
|
||
|
handle.close()
|
||
|
return content
|
||
|
|
||
|
|
||
|
def file_text_write(
|
||
|
path : str,
|
||
|
content : str
|
||
|
):
|
||
|
_os.makedirs(_os.path.dirname(path), exist_ok = True)
|
||
|
handle = open(path, "w" if _os.path.exists(path) else "a")
|
||
|
handle.write(content)
|
||
|
handle.close()
|
||
|
|
||
|
|
||
|
def file_binary_write(
|
||
|
path : str,
|
||
|
content
|
||
|
):
|
||
|
_os.makedirs(_os.path.dirname(path), exist_ok = True)
|
||
|
handle = open(path, ("w" if _os.path.exists(path) else "a") + "b")
|
||
|
handle.write(content)
|
||
|
handle.close()
|
||
|
|
||
|
|
||
|
def string_coin(
|
||
|
template : str,
|
||
|
arguments : dict[str,str]
|
||
|
) -> str:
|
||
|
result = template
|
||
|
for (key, value, ) in arguments.items():
|
||
|
result = result.replace("{{%s}}" % key, value)
|
||
|
return result
|
||
|
|