scripts/docs_add_banner: Fix several issues

* Fix a syntax error causing the script to fail
* Skip symlinks files (symlink directories were already skipped)
* Drop unneeded whitespace
* Abstract path join to a variable

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2022-06-03 10:49:41 +01:00
parent 5dd90ea43b
commit 9d7820da27

View File

@ -9,13 +9,8 @@
#
#
import os
html_content_dunfell = '''
<div id="outdated-warning">This document is outdated, you should select the <a href="https://docs.yoctoproject.org/dunfell">latest release version</a> in this series.</div>
<div xml:lang="en" class="body" lang="en">
@ -69,15 +64,18 @@ def add_banner_old_docs(dir):
html_replacement = html_content
for filename in filenames:
fullfile = os.path.join(root, filename)
if os.path.islink(fullfile):
continue
if filename.endswith('.html'):
with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f:
with open(fullfile, 'r', encoding="ISO-8859-1") as f:
current_content = f.read()
with open(os.path.join(root, filename), 'w', encoding="ISO-8859-1") as f:
f.write(current_content.replace('<body>', '<body>' + html_replacement)).replace('</body>', last_div + '</body>'))
if filename.endswith('.css'):
with open(os.path.join(root, filename), 'r', encoding="ISO-8859-1") as f:
with open(fullfile, 'w', encoding="ISO-8859-1") as f:
f.write(current_content.replace('<body>', '<body>' + html_replacement).replace('</body>', last_div + '</body>'))
elif filename.endswith('.css'):
with open(fullfile, 'r', encoding="ISO-8859-1") as f:
css_content = f.read()
with open(os.path.join(root, filename), 'w', encoding="ISO-8859-1") as f:
with open(fullfile, 'w', encoding="ISO-8859-1") as f:
f.write(css_content.replace(css_content[css_content.find('body {'):css_content.find('}'[0])], 'body {' + css_replacement_content ))
add_banner_old_docs('.')