From 3802c537e51164c15895752eda4b8de426c6d678 Mon Sep 17 00:00:00 2001
From: Jesse Cirimelli-Low
Date: Wed, 27 Feb 2019 22:19:03 -0800
Subject: [PATCH] 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
| Type | Description | Link |
|---|
|
'
+ with open(file, 'r+') as f:
+
+ file_string = f.read()
+ start_byte = file_string.find(start_tag) + len(start_tag)
+ row = '
| .db | Compiled .lib file | '+str(os.path.basename(db))+' |
'
+ 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)