forked from QIICR/dcm2tables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQDBDParser.py
33 lines (27 loc) · 885 Bytes
/
QDBDParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os, sys
# take name of the file produced by https://app.quickdatabasediagrams.com
# return dictionary with the mapping of the tables to the attributes
# ignore comments, settings, and connections
class QDBDParser:
def __init__(self,fileName):
self.tables = {}
with open(fileName,'r') as f:
content = f.readlines()
# ignore comments and everything after the space
content = [c for c in content if not c.startswith("#")]
content = [c.split('#')[0].split(' ')[0].strip() for c in content]
readTableName = True
tableName = None
for c in content:
if not len(c):
tableName = None
continue
if c == '-':
continue
if tableName is None:
tableName = c
self.tables[tableName] = []
else:
self.tables[tableName].append(c)
def getTablesSchema(self):
return self.tables