Files
ss-tools/merge_spec.py

67 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [DEF:MergeSpec:Module]
# @PURPOSE: Utility to merge specs
# @TIER: TRIVIAL
# @COMPLEXITY: 1
# @RELATION: [DEPENDS_ON] builtin
# [DEF:merge_spec:Module]
# @PURPOSE: Utility script for merge_spec
# @TIER: TRIVIAL
# @COMPLEXITY: 1
import os
import sys
from datetime import datetime
from pathlib import Path
def merge_specs(feature_number):
specs_dir = Path("specs")
if not specs_dir.exists():
print("Error: 'specs' directory not found.")
return
# Find the directory starting with the feature number
target_dir = None
for item in specs_dir.iterdir():
if item.is_dir() and item.name.startswith(f"{feature_number}-"):
target_dir = item
break
if not target_dir:
print(f"Error: No directory found for feature number '{feature_number}' in 'specs/'.")
return
feature_name = target_dir.name
now = datetime.now().strftime("%Y%m%d-%H%M%S")
output_filename = f"{feature_name}-{now}.md"
content_blocks = ["Мой коллега предложил такую фичу, оцени ее\n"]
# Recursively find all files
files_to_merge = sorted([f for f in target_dir.rglob("*") if f.is_file()])
for file_path in files_to_merge:
relative_path = file_path.relative_to(target_dir)
try:
with open(file_path, "r", encoding="utf-8") as f:
file_content = f.read()
content_blocks.append(f"--- FILE: {relative_path} ---\n")
content_blocks.append(file_content)
content_blocks.append("\n")
except Exception as e:
print(f"Skipping file {file_path} due to error: {e}")
with open(output_filename, "w", encoding="utf-8") as f:
f.write("\n".join(content_blocks))
print(f"Successfully created: {output_filename}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python merge_spec.py <feature_number>")
sys.exit(1)
merge_specs(sys.argv[1])
# [/DEF:merge_spec:Module]
# [/DEF:MergeSpec:Module]