2019-02-28 07:19:03 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
import glob
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
# This is the path to the directory you would like to search
|
|
|
|
|
# This directory is searched recursively for .html files
|
|
|
|
|
|
|
|
|
|
path_to_files = '../temp/'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_file_tree(path):
|
|
|
|
|
return list(Path(path).rglob("*.html"))
|
|
|
|
|
|
|
|
|
|
|
2019-03-07 05:59:52 +01:00
|
|
|
def parse_html(file, comment):
|
|
|
|
|
start_tag = '<!--'+comment
|
|
|
|
|
end_tag = '-->'
|
2019-02-28 07:19:03 +01:00
|
|
|
|
2019-03-07 05:59:52 +01:00
|
|
|
with open(file, 'r+') as f:
|
2019-02-28 07:19:03 +01:00
|
|
|
file_string = f.read()
|
2019-03-07 05:59:52 +01:00
|
|
|
start_byte = file_string.find(start_tag)
|
|
|
|
|
|
|
|
|
|
while(start_byte != -1):
|
|
|
|
|
f.seek(0)
|
|
|
|
|
file_string = f.read()
|
|
|
|
|
start_byte = file_string.find(start_tag)
|
|
|
|
|
end_byte = file_string.find(end_tag) + start_byte + len(end_tag)
|
|
|
|
|
|
|
|
|
|
f.seek(start_byte)
|
|
|
|
|
found = f.read(end_byte - start_byte)
|
|
|
|
|
|
|
|
|
|
file_string = "%s%s%s" % (
|
|
|
|
|
file_string[:start_byte], found[len(start_tag):len(found)-len(end_tag)] , file_string[end_byte:])
|
|
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
|
|
f.write(file_string)
|
|
|
|
|
start_byte = file_string.find(start_tag)
|
|
|
|
|
end_byte = file_string.find(end_tag) + start_byte + len(end_tag)
|
|
|
|
|
|
|
|
|
|
def uncomment(comments):
|
|
|
|
|
for datasheet in datasheet_list:
|
|
|
|
|
for comment in comments:
|
|
|
|
|
if glob.glob(os.path.dirname(datasheet)+'/*' + comment):
|
|
|
|
|
comment_files = list(Path(os.path.dirname(datasheet)).rglob('*'+comment))
|
|
|
|
|
for comment_file in comment_files:
|
|
|
|
|
parse_html(datasheet, comment)
|
2019-02-28 07:19:03 +01:00
|
|
|
|
|
|
|
|
datasheet_list = get_file_tree(path_to_files)
|
2019-03-07 05:59:52 +01:00
|
|
|
comments = ['.db']
|
|
|
|
|
uncomment(comments)
|
|
|
|
|
|