Skip to content

Commit

Permalink
a tool generate filelist based on IAR *.dep file
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoMCU committed Jun 20, 2018
1 parent 6b5056d commit 7dadc45
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions si4project_filelist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'''
This tool will generate source insight 4 project file list
from IAR build output file (*.dep),then we can import the
file list in the source insight 4 project.
'''
import os
import sys
import xml.etree.ElementTree as ET
from datetime import datetime

# 1、Find all .dep files and selete one
items = os.listdir()
sourcefilelist = []
for names in items:
if names.endswith(".dep"):
sourcefilelist.append(names)

sourcefile = ''

listsize = len(sourcefilelist)
if listsize > 1:
print("There are multiple .dep file:")
for index in range(0, listsize):
print("%d %s" % (index+1, sourcefilelist[index]))

print("Enter the index num to selete one:")
strin = input()
if strin.isdigit():
selnum = int(strin)
if (selnum < (listsize + 1)):
sourcefile = sourcefilelist[selnum - 1]
else:
print("Please restart the tool, the input shounld be a number")
sys.exit(0)

elif listsize == 1:
sourcefile = sourcefilelist[0]
else:
sourcefile = ''
sys.exit(0)

#2、parse the seleted dep file
tree = ET.ElementTree(file=sourcefile)
tag_cfg_list = tree.findall('configuration')
output_tag = ''

listsize = len(tag_cfg_list)
if listsize > 1:
print("There are multiple configuration:")
for index in range(0, listsize):
print("%d %s" % (index+1, tag_cfg_list[index].find('name').text))

print("Enter the index num to selete one:")
strin = input()
if strin.isdigit():
selnum = int(strin)
if (selnum < (listsize + 1)):
output_tag = tag_cfg_list[selnum - 1].find('outputs')
else:
print("Please restart the tool, the input shounld be a number")
sys.exit(0)

elif listsize == 1:
output_tag = tag_cfg_list[0].find('outputs')
else:
sys.exit(0)

si4filelist = []
for elem in output_tag.iterfind('file'):
if elem.text.startswith('$PROJ_DIR$'):
if elem.text.endswith('.c'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
elif elem.text.endswith('.h'):
si4filelist.append(os.path.abspath(elem.text.replace('$PROJ_DIR$', os.getcwd()))+'\n')
'''
elif elem.text.startswith('$TOOLKIT_DIR$'):
print(elem.text)
'''

#3、save the lists
outputfile = open(os.path.splitext(sourcefile)[0]+'.si4project_filelist.txt', 'w')
outputfile.write('; Source Insight Project File List\n')
outputfile.write('; Project Name: '+os.path.splitext(sourcefile)[0]+'\n')
outputfile.write('; Generated by si4project_filelist.py at '+datetime.now().strftime('%Y/%m/%d %H:%M:%S')+'\n')
outputfile.write('; Version=4.00.xxxx\n')
outputfile.write(';\n')
outputfile.write('; Each line should contain either a file name, a wildcard, or a sub-directory name.\n')
outputfile.write('; File paths are relative to the project source root directory.\n')
outputfile.write(';\n')
outputfile.writelines(si4filelist)
outputfile.close()

0 comments on commit 7dadc45

Please sign in to comment.