Unverified Commit 98808fb5 authored by Richard Berger's avatar Richard Berger
Browse files

Skip doc files that don't have common file structure

parent 8d1a117b
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
#!/usr/bin/env python3
# Utility script to fix headers in doc pages and generate "Accelerator Styles" portion
import os
import shutil
import re
import argparse
@@ -16,10 +17,12 @@ for orig_file in args.files:
    styles = []
    headings = {}
    new_file = f"{orig_file}.tmp"
    found_syntax = False

    with open(orig_file, 'r') as reader, open(new_file, 'w') as writer:
        for line in reader:
            if line.startswith("Syntax"):
                found_syntax = True
                break

            m = index_pattern.match(line)
@@ -43,6 +46,7 @@ for orig_file in args.files:
                elif style not in headings[base_name]:
                    headings[base_name].append(style)

        if found_syntax:
            # write new header
            for s in styles:
                print(f".. index:: {command_type} {s}", file=writer)
@@ -65,5 +69,8 @@ for orig_file in args.files:
            for line in reader:
                print(line, end="", file=writer)

    if found_syntax:
        # override original file
        shutil.move(new_file, orig_file)
    else:
        os.remove(new_file)