From 546ed838a489b1510da5c65496e3db5abad4b21f Mon Sep 17 00:00:00 2001 From: SteveSamJacob19 Date: Thu, 4 Jul 2024 14:50:37 +0530 Subject: [PATCH 1/2] added validation --- scripts/build/parse_features_toc.py | 35 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/scripts/build/parse_features_toc.py b/scripts/build/parse_features_toc.py index e0cf8a9b5e..26e900d7ab 100755 --- a/scripts/build/parse_features_toc.py +++ b/scripts/build/parse_features_toc.py @@ -297,22 +297,25 @@ def sort_versions_for(feature, high_to_low=True): print("Modifying the docs TOCs of version " + version + " to remove the duplicate feature versions.") feature_version_path = featurePath + version for root, dirs, files in os.walk(feature_version_path): - for basename in files: - if fnmatch.fnmatch(basename, "*.html"): - if(basename != "index.html"): - href = path.join(root, basename) - page = BeautifulSoup(open(href), "lxml") - - # Find the toc and replace it with the modified toc - page_toc = page.find_all('ul', {'class': 'nav-list'})[0] - if page_toc.find('span', text='Features') is not None: - toc_to_replace = page_toc.find('span', text='Features').parent - elif page_toc.find('a', text='Features') is not None: - toc_to_replace = page_toc.find('a', text='Features').parent - toc_to_replace.clear() - toc_to_replace.append(featureTOC) - with open(href, "w") as file: - file.write(str(page)) + if "../" not in root: + for basename in files: + if fnmatch.fnmatch(basename, "*.html"): + if(basename != "index.html"): + href = path.join(root, basename) + page = BeautifulSoup(open(href), "lxml") + + # Find the toc and replace it with the modified toc + page_toc = page.find_all('ul', {'class': 'nav-list'})[0] + if page_toc.find('span', text='Features') is not None: + toc_to_replace = page_toc.find('span', text='Features').parent + elif page_toc.find('a', text='Features') is not None: + toc_to_replace = page_toc.find('a', text='Features').parent + toc_to_replace.clear() + toc_to_replace.append(featureTOC) + with open(href, "w") as file: + file.write(str(page)) + else: + print("invalid") timerEnd = time.time() print('Total execution time for parsing ToC Features: ', timerEnd - timerStart) From 9103fb84f114cfdfefcaab5a12bd2dbd651a23fd Mon Sep 17 00:00:00 2001 From: SteveSamJacob19 Date: Thu, 4 Jul 2024 14:53:15 +0530 Subject: [PATCH 2/2] made some edits --- scripts/build/parse_features_toc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build/parse_features_toc.py b/scripts/build/parse_features_toc.py index 26e900d7ab..05192fa039 100755 --- a/scripts/build/parse_features_toc.py +++ b/scripts/build/parse_features_toc.py @@ -315,7 +315,7 @@ def sort_versions_for(feature, high_to_low=True): with open(href, "w") as file: file.write(str(page)) else: - print("invalid") + print("Invalid path for root") timerEnd = time.time() print('Total execution time for parsing ToC Features: ', timerEnd - timerStart)