OpenRAM/compiler/datasheet/add_db.py

50 lines
1.2 KiB
Python
Raw Normal View History

# See LICENSE for licensing information.
#
2023-01-29 07:56:27 +01:00
# Copyright (c) 2016-2023 Regents of the University of California and The Board
2019-06-14 17:43:41 +02:00
# of Regents for the Oklahoma Agricultural and Mechanical College
# (acting for and on behalf of Oklahoma State University)
# All rights reserved.
#
import sys
2022-11-27 22:01:20 +01:00
import os
import glob
from pathlib import Path
# 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:
2020-11-03 15:29:17 +01:00
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,"")
2020-11-03 15:29:17 +01:00
2019-03-07 07:20:07 +01:00
f.write(file_string)
2020-11-03 15:29:17 +01:00
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)