Created
June 23, 2023 12:50
-
-
Save stoyanK7/9519c7c1358ffdc8ab3998cecc3b774d to your computer and use it in GitHub Desktop.
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
# 1. Place in src/xdocs folder | |
# 2. Run python3 script.py | |
import os | |
import re | |
from lxml import etree | |
folders = ['checks', 'filters', 'filefilters'] | |
for folder in folders: | |
dir = os.path.join(folder) | |
for root, dirs, files in os.walk(dir): | |
for filename in files: | |
if filename == "index.xml": | |
continue | |
file_path = os.path.join(root, filename) | |
file_tree = etree.parse(file_path) | |
# Get module name from title, i.e. AbstractClassName | |
module_name = file_tree.xpath('//*[local-name()="title"]')[0].text | |
# Read file contents | |
with open(file_path, 'r') as input_file: | |
contents = input_file.read() | |
# Replace id="AbstractClassName_ with id=" | |
# Essentially removing the module name and underscore after from the id | |
pattern = re.compile(rf'id="{module_name}_') | |
new_contents = pattern.sub('id="', contents) | |
# Write back to file | |
with open(file_path, 'w') as output_file: | |
output_file.write(new_contents) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment