From c1770036aca72ef91515df4736127567fce80eaf Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 6 Mar 2019 22:20:07 -0800 Subject: [PATCH] made the add_db code much simpler --- compiler/datasheet/add_db.py | 33 +++++++++++---------------------- compiler/datasheet/table_gen.py | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/compiler/datasheet/add_db.py b/compiler/datasheet/add_db.py index f0f69fc7..d708985f 100644 --- a/compiler/datasheet/add_db.py +++ b/compiler/datasheet/add_db.py @@ -14,36 +14,25 @@ def get_file_tree(path): def parse_html(file, comment): start_tag = '' + end_tag = comment+'-->' - with open(file, 'r+') as f: + with open(file, 'r') as f: + file_string = f.read() - 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) + with open(file, 'w') as f: + file_string = file_string.replace(start_tag,"") + file_string = file_string.replace(end_tag,"") + + f.write(file_string) + def uncomment(comments): + comment_files = [] 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) + parse_html(datasheet, comment) datasheet_list = get_file_tree(path_to_files) comments = ['.db'] diff --git a/compiler/datasheet/table_gen.py b/compiler/datasheet/table_gen.py index 82cb3393..227bb5c4 100644 --- a/compiler/datasheet/table_gen.py +++ b/compiler/datasheet/table_gen.py @@ -40,7 +40,7 @@ class table_gen: html += '' + html += ''+row[0]+'-->' html += '' html += ''