Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

refactor:simplify file operations

author: pixel
date: 2026-07-22 09:37
hash: a36060f19554d3804ebacb7a1af45afd5bf4b97c

Diffstat:

M

src/fileops.py
21 ++++++++++--------------------
 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
diff --git a/src/fileops.py b/src/fileops.py
index 0cad009..d426346 100644
--- a/src/fileops.py
+++ b/src/fileops.py
@@ -4,17 +4,15 @@ from .modules import Tree
 def is_dotfile(file_path):
     return any(part.startswith(".") for part in path.normpath(file_path).split(sep))

-def write_file(file_path: str, file_content: str) -> None:
+def write_file(file_path, file_content):
     with open(file_path, "w") as f:
         f.write(file_content)

-def read_file(file_path:str) -> str:
-    """Read and return file contents"""
-    with open(file_path, "r") as f :
+def read_file(file_path):
+    with open(file_path, "r") as f:
         return f.read()

-def resolve_tree_paths(project_dir: str, tree: Tree) -> Tree:
-    """Return a new Tree with all paths joined onto project_dir."""
+def resolve_tree_paths(project_dir, tree):
     return Tree(
         markdown=path.join(project_dir, tree.markdown),
         static=path.join(project_dir, tree.static),
@@ -24,11 +22,6 @@ def resolve_tree_paths(project_dir: str, tree: Tree) -> Tree:
         plugins=path.join(project_dir, tree.plugins),
     )

-def create_tree_dirs (tree:Tree) -> None:
-    """ Creates parent dirs before start writing """
-    makedirs(tree.markdown , exist_ok=True)
-    makedirs(tree.static   , exist_ok=True)
-    makedirs(tree.templates, exist_ok=True)
-    makedirs(tree.draft_dest     , exist_ok=True)
-    makedirs(tree.release_dest   , exist_ok=True)
-    makedirs(tree.plugins  , exist_ok=True)
+def create_tree_dirs(tree):
+    for d in [tree.markdown, tree.static, tree.templates, tree.draft_dest, tree.release_dest, tree.plugins]:
+        makedirs(d, exist_ok=True)