bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / utils / bsc_md / pipeline.py

pipeline.py (4216B)


      1 import os
      2 
      3 from .config import (
      4     FILES_LIST, BSC_ROOT, DOCS_OUTPUT,
      5     ALGO_FOLDER_NAME, SUPPORTED_LANGS, PROTECTED_INDEX_FILES,
      6 )
      7 from .formatting import derive_tags
      8 from .parsers import parse_c_style, parse_hash_style, parse_algo_md
      9 from .builders import build_md, build_algo_md
     10 from .indexing import create_folder_indexes
     11 
     12 
     13 def run():
     14     with open(FILES_LIST, 'r', encoding='utf-8') as f:
     15         file_paths = [line.strip() for line in f if line.strip()]
     16 
     17     generated = skipped = 0
     18 
     19     for full_path in file_paths:
     20         full_path = os.path.normpath(full_path)
     21         ext = os.path.splitext(full_path)[1].lower()
     22 
     23         # Handle algorithm .md files
     24         if ext == '.md':
     25             parent_folder = os.path.basename(os.path.dirname(full_path))
     26             if parent_folder.lower() != ALGO_FOLDER_NAME:
     27                 print(f"SKIP (non-algo .md): {full_path}")
     28                 skipped += 1
     29                 continue
     30 
     31             try:
     32                 with open(full_path, 'r', encoding='utf-8', errors='ignore') as f:
     33                     content_md = f.read()
     34             except FileNotFoundError:
     35                 print(f"NOT FOUND: {full_path}")
     36                 skipped += 1
     37                 continue
     38 
     39             filename_base = os.path.splitext(os.path.basename(full_path))[0]
     40             rel_path = os.path.relpath(full_path, BSC_ROOT)
     41             title, problem_statement, body_lines = parse_algo_md(content_md)
     42             if not title:
     43                 title = filename_base
     44             rel_url_algo = rel_path.replace('\\', '/')
     45             algo_tags = derive_tags(rel_path)
     46             md_content = build_algo_md(
     47                 filename_base, title, problem_statement, body_lines, rel_url_algo, algo_tags
     48             )
     49 
     50             rel_path = os.path.relpath(full_path, BSC_ROOT)
     51             md_rel = os.path.splitext(rel_path)[0] + '.md'
     52             md_out = os.path.normpath(os.path.join(DOCS_OUTPUT, md_rel))
     53 
     54             if md_out in PROTECTED_INDEX_FILES and os.path.exists(md_out):
     55                 print(f"SKIP (Protected Index File): {md_out}")
     56                 skipped += 1
     57                 continue
     58 
     59             os.makedirs(os.path.dirname(md_out), exist_ok=True)
     60             with open(md_out, 'w', encoding='utf-8') as f:
     61                 f.write(md_content)
     62 
     63             print(f"OK  {md_rel}")
     64             generated += 1
     65             continue
     66 
     67         if ext not in SUPPORTED_LANGS:
     68             print(f"SKIP (unsupported extension): {full_path}")
     69             skipped += 1
     70             continue
     71 
     72         lang_info = SUPPORTED_LANGS[ext]
     73 
     74         try:
     75             rel_path = os.path.relpath(full_path, BSC_ROOT)
     76         except ValueError:
     77             print(f"SKIP (relpath failed): {full_path}")
     78             skipped += 1
     79             continue
     80 
     81         rel_url = rel_path.replace('\\', '/')
     82 
     83         try:
     84             with open(full_path, 'r', encoding='utf-8', errors='ignore') as f:
     85                 content = f.read()
     86         except FileNotFoundError:
     87             print(f"NOT FOUND: {full_path}")
     88             skipped += 1
     89             continue
     90 
     91         filename = os.path.basename(full_path)
     92 
     93         if lang_info['style'] == 'c':
     94             problem_statement, code = parse_c_style(content)
     95         else:
     96             problem_statement, code = parse_hash_style(content)
     97 
     98         file_tags = derive_tags(rel_path, lang_info['label'])
     99         md_content = build_md(
    100             filename, lang_info['label'], lang_info['fence'],
    101             problem_statement, code, rel_url, file_tags,
    102         )
    103 
    104         md_rel = os.path.splitext(rel_path)[0] + '.md'
    105         md_out = os.path.normpath(os.path.join(DOCS_OUTPUT, md_rel))
    106 
    107         if md_out in PROTECTED_INDEX_FILES and os.path.exists(md_out):
    108             print(f"SKIP (Protected Index File): {md_out}")
    109             skipped += 1
    110             continue
    111 
    112         os.makedirs(os.path.dirname(md_out), exist_ok=True)
    113         with open(md_out, 'w', encoding='utf-8') as f:
    114             f.write(md_content)
    115 
    116         print(f"OK  {md_rel}")
    117         generated += 1
    118 
    119     print(f"\nDone - {generated} generated, {skipped} skipped.")
    120     print("Generating folder index pages...")
    121     create_folder_indexes(DOCS_OUTPUT)
    122     print("Folder indexes created.")
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror