From 3802c537e51164c15895752eda4b8de426c6d678 Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 27 Feb 2019 22:19:03 -0800 Subject: [PATCH 1/5] added add_db.py to add .db files to datasheets --- compiler/datasheet/add_db.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 compiler/datasheet/add_db.py diff --git a/compiler/datasheet/add_db.py b/compiler/datasheet/add_db.py new file mode 100644 index 00000000..1df3cf7b --- /dev/null +++ b/compiler/datasheet/add_db.py @@ -0,0 +1,34 @@ +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")) + + +def parse_html(file, db): + start_tag = 'Deliverables

' + with open(file, 'r+') as f: + + file_string = f.read() + start_byte = file_string.find(start_tag) + len(start_tag) + row = '' + file_string = "%s%s%s" % ( + file_string[:start_byte], row, file_string[start_byte:]) + f.seek(0) + f.write(file_string) + + +datasheet_list = get_file_tree(path_to_files) +for datasheet in datasheet_list: + if glob.glob(os.path.dirname(datasheet)+'/*.db'): + db_files = list(Path(os.path.dirname(datasheet)).rglob("*.db")) + for db_file in db_files: + parse_html(datasheet, db_file) From fac9ff9be632ccd9118d771b825aa89a114ef0d3 Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 6 Mar 2019 20:59:52 -0800 Subject: [PATCH 2/5] changed add_db.py to uncommenting method --- compiler/datasheet/add_db.py | 47 ++++++++++++++++++++--------- compiler/datasheet/datasheet.py | 15 +++++---- compiler/datasheet/datasheet_gen.py | 5 +++ compiler/datasheet/table_gen.py | 25 ++++++++++----- 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/compiler/datasheet/add_db.py b/compiler/datasheet/add_db.py index 1df3cf7b..f0f69fc7 100644 --- a/compiler/datasheet/add_db.py +++ b/compiler/datasheet/add_db.py @@ -12,23 +12,40 @@ def get_file_tree(path): return list(Path(path).rglob("*.html")) -def parse_html(file, db): - start_tag = 'Deliverables

TypeDescriptionLink
.dbCompiled .lib file'+str(os.path.basename(db))+'
' - with open(file, 'r+') as f: +def parse_html(file, comment): + start_tag = '' + with open(file, 'r+') as f: file_string = f.read() - start_byte = file_string.find(start_tag) + len(start_tag) - row = '' - file_string = "%s%s%s" % ( - file_string[:start_byte], row, file_string[start_byte:]) - f.seek(0) - f.write(file_string) + 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) datasheet_list = get_file_tree(path_to_files) -for datasheet in datasheet_list: - if glob.glob(os.path.dirname(datasheet)+'/*.db'): - db_files = list(Path(os.path.dirname(datasheet)).rglob("*.db")) - for db_file in db_files: - parse_html(datasheet, db_file) +comments = ['.db'] +uncomment(comments) + diff --git a/compiler/datasheet/datasheet.py b/compiler/datasheet/datasheet.py index a7700349..a21d3dae 100644 --- a/compiler/datasheet/datasheet.py +++ b/compiler/datasheet/datasheet.py @@ -38,6 +38,9 @@ class datasheet(): with open(os.path.abspath(os.environ.get("OPENRAM_HOME")) + '/datasheet/assets/OpenRAM_logo.png', "rb") as image_file: openram_logo = base64.b64encode(image_file.read()) + #comment table rows which we may want to enable after compile time + comments = ['.db'] + self.html += 'VLSIDAOpenRAM'.format(str(vlsi_logo)[2:-1], str(openram_logo)[2:-1]) self.html += '

' + \ @@ -51,11 +54,11 @@ class datasheet(): 'Git commit id: ' + str(self.git_id) + '

' # print port table self.html += '

Ports and Configuration

' - self.html += self.io_table.to_html() + self.html += self.io_table.to_html(comments) # print operating condidition information self.html += '

Operating Conditions

' - self.html += self.operating_table.to_html() + self.html += self.operating_table.to_html(comments) # check if analytical model is being used self.html += '

Timing Data

' @@ -66,13 +69,13 @@ class datasheet(): model = "spice characterizer" # display timing data self.html += '

Using '+model+'

' - self.html += self.timing_table.to_html() + self.html += self.timing_table.to_html(comments) # display power data self.html += '

Power Data

' - self.html += self.power_table.to_html() + self.html += self.power_table.to_html(comments) # display corner information self.html += '

Characterization Corners

' - self.html += self.corners_table.to_html() + self.html += self.corners_table.to_html(comments) # display deliverables table self.html += '

Deliverables

' - self.html += self.dlv_table.to_html() + self.html += self.dlv_table.to_html(comments) diff --git a/compiler/datasheet/datasheet_gen.py b/compiler/datasheet/datasheet_gen.py index 3b4fe2ac..e6c728f0 100644 --- a/compiler/datasheet/datasheet_gen.py +++ b/compiler/datasheet/datasheet_gen.py @@ -386,6 +386,9 @@ def parse_characterizer_csv(f, pages): [PROC, VOLT, TEMP, LIB_NAME.replace(OUT_DIR, '').replace(NAME, '')]) new_sheet.dlv_table.add_row( ['.lib', 'Synthesis models', '{1}'.format(LIB_NAME, LIB_NAME.replace(OUT_DIR, ''))]) + new_sheet.dlv_table.add_row( + ['.db', 'Compiled .lib', '{1}'.format(LIB_NAME[:-3] + 'db', LIB_NAME.replace(OUT_DIR, '')[:-3] + 'db')]) + if found == 0: @@ -603,6 +606,8 @@ def parse_characterizer_csv(f, pages): ['.html', 'This datasheet', '{0}.{1}'.format(OPTS.output_name, 'html')]) new_sheet.dlv_table.add_row( ['.lib', 'Synthesis models', '{1}'.format(LIB_NAME, LIB_NAME.replace(OUT_DIR, ''))]) + new_sheet.dlv_table.add_row( + ['.db', 'Compiled .lib', '{1}'.format(LIB_NAME[:-3] + 'db', LIB_NAME.replace(OUT_DIR, '')[:-3] + 'db')]) new_sheet.dlv_table.add_row( ['.py', 'OpenRAM configuration file', '{0}.{1}'.format(OPTS.output_name, 'py')]) new_sheet.dlv_table.add_row( diff --git a/compiler/datasheet/table_gen.py b/compiler/datasheet/table_gen.py index 8f94e896..a03fea8c 100644 --- a/compiler/datasheet/table_gen.py +++ b/compiler/datasheet/table_gen.py @@ -22,27 +22,36 @@ class table_gen: html += '' return html - def gen_table_body(self): + def gen_table_body(self,comments): """generate html body (used after gen_table_head)""" html = '' html += '' html += '' for row in self.rows[1:]: - html += '' - for col in row: - html += '' - html += '' + + if row[0] not in comments: + html += '' + for col in row: + html += '' + html += '' + + else: + html += '' + html += '' html += '' return html - def to_html(self): + def to_html(self,comments): """writes table_gen object to inline html""" html = '' html += '
TypeDescriptionLink
.dbCompiled .lib file'+str(os.path.basename(db))+'
' + str(col) + '
' + str(col) + '
' html += self.gen_table_head() - html += self.gen_table_body() - html += '
' + html += self.gen_table_body(comments) + html += '\n' return html From 83e810f8b89fde9144c916954a980aa70f3ca89c Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 6 Mar 2019 21:12:21 -0800 Subject: [PATCH 3/5] added sorting to deliverables output --- compiler/datasheet/datasheet.py | 1 + compiler/datasheet/table_gen.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/compiler/datasheet/datasheet.py b/compiler/datasheet/datasheet.py index a21d3dae..b48d217d 100644 --- a/compiler/datasheet/datasheet.py +++ b/compiler/datasheet/datasheet.py @@ -78,4 +78,5 @@ class datasheet(): self.html += self.corners_table.to_html(comments) # display deliverables table self.html += '

Deliverables

' + self.dlv_table.sort() self.html += self.dlv_table.to_html(comments) diff --git a/compiler/datasheet/table_gen.py b/compiler/datasheet/table_gen.py index a03fea8c..82cb3393 100644 --- a/compiler/datasheet/table_gen.py +++ b/compiler/datasheet/table_gen.py @@ -45,6 +45,8 @@ class table_gen: html += '' html += '' return html + def sort(self): + self.rows[1:] = sorted(self.rows[1:], key=lambda x : x[0]) def to_html(self,comments): """writes table_gen object to inline html""" From c1770036aca72ef91515df4736127567fce80eaf Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 6 Mar 2019 22:20:07 -0800 Subject: [PATCH 4/5] 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 += '' From 4754e6851d20db5454e00c6620fa9908e34da266 Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 6 Mar 2019 22:21:05 -0800 Subject: [PATCH 5/5] add_db takes commline line argv for path --- compiler/datasheet/add_db.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/datasheet/add_db.py b/compiler/datasheet/add_db.py index d708985f..862c1d8a 100644 --- a/compiler/datasheet/add_db.py +++ b/compiler/datasheet/add_db.py @@ -1,11 +1,12 @@ 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 = '../temp/' +path_to_files = sys.argv[1] def get_file_tree(path):