You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

40 lines
962 B

#!/bin/python3
# Find all tags <build-id /> and replace it with the current
# git commit id (short notation)
import sys
import json
import re
import subprocess
buildId = subprocess.check_output(["git", "rev-parse", "--verify", "--short", "HEAD"]).decode('utf-8')[:-1]
def ReplaceBuildIdTagsInChapter(chapter):
# Easy-peasy-lemon-squeezy regex substitution
chapter['content'] = re.sub(
r'<build-id />',
buildId,
chapter['content']
)
def Recursive_TraverseAllChapters(chapter):
ReplaceBuildIdTagsInChapter(chapter)
for subsection in chapter['sub_items']:
Recursive_TraverseAllChapters(subsection['Chapter'])
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == "supports":
sys.exit(0)
context, book = json.load(sys.stdin)
for section in book['sections']:
Recursive_TraverseAllChapters(section['Chapter'])
print(json.dumps(book))