-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
31 lines (29 loc) · 1.12 KB
/
utils.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
import os, sys
import cantools
def get_dbc_files(keyword: str = None) -> cantools.db.Database:
# Get all the DBC files for parsing and add them together
try:
path_name = 'dbc-files'
file_path = []
file_count = 0
for root, dirs, files in os.walk(path_name, topdown=False):
for name in files:
if ".dbc" in name or ".DBC" in name:
if keyword is not None:
if keyword in name:
fp = os.path.join(root, name)
file_path.append(fp)
file_count += 1
else:
fp = os.path.join(root, name)
file_path.append(fp)
file_count += 1
except:
print('failed, no dbc files found.')
sys.exit(0)
mega_dbc=cantools.database.Database()
for filename in file_path:
with open (filename, 'r') as newdbc:
mega_dbc.add_dbc(newdbc)
print('Step 1: found ' + str(file_count) + ' files in the ' + path_name + ' folder')
return mega_dbc