-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_write_file.py
71 lines (56 loc) · 1.03 KB
/
func_write_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python3.9
from pathlib import Path
from typing import Mapping
from utils import util_path_fixer
from utils import util_verif_str
_JOBNAME="write-file"
def job(
path_dest:Path,
content:str,
):
print(
"→ Writing to a file" "\n"
"\t" f"To: {path_dest}" "\n"
)
path_dest.parent.mkdir(exist_ok=True,parents=True)
if path_dest.exists():
if not path_dest.is_file():
return False
try:
if path_dest.is_file():
path_dest.unlink()
path_dest.write_text(
content.strip()
)
except Exception as exc:
print(
"\tError while writing to the file:",
exc
)
return False
return True
def main(
arguments:Mapping,
path_basedir:Path
)->bool:
# write-file:
# dest: Path
# content: |
# ...
path_dest_str=util_verif_str(
arguments.get("dest")
)
if not path_dest_str:
return False
content=util_verif_str(arguments.get("content"))
if not isinstance(content,str):
return False
return (
job(
util_path_fixer(
Path(path_dest_str),
path_basedir
),
content
)
)