forked from ClusterLabs/crmsh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: doc/toolchain: implement adocaio (ClusterLabs#1374)
a preprocessor for asciidoc inlcude directive to generate an all-in-one adoc file
- Loading branch information
1 parent
bf6c866
commit 7dd6a1e
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python3 | ||
"""Preprocessor for include:: directive""" | ||
|
||
|
||
import os.path | ||
import re | ||
import sys | ||
|
||
|
||
RE_INCLUDE_DIRECTIVE = re.compile('^include::(.*)\\[]\\s*$') | ||
|
||
|
||
def all_in_one(path: str, out): | ||
dir = os.path.dirname(os.path.abspath(path)) | ||
with open(path, 'r', encoding='utf-8') as f: | ||
for line in f: | ||
found = RE_INCLUDE_DIRECTIVE.match(line) | ||
if not found: | ||
out.write(line) | ||
else: | ||
included_filepath = f'{dir}/{found.group(1)}' | ||
all_in_one(included_filepath, out) | ||
|
||
|
||
def main(): | ||
if len(sys.argv) != 2: | ||
print(f'usage: {sys.argv[0]} [infile]') | ||
sys.exit(1) | ||
all_in_one(sys.argv[1], sys.stdout) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |