Fix update_toc.py script to stop appending empty lines

This commit is contained in:
Maciej Pytel 2017-06-30 14:18:18 +02:00
parent de1f95f302
commit 94528ab209
2 changed files with 5 additions and 13 deletions

View File

@ -493,14 +493,3 @@ required to activate them:
https://github.com/kubernetes/autoscaler/pull/74#issuecomment-302434795). https://github.com/kubernetes/autoscaler/pull/74#issuecomment-302434795).
We are aware that this process is tedious and we will work to improve it. We are aware that this process is tedious and we will work to improve it.

View File

@ -22,11 +22,14 @@ QUESTION_PREFIX = "### "
def updateFAQ(): def updateFAQ():
with open("FAQ.md","r") as faq_file: with open("FAQ.md","r") as faq_file:
faq_content = faq_file.read() faq_content = faq_file.read()
faq_lines = faq_content.splitlines()
while faq_lines and faq_lines[-1] == '':
faq_lines = faq_lines[:-1]
prefixes = (SECTION_PREFIX, QUESTION_PREFIX) prefixes = (SECTION_PREFIX, QUESTION_PREFIX)
toc_elements = [] toc_elements = []
after_toc = False after_toc = False
for line in faq_content.splitlines(): for line in faq_lines:
if line.strip() == "<!--- TOC END -->": if line.strip() == "<!--- TOC END -->":
after_toc = True after_toc = True
if not after_toc: if not after_toc:
@ -40,7 +43,7 @@ def updateFAQ():
in_toc = False in_toc = False
with open("FAQ.md","w") as faq_file: with open("FAQ.md","w") as faq_file:
for line in faq_content.split("\n"): for line in faq_lines:
if line.strip() == "<!--- TOC BEGIN -->": if line.strip() == "<!--- TOC BEGIN -->":
in_toc = True in_toc = True
faq_file.write(line +"\n") faq_file.write(line +"\n")