Skip doc files that don't have common file structure
This commit is contained in:
@ -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)
|
||||||
@ -42,28 +45,32 @@ for orig_file in args.files:
|
|||||||
headings[style] = []
|
headings[style] = []
|
||||||
elif style not in headings[base_name]:
|
elif style not in headings[base_name]:
|
||||||
headings[base_name].append(style)
|
headings[base_name].append(style)
|
||||||
|
|
||||||
# write new header
|
|
||||||
for s in styles:
|
|
||||||
print(f".. index:: {command_type} {s}", file=writer)
|
|
||||||
|
|
||||||
print(file=writer)
|
if found_syntax:
|
||||||
|
# write new header
|
||||||
|
for s in styles:
|
||||||
|
print(f".. index:: {command_type} {s}", file=writer)
|
||||||
|
|
||||||
for s, variants in headings.items():
|
|
||||||
header = f"{command_type} {s} command"
|
|
||||||
print(header, file=writer)
|
|
||||||
print("="*len(header), file=writer)
|
|
||||||
print(file=writer)
|
print(file=writer)
|
||||||
|
|
||||||
if len(variants) > 0:
|
for s, variants in headings.items():
|
||||||
print("Accelerator Variants: ", end="", file=writer)
|
header = f"{command_type} {s} command"
|
||||||
print(", ".join([f"*{v}*" for v in variants]), file=writer)
|
print(header, file=writer)
|
||||||
|
print("="*len(header), file=writer)
|
||||||
print(file=writer)
|
print(file=writer)
|
||||||
|
|
||||||
# write rest of reader
|
if len(variants) > 0:
|
||||||
print(line, end="", file=writer)
|
print("Accelerator Variants: ", end="", file=writer)
|
||||||
for line in reader:
|
print(", ".join([f"*{v}*" for v in variants]), file=writer)
|
||||||
print(line, end="", file=writer)
|
print(file=writer)
|
||||||
|
|
||||||
# override original file
|
# write rest of reader
|
||||||
shutil.move(new_file, orig_file)
|
print(line, end="", file=writer)
|
||||||
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user