Skip to content

Commit 5b7cd37

Browse files
authored
optimize code
1 parent 8b9d10b commit 5b7cd37

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

__main__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def main(pack_path: str, xml_path: str):
5858
if not os.path.isabs(pack_path):
5959
pack_path = os.path.abspath(pack_path)
6060

61+
if not os.path.isfile(pack_path):
62+
raise Exception('error, \'{}\' is not a file !'.format(pack_path))
63+
6164
jlink_root_dir = os.path.dirname(xml_path)
6265

6366
print('-> Use cmsis package : ' + pack_path)
@@ -88,15 +91,15 @@ def main(pack_path: str, xml_path: str):
8891
continue
8992
for ele in node.iter():
9093
if ele.tag == 'ChipInfo':
91-
vendor_existed_devs.append(ele.attrib.get('Name'))
94+
if ele.attrib.get('Vendor') == vendor_name:
95+
vendor_existed_devs.append(ele.attrib.get('Name'))
9296

93-
print('exsited devices: ' + str(vendor_existed_devs))
97+
print('Vendor \'{}\' existed devices: {}'.format(vendor_name, str(vendor_existed_devs)))
9498

9599
# add comment header
96-
if len(vendor_existed_devs) == 0:
97-
xml_dom_db.append(ElementTree.Comment(''))
98-
xml_dom_db.append(ElementTree.Comment(' {} ({}) '.format(vendor_name, dev_familys[0])))
99-
xml_dom_db.append(ElementTree.Comment(''))
100+
xml_dom_db.append(ElementTree.Comment(''))
101+
xml_dom_db.append(ElementTree.Comment(' {} ({}) '.format(vendor_name, dev_familys[0])))
102+
xml_dom_db.append(ElementTree.Comment(''))
100103

101104
ign_cnt = 0
102105

@@ -134,7 +137,7 @@ def main(pack_path: str, xml_path: str):
134137
n_ele_fbi = SubElement(n_ele, 'FlashBankInfo')
135138
name = '{} ({})'.format(rom.name, rom.type.name)
136139
if rom.is_boot_memory:
137-
name = '{} (Internal Flash)'.format(rom.name)
140+
name = 'Internal Flash'
138141
algo_src_repath = flm_ele.attrib['name']
139142
algo_dst_repath = 'Devices/{}/{}/{}'.format(
140143
vendor_name, family_name, os.path.basename(algo_src_repath))

0 commit comments

Comments
 (0)