OpenRAM/compiler/datasheet/add_db.py

42 lines
947 B
Python
Raw Normal View History

from pathlib import Path
import glob
import os
import sys
# This is the path to the directory you would like to search
# This directory is searched recursively for .html files
path_to_files = sys.argv[1]
def get_file_tree(path):
return list(Path(path).rglob("*.html"))
def parse_html(file, comment):
start_tag = '<!--'+comment
2019-03-07 07:20:07 +01:00
end_tag = comment+'-->'
2019-03-07 07:20:07 +01:00
with open(file, 'r') as f:
file_string = f.read()
2019-03-07 07:20:07 +01:00
with open(file, 'w') as f:
2019-03-07 07:20:07 +01:00
file_string = file_string.replace(start_tag,"")
file_string = file_string.replace(end_tag,"")
f.write(file_string)
def uncomment(comments):
2019-03-07 07:20:07 +01:00
comment_files = []
for datasheet in datasheet_list:
for comment in comments:
if glob.glob(os.path.dirname(datasheet)+'/*' + comment):
2019-03-07 07:20:07 +01:00
parse_html(datasheet, comment)
datasheet_list = get_file_tree(path_to_files)
comments = ['.db']
uncomment(comments)