-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunpacker.py
More file actions
73 lines (55 loc) · 2.17 KB
/
Copy pathunpacker.py
File metadata and controls
73 lines (55 loc) · 2.17 KB
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
72
73
# unpacker.py V2.0 (Improved Security & Performance)
import re
import os
import sys
def unpack_project(markdown_file_path: str):
print(f"--- Evo Unpacker v2.0 ---")
print(f"Reading: {markdown_file_path}\n")
try:
with open(markdown_file_path, 'r', encoding='utf-8-sig') as f:
content = f.read()
except Exception as e:
print(f"❌ [Error] Cannot read file: {e}", file=sys.stderr)
return
# File header pattern
HEADER_PATTERN = re.compile(
r"^(?:# === FILENAME:|### file:|# --- FILENAME:|# FILENAME:)\s*(.*?)\s*$",
re.MULTILINE | re.IGNORECASE
)
CLEAN_DELIMITER = "\n---EVO-FILE-START---\n"
def replace_header(match):
filename = match.group(1).strip().replace("===", "").strip()
return f"{CLEAN_DELIMITER}{filename}\n"
content = HEADER_PATTERN.sub(replace_header, content)
file_blocks = [b for b in content.split(CLEAN_DELIMITER) if b.strip()]
if not file_blocks:
print("Error: Could not find file blocks in markdown.", file=sys.stderr)
return
created_count = 0
for block in file_blocks:
parts = block.strip().split('\n', 1)
if len(parts) < 2:
continue
file_path = parts[0].strip()
file_content = parts[1].rstrip() + "\n"
if not file_path:
continue
try:
directory = os.path.dirname(file_path)
if directory and not os.path.exists(directory):
os.makedirs(directory, exist_ok=True)
print(f" [Directory Created] {directory}/")
with open(file_path, 'w', encoding='utf-8') as f:
f.write(file_content)
print(f"✅ [File Created] {file_path}")
created_count += 1
except Exception as e:
print(f"❌ [Error] Failed to create {file_path}: {e}", file=sys.stderr)
print(f"\n--- Complete ---")
print(f"Total {created_count} files successfully unpacked.")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python unpacker.py [markdown_filename]")
print("Example: python unpacker.py blackjack.md")
else:
unpack_project(sys.argv[1])