OpenRAM/compiler/datasheet/add_db.py

49 lines
1.2 KiB
Python
Raw Normal View History

# See LICENSE for licensing information.
#
2019-05-06 15:50:15 +02:00
#Copyright (c) 2016-2019 Regents of the University of California and The Board
#of Regents for the Oklahoma Agricultural and Mechanical College
#(acting for and on behalf of Oklahoma State University)
#All rights reserved.
#
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)