haraka 0.2.32__py3-none-any.whl → 0.2.34__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- haraka/post_gen/service/fileOps/purge.py +77 -54
- {haraka-0.2.32.dist-info → haraka-0.2.34.dist-info}/METADATA +1 -1
- {haraka-0.2.32.dist-info → haraka-0.2.34.dist-info}/RECORD +5 -5
- {haraka-0.2.32.dist-info → haraka-0.2.34.dist-info}/WHEEL +0 -0
- {haraka-0.2.32.dist-info → haraka-0.2.34.dist-info}/top_level.txt +0 -0
@@ -23,6 +23,7 @@ from __future__ import annotations
|
|
23
23
|
from pathlib import Path
|
24
24
|
|
25
25
|
from pathspec import PathSpec
|
26
|
+
from typing import Tuple, List
|
26
27
|
|
27
28
|
from haraka.post_gen.service.fileOps.files import FileOps
|
28
29
|
from haraka.utils import Logger, divider
|
@@ -34,6 +35,12 @@ _MANIFEST_DIR = Path(__file__).resolve().parent.parent.parent / "manifests"
|
|
34
35
|
# --------------------------------------------------------------------------- #
|
35
36
|
# main purger #
|
36
37
|
# --------------------------------------------------------------------------- #
|
38
|
+
def is_dir_protected(rel: str, spec: PathSpec) -> bool:
|
39
|
+
"""True if *rel* (or an ancestor) is matched by keep spec."""
|
40
|
+
# `spec.match_file` already walks ancestors for dirs
|
41
|
+
return spec.match_file(rel)
|
42
|
+
|
43
|
+
|
37
44
|
class ResourcePurger:
|
38
45
|
"""Filesystem cleaner driven by variant manifest files."""
|
39
46
|
|
@@ -70,71 +77,87 @@ class ResourcePurger:
|
|
70
77
|
for pattern in keep_patterns:
|
71
78
|
self._log.debug(f"Keep pattern: {pattern}")
|
72
79
|
|
73
|
-
self.
|
80
|
+
all_paths = self._walk_tree(project_dir)
|
81
|
+
|
82
|
+
matched, non_dirs, non_files, _ = self.classify_paths(all_paths, project_dir, spec)
|
83
|
+
|
84
|
+
self.print_summary(matched, non_dirs, non_files)
|
85
|
+
|
74
86
|
self._log.debug(f"Finished purging unrelated paths in project directory: {project_dir}")
|
75
87
|
|
76
88
|
divider("Project tree after purge…")
|
77
89
|
self._f.print_tree(project_dir)
|
78
90
|
|
79
|
-
# ----------------------------- internals ------------------------------ #
|
80
|
-
def _purge_unrelated(self, root: Path, spec: PathSpec) -> None:
|
81
|
-
"""
|
82
|
-
Walk the project tree; delete every path NOT matched by *spec*.
|
83
|
-
|
84
|
-
Updated to align with the `test_java_manifest` logic for cleaner organization.
|
85
|
-
"""
|
86
|
-
|
87
|
-
# Dictionaries to separate matches and non-matches for logging
|
88
91
|
|
89
|
-
|
90
|
-
all_paths = list(root.rglob("*"))
|
91
|
-
if self._log.evm:
|
92
|
-
self._log.debug(f"📋 All paths under {root} (total {len(all_paths)}):")
|
93
|
-
for p in all_paths:
|
94
|
-
print(f"{p.relative_to(root)}")
|
95
|
-
else:
|
96
|
-
self._log.debug(f"Found {len(all_paths)} paths under {root})")
|
92
|
+
# ----------------------------- internals ------------------------------ #
|
97
93
|
|
98
|
-
|
99
|
-
|
100
|
-
|
94
|
+
def _walk_tree(self, root: Path) -> List[Path]:
|
95
|
+
"""Return every file/dir under *root*, logging the walk."""
|
96
|
+
paths = list(root.rglob("*"))
|
97
|
+
self._log.debug(f"📋 All paths under {root} (total {len(paths)}:")
|
98
|
+
for p in paths:
|
99
|
+
self._log.debug(f" {p.relative_to(root)}")
|
100
|
+
return paths
|
101
|
+
|
102
|
+
|
103
|
+
# --------------------------------------------------------------------------- #
|
104
|
+
# Classification helpers #
|
105
|
+
# --------------------------------------------------------------------------- #
|
106
|
+
|
107
|
+
def classify_paths(
|
108
|
+
self,
|
109
|
+
paths: List[Path], root: Path, spec: PathSpec
|
110
|
+
) -> Tuple[List[str], List[str], List[str], List[str]]:
|
111
|
+
"""Split paths into keep/delete buckets."""
|
112
|
+
matched: List[str] = []
|
113
|
+
non_matched_files: List[str] = []
|
114
|
+
non_matched_dirs: List[str] = []
|
115
|
+
directories_skipped: List[str] = []
|
116
|
+
|
117
|
+
for path in paths:
|
101
118
|
rel = path.relative_to(root).as_posix()
|
102
|
-
self._log.debug(f"Relative path for inspection: {rel}")
|
103
|
-
# Match file against the PathSpec
|
104
|
-
if spec.match_file(rel):
|
105
|
-
self._log.debug(f"✅ KEEP: Path matches keep patterns: {rel}")
|
106
|
-
matches.append(path) # Collect paths to keep
|
107
|
-
else:
|
108
|
-
if path.is_dir():
|
109
|
-
if self._is_dir_protected(rel, spec):
|
110
|
-
self._log.debug(f"{"⏭️ SKIPPING DELETE: Protected ancestor found: %s", path}")
|
111
|
-
directories_skipped.append(rel)
|
112
|
-
else:
|
113
|
-
self._log.debug(f"{"❌ DELETE DIR: %s", rel}")
|
114
|
-
self._f.remove_dir(path)
|
115
|
-
non_matched_dirs.append(rel)
|
116
|
-
else:
|
117
|
-
non_matched_files.append(rel)
|
118
|
-
self._f.remove_file(path)
|
119
|
-
self._log.debug(f"{"❌ DELETE FILE: %s", rel}")
|
120
119
|
|
121
|
-
|
122
|
-
|
120
|
+
if spec.match_file(rel):
|
121
|
+
self._log.debug(f"✅ KEEP {rel}")
|
122
|
+
matched.append(rel)
|
123
|
+
continue
|
123
124
|
|
124
125
|
if path.is_dir():
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
126
|
+
if is_dir_protected(rel, spec):
|
127
|
+
self._log.debug(f"⏭️ SKIPPING DELETE: Protected ancestor found: {path}")
|
128
|
+
directories_skipped.append(rel)
|
129
|
+
else:
|
130
|
+
self._log.debug(f"❌ DELETE DIR: {rel}")
|
131
|
+
non_matched_dirs.append(rel)
|
132
|
+
else:
|
133
|
+
non_matched_files.append(rel)
|
134
|
+
|
135
|
+
return matched, non_matched_dirs, non_matched_files, directories_skipped
|
136
|
+
|
137
|
+
# --------------------------------------------------------------------------- #
|
138
|
+
# Summary printing helpers #
|
139
|
+
# --------------------------------------------------------------------------- #
|
140
|
+
def _print_section(self, title: str, items: List[str]) -> None:
|
141
|
+
self._log.info(f"{title} — {len(items)}")
|
142
|
+
if items:
|
143
|
+
for p in sorted(items):
|
144
|
+
self._log.info(f" • {p}")
|
145
|
+
else:
|
146
|
+
self._log.info(" (none)")
|
147
|
+
self._log.info("-" * 70)
|
148
|
+
|
149
|
+
def print_summary(
|
150
|
+
self,
|
151
|
+
matched: List[str],
|
152
|
+
non_matched_dirs: List[str],
|
153
|
+
non_matched_files: List[str],
|
154
|
+
) -> None:
|
155
|
+
"""Human-friendly digest of keep/delete results."""
|
156
|
+
self._log.info("\n" + "=" * 70)
|
157
|
+
self._print_section("✅ MATCHED (keep)", matched)
|
158
|
+
self._print_section("🗂️ NON-MATCHED DIRECTORIES (delete)", non_matched_dirs)
|
159
|
+
self._print_section("📄 NON-MATCHED FILES (delete)", non_matched_files)
|
160
|
+
self._log.info("=" * 70)
|
138
161
|
|
139
162
|
@staticmethod
|
140
163
|
def _is_dir_protected(relative_path: str, spec: PathSpec) -> bool:
|
@@ -17,7 +17,7 @@ haraka/post_gen/service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
17
17
|
haraka/post_gen/service/command.py,sha256=yvEzW9rMSXWeQ_2DXuQNtGH6sRuZnK6viMud-amFQXw,2348
|
18
18
|
haraka/post_gen/service/fileOps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
haraka/post_gen/service/fileOps/files.py,sha256=Jm_0bhvVnNqSPGKQ2RnMpx8JLV74M-IXMmwly9fpmVw,3020
|
20
|
-
haraka/post_gen/service/fileOps/purge.py,sha256=
|
20
|
+
haraka/post_gen/service/fileOps/purge.py,sha256=1jqQfbvDykpl4R6iaJio3mdOy9eV8lSH7ZjygBWbhck,6297
|
21
21
|
haraka/post_gen/service/gitOps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
22
|
haraka/post_gen/service/gitOps/gitops.py,sha256=clWny1m9qB4yr8asba8JwqBjewlMVsJUmIOCLtAL8RI,4052
|
23
23
|
haraka/utils/__init__.py,sha256=3Cp4u0dyAGcmqes-tIr95KFsNsJx5Ji5Yzkto9546Hs,168
|
@@ -29,7 +29,7 @@ haraka/utils/manifests/go-grpc-gateway-buf.yml,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
|
|
29
29
|
haraka/utils/manifests/go-grpc-protoc.yml,sha256=OaQlfW_S_OguhW_UcpBVdqdEtUMlg-SrT4bqLhQrY7Y,936
|
30
30
|
haraka/utils/manifests/java-springboot.yml,sha256=DTZoVrIDNVpq2AuuXjL2jAvPggeKWVuKJEKwFb90cz4,989
|
31
31
|
haraka/utils/manifests/python-fastapi.yml,sha256=nhO6S9j_r-S10nM8nuw7PtR247-ePhBXHvaXg74CjWw,922
|
32
|
-
haraka-0.2.
|
33
|
-
haraka-0.2.
|
34
|
-
haraka-0.2.
|
35
|
-
haraka-0.2.
|
32
|
+
haraka-0.2.34.dist-info/METADATA,sha256=hL7ItQWrGCLTsfE4VO3smO0Mh5EmmkjjoQcwRbJwnyM,579
|
33
|
+
haraka-0.2.34.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
34
|
+
haraka-0.2.34.dist-info/top_level.txt,sha256=1khpwypLKWoklVd_CgFiwAfcctVSXRoRPc3BI9lyIXo,7
|
35
|
+
haraka-0.2.34.dist-info/RECORD,,
|
File without changes
|
File without changes
|