From 7dadc459fd7b36d110bece47ce41020f04a5b6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=85=B4?= <704168417@qq.com> Date: Wed, 20 Jun 2018 22:21:04 +0800 Subject: [PATCH] a tool generate filelist based on IAR *.dep file --- si4project_filelist.py | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 si4project_filelist.py diff --git a/si4project_filelist.py b/si4project_filelist.py new file mode 100644 index 0000000..c403262 --- /dev/null +++ b/si4project_filelist.py @@ -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() +