Skip doc files that don't have common file structure

This commit is contained in:
Richard Berger
2020-09-02 11:04:08 -04:00
parent 8d1a117b75
commit 98808fb5ff

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Utility script to fix headers in doc pages and generate "Accelerator Styles" portion # Utility script to fix headers in doc pages and generate "Accelerator Styles" portion
import os
import shutil import shutil
import re import re
import argparse import argparse
@ -16,10 +17,12 @@ for orig_file in args.files:
styles = [] styles = []
headings = {} headings = {}
new_file = f"{orig_file}.tmp" new_file = f"{orig_file}.tmp"
found_syntax = False
with open(orig_file, 'r') as reader, open(new_file, 'w') as writer: with open(orig_file, 'r') as reader, open(new_file, 'w') as writer:
for line in reader: for line in reader:
if line.startswith("Syntax"): if line.startswith("Syntax"):
found_syntax = True
break break
m = index_pattern.match(line) m = index_pattern.match(line)
@ -43,6 +46,7 @@ for orig_file in args.files:
elif style not in headings[base_name]: elif style not in headings[base_name]:
headings[base_name].append(style) headings[base_name].append(style)
if found_syntax:
# write new header # write new header
for s in styles: for s in styles:
print(f".. index:: {command_type} {s}", file=writer) print(f".. index:: {command_type} {s}", file=writer)
@ -65,5 +69,8 @@ for orig_file in args.files:
for line in reader: for line in reader:
print(line, end="", file=writer) print(line, end="", file=writer)
if found_syntax:
# override original file # override original file
shutil.move(new_file, orig_file) shutil.move(new_file, orig_file)
else:
os.remove(new_file)