-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
2655 lines (2296 loc) · 134 KB
/
main.py
File metadata and controls
2655 lines (2296 loc) · 134 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
主应用程序
嵌入式固件管理工具 - 带GUI界面的Windows应用程序
"""
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox, filedialog
import json
import os
import sys
from lib_logger import logger
import threading
import queue
from datetime import datetime
from pathlib import Path
from typing import Optional
# 导入自定义模块
from git_manager import GitManager
from builder_factory import BuilderFactory
from project_analyzer_factory import ProjectAnalyzerFactory
from binary_modifier import BinaryModifier
from file_manager_factory import FileManagerFactory
from version_manager import VersionManager
from info_manager_factory import InfoManagerFactory
from path_manager_factory import PathManagerFactory
from tool_version_manager import ToolVersionManager
from version import VERSION
# 语言配置
LANGUAGES = {
'zh_CN': {
'name': '简体中文',
'texts': {
'app_title': '嵌入式固件管理工具',
'project_path': '项目路径:',
'iar_path': '编译工具路径:',
'check_git': '检查Git状态',
'check_version': '检查版本',
'start_build': '开始编译',
'open_settings': '设置',
'open_firmware': '本地发布目录',
'status_ready': '就绪',
'status_checking': '检查中...',
'status_building': '编译中...',
'project_info': '项目信息',
'firmware_version': '固件版本:',
'git_status': 'Git状态:',
'iar_path_display': '编译工具路径:',
'flash_start_addr': 'Flash起始地址:',
'settings_title': '设置',
'project_settings': '项目设置',
'binary_settings': '二进制设置',
'compile_tool': '编译工具:',
'iar_installation_path': 'IAR安装目录:',
'mdk_installation_path': 'MDK安装目录:',
'fw_publish_directory': '本地发布目录:',
'remote_publish_directory': '远程发布目录:',
'enable_remote_publish': '启用远程发布',
'bin_start_address': 'bin起始地址:',
'config_file': '配置文件:',
'language': '语言:',
'select_directory': '选择目录',
'select': '选择',
'save': '保存',
'cancel': '取消',
'example_bin_address': '(例如: 0x8000000)',
'browse': '浏览',
'log_output': '日志输出',
'success': '成功',
'error': '错误',
'warning': '警告',
'info': '信息',
'not_checked': '未检查',
'not_configured': '未配置',
'msg_error': '错误',
'msg_success': '成功',
'msg_warning': '警告',
'msg_info': '信息',
'msg_config_error': '配置错误',
'msg_config_incomplete': '配置不完整',
'msg_compile_failed': '编译失败',
'msg_modify_failed': '修改失败',
'msg_file_process_failed': '文件处理失败',
'msg_firmware_publish_failed': '固件发布失败',
'msg_firmware_publish_error': '固件发布异常',
'msg_cleanup_complete': '清理完成',
'msg_cleanup_failed': '清理失败',
'msg_settings_saved': '设置已保存',
'msg_bin_address_format_error': 'bin起始地址格式错误',
'msg_save_settings_failed': '保存设置失败',
'msg_select_directory_error': '选择目录时出错',
'msg_open_directory_failed': '打开目录失败',
'msg_open_firmware_directory_failed': '打开固件目录失败',
'msg_select_config_file_error': '选择配置文件时出错',
'msg_select_iar_directory_error': '选择IAR目录时出错',
'msg_not_git_repo': '当前目录不是Git仓库',
'msg_cannot_get_commit_id': '无法获取commit ID',
'feature_settings': '功能设置',
'enable_git_commit_id': 'Git提交ID',
'enable_file_size': '文件大小',
'enable_bin_checksum': '二进制校验和',
'enable_hash_value': '哈希校验和',
'git_commit_id_keyword': 'Git提交ID变量:',
'file_size_keyword': '文件大小变量:',
'bin_checksum_keyword': '二进制校验和变量:',
'hash_value_keyword': '哈希校验和变量:',
'firmware_version_keyword': '固件版本变量:',
'add_timestamp_to_filename': 'bin文件名添加时间戳',
'publish_out_file': '发布.out文件',
'feature_settings_desc': '选择要启用的功能模块,禁用后相关功能将不会执行',
'msg_compile_success_no_bin': '编译成功但未找到输出bin文件',
'msg_compile_complete': '编译完成!',
'msg_compile_exception': '编译流程异常',
'msg_firmware_directory_not_exist': '固件发布目录不存在',
'msg_remote_publish_directory_not_exist': '远程发布目录不存在',
'msg_remote_publish_success': '远程发布成功',
'msg_remote_publish_failed': '远程发布失败',
'msg_config_file_analysis_failed': '配置文件分析失败',
'msg_check_config_file_pragma': '请检查配置文件是否包含正确的#pragma location定义。',
'git_commit_dialog_title': '提交信息 & Release Notes',
'git_commit_dialog_message': '请输入本次提交的更新信息(将同时用于Git提交和Release Notes):',
'git_commit_dialog_placeholder': '例如:修复了某个bug,添加了新功能等...\n\n注意:提交描述会自动添加"发布xxxx版本"前缀\n\n快捷键:Ctrl+Enter 确认,Escape 取消',
'git_commit_dialog_ok': '确定',
'git_commit_dialog_cancel': '取消',
'release_note_title': 'Release Notes',
'release_note_created': 'Release note文件已创建',
'release_note_updated': 'Release note文件已更新',
'enabled': '启用',
'disabled': '未启用',
'bin_address_auto_note': '注意:bin起始地址现在从ICF文件自动获取,无需手动配置',
'build_configuration': '编译配置:',
'not_selected': '未选择',
'refresh_config': '刷新配置',
'no_valid_configs': '未找到有效配置',
'no_configs_found': '未找到有效的编译配置',
'refresh_config_failed': '刷新配置失败',
'invalid_project_path': '项目路径无效,无法刷新配置',
'config_parse_failed': '解析项目配置失败',
'no_project_file': '未找到项目文件',
'configs_found': '找到 {count} 个配置: {names}',
'current_selection': '当前选择: {name}',
'config_selected': '选择配置: {name}',
'output_directory': '输出目录: {dir}',
'debug_mode': 'Debug模式: {mode}',
'config_selection_failed': '配置选择失败',
'checking_git_status': '检查Git状态中...',
'not_git_repo_status': '当前目录不是Git仓库',
'has_uncommitted_changes': '检测到未提交的更改',
'git_workdir_clean': 'Git工作区干净,可以编译',
'git_check_complete': 'Git状态检查完成',
'checking_firmware_version': '检查固件版本中...',
'version_check_complete': '版本检查完成',
'start_build_process': '开始编译流程...',
'input_update_info': '输入更新信息...',
'committing_changes': '提交更改...',
'updating_version': '更新版本号...',
'updating_release_notes': '更新Release Notes...',
'committing_version_changes': '提交版本号更改和Release Notes...',
'compiling_project': '编译项目中...',
'modifying_binary': '修改二进制文件...',
'processing_files': '处理输出文件...',
'publishing_firmware': '发布固件...',
'publishing_remote': '发布到远程目录...',
'build_process_complete': '编译流程完成',
'language_options': {
'zh_CN': 'zh_CN 简体中文',
'zh_TW': 'zh_TW 繁體中文',
'en_US': 'en_US English'
}
}
},
'zh_TW': {
'name': '繁體中文',
'texts': {
'app_title': 'IAR固件發布工具',
'project_path': '專案路徑:',
'iar_path': '編譯工具路徑:',
'check_git': '檢查Git狀態',
'check_version': '檢查版本',
'start_build': '開始編譯',
'open_settings': '設定',
'open_firmware': '本地發布目錄',
'status_ready': '就緒',
'status_checking': '檢查中...',
'status_building': '編譯中...',
'project_info': '專案資訊',
'firmware_version': '固件版本:',
'git_status': 'Git狀態:',
'iar_path_display': '編譯工具路徑:',
'flash_start_addr': 'Flash起始位址:',
'settings_title': '設定',
'project_settings': '專案設定',
'binary_settings': '二進位設定',
'compile_tool': '編譯工具:',
'iar_installation_path': 'IAR安裝目錄:',
'mdk_installation_path': 'MDK安裝目錄:',
'fw_publish_directory': '本地發布目錄:',
'remote_publish_directory': '遠程發布目錄:',
'enable_remote_publish': '啟用遠程發布',
'bin_start_address': 'bin起始位址:',
'config_file': '配置檔案:',
'language': '語言:',
'select_directory': '選擇目錄',
'select': '選擇',
'save': '儲存',
'cancel': '取消',
'example_bin_address': '(例如: 0x8000000)',
'browse': '瀏覽',
'log_output': '日誌輸出',
'success': '成功',
'error': '錯誤',
'warning': '警告',
'info': '資訊',
'not_checked': '未檢查',
'not_configured': '未配置',
'msg_error': '錯誤',
'msg_success': '成功',
'msg_warning': '警告',
'msg_info': '資訊',
'msg_config_error': '配置錯誤',
'msg_config_incomplete': '配置不完整',
'msg_compile_failed': '編譯失敗',
'msg_modify_failed': '修改失敗',
'msg_file_process_failed': '檔案處理失敗',
'msg_firmware_publish_failed': '固件發布失敗',
'msg_firmware_publish_error': '固件發布異常',
'msg_cleanup_complete': '清理完成',
'msg_cleanup_failed': '清理失敗',
'msg_settings_saved': '設定已儲存',
'msg_bin_address_format_error': 'bin起始位址格式錯誤',
'msg_save_settings_failed': '儲存設定失敗',
'msg_select_directory_error': '選擇目錄時出錯',
'msg_open_directory_failed': '開啟目錄失敗',
'msg_open_firmware_directory_failed': '開啟固件目錄失敗',
'msg_select_config_file_error': '選擇配置檔案時出錯',
'msg_select_iar_directory_error': '選擇IAR目錄時出錯',
'msg_not_git_repo': '當前目錄不是Git倉庫',
'msg_cannot_get_commit_id': '無法獲取commit ID',
'feature_settings': '功能設置',
'enable_git_commit_id': 'Git提交ID',
'enable_file_size': '檔案大小',
'enable_bin_checksum': '二進制校驗和',
'enable_hash_value': '哈希校驗和',
'git_commit_id_keyword': 'Git提交ID變數:',
'file_size_keyword': '文件大小變數:',
'bin_checksum_keyword': '二進制校驗和變數:',
'hash_value_keyword': '哈希校驗和變數:',
'firmware_version_keyword': '固件版本變數:',
'add_timestamp_to_filename': 'bin檔案名添加時間戳',
'publish_out_file': '發布.out檔案',
'feature_settings_desc': '選擇要啟用的功能模組,禁用後相關功能將不會執行',
'msg_compile_success_no_bin': '編譯成功但未找到輸出bin檔案',
'msg_compile_complete': '編譯完成!',
'msg_compile_exception': '編譯流程異常',
'msg_firmware_directory_not_exist': '固件發布目錄不存在',
'msg_remote_publish_directory_not_exist': '遠程發布目錄不存在',
'msg_remote_publish_success': '遠程發布成功',
'msg_remote_publish_failed': '遠程發布失敗',
'msg_config_file_analysis_failed': '配置檔案分析失敗',
'msg_check_config_file_pragma': '請檢查配置檔案是否包含正確的#pragma location定義。',
'git_commit_dialog_title': '提交資訊 & Release Notes',
'git_commit_dialog_message': '請輸入本次提交的更新資訊(將同時用於Git提交和Release Notes):',
'git_commit_dialog_placeholder': '例如:修復了某個bug,添加了新功能等...\n\n注意:提交描述會自動添加"發布xxxx版本"前綴\n\n快捷鍵:Ctrl+Enter 確認,Escape 取消',
'git_commit_dialog_ok': '確定',
'git_commit_dialog_cancel': '取消',
'release_note_title': 'Release Notes',
'release_note_created': 'Release note檔案已建立',
'release_note_updated': 'Release note檔案已更新',
'enabled': '啟用',
'disabled': '未啟用',
'bin_address_auto_note': '注意:bin起始位址現在從ICF檔案自動獲取,無需手動配置',
'build_configuration': '編譯配置:',
'not_selected': '未選擇',
'refresh_config': '刷新配置',
'no_valid_configs': '未找到有效配置',
'no_configs_found': '未找到有效的編譯配置',
'refresh_config_failed': '刷新配置失敗',
'invalid_project_path': '項目路徑無效,無法刷新配置',
'config_parse_failed': '解析項目配置失敗',
'no_project_file': '未找到項目檔案',
'configs_found': '找到 {count} 個配置: {names}',
'current_selection': '當前選擇: {name}',
'config_selected': '選擇配置: {name}',
'output_directory': '輸出目錄: {dir}',
'debug_mode': 'Debug模式: {mode}',
'config_selection_failed': '配置選擇失敗',
'checking_git_status': '檢查Git狀態中...',
'not_git_repo_status': '當前目錄不是Git倉庫',
'has_uncommitted_changes': '檢測到未提交的更改',
'git_workdir_clean': 'Git工作區乾淨,可以編譯',
'git_check_complete': 'Git狀態檢查完成',
'checking_firmware_version': '檢查固件版本中...',
'version_check_complete': '版本檢查完成',
'start_build_process': '開始編譯流程...',
'input_update_info': '輸入更新資訊...',
'committing_changes': '提交更改...',
'updating_version': '更新版本號...',
'updating_release_notes': '更新Release Notes...',
'committing_version_changes': '提交版本號更改和Release Notes...',
'compiling_project': '編譯專案中...',
'modifying_binary': '修改二進制檔案...',
'processing_files': '處理輸出檔案...',
'publishing_firmware': '發布固件...',
'publishing_remote': '發布到遠程目錄...',
'build_process_complete': '編譯流程完成',
'language_options': {
'zh_CN': 'zh_CN 简体中文',
'zh_TW': 'zh_TW 繁體中文',
'en_US': 'en_US English'
}
}
},
'en_US': {
'name': 'English',
'texts': {
'app_title': 'Embedded Firmware Manager',
'project_path': 'Project Path:',
'iar_path': 'Compile Tool Path:',
'check_git': 'Check Git Status',
'check_version': 'Check Version',
'start_build': 'Start Build',
'open_settings': 'Settings',
'open_firmware': 'Local Publish Directory',
'status_ready': 'Ready',
'status_checking': 'Checking...',
'status_building': 'Building...',
'project_info': 'Project Info',
'firmware_version': 'Firmware Version:',
'git_status': 'Git Status:',
'iar_path_display': 'Compile Tool Path:',
'flash_start_addr': 'Flash Start Address:',
'settings_title': 'Settings',
'project_settings': 'Project Settings',
'binary_settings': 'Binary Settings',
'compile_tool': 'Compile Tool:',
'iar_installation_path': 'IAR Installation Path:',
'mdk_installation_path': 'MDK Installation Path:',
'fw_publish_directory': 'Local Publish Directory:',
'remote_publish_directory': 'Remote Publish Directory:',
'enable_remote_publish': 'Enable Remote Publish',
'bin_start_address': 'Bin Start Address:',
'config_file': 'Config File:',
'language': 'Language:',
'select_directory': 'Select Directory',
'select': 'Select',
'save': 'Save',
'cancel': 'Cancel',
'example_bin_address': '(e.g.: 0x8000000)',
'browse': 'Browse',
'log_output': 'Log Output',
'success': 'Success',
'error': 'Error',
'warning': 'Warning',
'info': 'Info',
'not_checked': 'Not Checked',
'not_configured': 'Not Configured',
'msg_error': 'Error',
'msg_success': 'Success',
'msg_warning': 'Warning',
'msg_info': 'Info',
'msg_config_error': 'Configuration Error',
'msg_config_incomplete': 'Configuration Incomplete',
'msg_compile_failed': 'Compilation Failed',
'msg_modify_failed': 'Modification Failed',
'msg_file_process_failed': 'File Processing Failed',
'msg_firmware_publish_failed': 'Firmware Publish Failed',
'msg_firmware_publish_error': 'Firmware Publish Error',
'msg_cleanup_complete': 'Cleanup Complete',
'msg_cleanup_failed': 'Cleanup Failed',
'msg_settings_saved': 'Settings Saved',
'msg_bin_address_format_error': 'Bin Start Address Format Error',
'msg_save_settings_failed': 'Save Settings Failed',
'msg_select_directory_error': 'Error Selecting Directory',
'msg_open_directory_failed': 'Failed to Open Directory',
'msg_open_firmware_directory_failed': 'Failed to Open Firmware Directory',
'msg_select_config_file_error': 'Error Selecting Config File',
'msg_select_iar_directory_error': 'Error Selecting IAR Directory',
'msg_not_git_repo': 'Current directory is not a Git repository',
'msg_cannot_get_commit_id': 'Cannot get commit ID',
'feature_settings': 'Feature Settings',
'enable_git_commit_id': 'Git Commit ID',
'enable_file_size': 'File Size',
'enable_bin_checksum': 'Binary Checksum',
'enable_hash_value': 'Hash Value',
'git_commit_id_keyword': 'Git Commit ID Variable:',
'file_size_keyword': 'File Size Variable:',
'bin_checksum_keyword': 'Binary Checksum Variable:',
'hash_value_keyword': 'Hash Value Variable:',
'firmware_version_keyword': 'Firmware Version Variable:',
'add_timestamp_to_filename': 'Add timestamp to bin filename',
'publish_out_file': 'Publish .out file',
'feature_settings_desc': 'Select which feature modules to enable. Disabled features will not be executed.',
'msg_compile_success_no_bin': 'Compilation successful but no output bin file found',
'msg_compile_complete': 'Compilation Complete!',
'msg_compile_exception': 'Compilation Process Exception',
'msg_firmware_directory_not_exist': 'Firmware publish directory does not exist',
'msg_remote_publish_directory_not_exist': 'Remote publish directory does not exist',
'msg_remote_publish_success': 'Remote publish successful',
'msg_remote_publish_failed': 'Remote publish failed',
'msg_config_file_analysis_failed': 'Config file analysis failed',
'msg_check_config_file_pragma': 'Please check if the config file contains correct #pragma location definitions.',
'git_commit_dialog_title': 'Commit Message & Release Notes',
'git_commit_dialog_message': 'Please enter the update information for this commit (will be used for both Git commit and Release Notes):',
'git_commit_dialog_placeholder': 'e.g.: Fixed a bug, added new feature, etc...\n\nNote: "Release xxxx version" prefix will be added automatically\n\nShortcuts: Ctrl+Enter to confirm, Escape to cancel',
'git_commit_dialog_ok': 'OK',
'git_commit_dialog_cancel': 'Cancel',
'release_note_title': 'Release Notes',
'release_note_created': 'Release note file created',
'release_note_updated': 'Release note file updated',
'enabled': 'Enabled',
'disabled': 'Disabled',
'bin_address_auto_note': 'Note: Bin start address is now automatically obtained from ICF file, no manual configuration needed',
'build_configuration': 'Build Configuration:',
'not_selected': 'Not Selected',
'refresh_config': 'Refresh Config',
'no_valid_configs': 'No Valid Configs Found',
'no_configs_found': 'No Valid Build Configurations Found',
'refresh_config_failed': 'Refresh Config Failed',
'invalid_project_path': 'Invalid project path, cannot refresh configurations',
'config_parse_failed': 'Failed to parse project configurations',
'no_project_file': 'No Project File Found',
'configs_found': 'Found {count} configurations: {names}',
'current_selection': 'Current selection: {name}',
'config_selected': 'Configuration selected: {name}',
'output_directory': 'Output directory: {dir}',
'debug_mode': 'Debug mode: {mode}',
'config_selection_failed': 'Configuration selection failed',
'checking_git_status': 'Checking Git status...',
'not_git_repo_status': 'Current directory is not a Git repository',
'has_uncommitted_changes': 'Uncommitted changes detected',
'git_workdir_clean': 'Git working directory is clean, ready to build',
'git_check_complete': 'Git status check complete',
'checking_firmware_version': 'Checking firmware version...',
'version_check_complete': 'Version check complete',
'start_build_process': 'Starting build process...',
'input_update_info': 'Input update information...',
'committing_changes': 'Committing changes...',
'updating_version': 'Updating version...',
'updating_release_notes': 'Updating Release Notes...',
'committing_version_changes': 'Committing version changes and Release Notes...',
'compiling_project': 'Compiling project...',
'modifying_binary': 'Modifying binary file...',
'processing_files': 'Processing output files...',
'publishing_firmware': 'Publishing firmware...',
'publishing_remote': 'Publishing to remote directory...',
'build_process_complete': 'Build process complete',
'language_options': {
'zh_CN': 'zh_CN 简体中文',
'zh_TW': 'zh_TW 繁體中文',
'en_US': 'en_US English'
}
}
}
}
class MCUAutoBuildApp:
"""MCU自动编译工具主应用程序"""
def __init__(self):
"""初始化应用程序"""
self.root = tk.Tk()
self.config = {}
self.log_queue = queue.Queue()
# 初始化语言设置
self.current_language = 'zh_CN' # 默认简体中文
self.texts = LANGUAGES[self.current_language]['texts']
# 初始化组件
self.git_manager = None
self.builder = None
self.binary_modifier = None
self.file_manager = None
self.version_manager = None
self.info_manager = None
self.path_manager = None
self.tool_version_manager = ToolVersionManager()
# 缓存信息文件路径,避免重复查找
self.cached_info_file_path = None
# 配置相关变量
self.available_configurations = []
self.selected_configuration = None
# 操作成功标志位
self.git_status_checked = False
self.version_checked = False
# 设置窗口
self.setup_window()
# 加载配置(包括语言设置)
self.load_config()
# 创建界面(语言设置已生效)
self.create_widgets()
# 加载用户配置到界面
self._load_user_config_to_ui()
# 初始化flash起始地址显示
self._update_flash_start_addr_display()
# 初始化日志
self.setup_logging()
# 启动日志处理
self.process_log_queue()
def set_language(self, language_code: str):
"""设置语言"""
if language_code in LANGUAGES:
self.current_language = language_code
self.texts = LANGUAGES[language_code]['texts']
# 只有在logger初始化后才记录日志
if hasattr(self, 'logger'):
logger.info(f"语言已切换为: {LANGUAGES[language_code]['name']}")
else:
logger.info(f"语言已切换为: {LANGUAGES[language_code]['name']}")
return True
return False
def get_text(self, key: str) -> str:
"""获取本地化文本"""
return self.texts.get(key, key)
def setup_window(self):
"""设置主窗口"""
# 获取工具版本
self.root.title(f"{self.get_text('app_title')} v{VERSION}")
self.root.geometry("1000x700")
self.root.minsize(800, 600)
# 设置窗口图标
try:
icon_path = os.path.join(self._get_script_dir(), "icon_efm.ico")
if os.path.exists(icon_path):
self.root.iconbitmap(icon_path)
logger.info(f"设置窗口图标: {icon_path}")
else:
logger.warning(f"图标文件不存在: {icon_path}")
except Exception as e:
logger.warning(f"设置窗口图标失败: {e}")
# 设置关闭事件
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
def _get_script_dir(self):
"""获取脚本所在目录,兼容exe和Python脚本环境"""
if getattr(sys, 'frozen', False):
# 如果是打包的exe,使用exe所在目录
return os.path.dirname(os.path.abspath(sys.executable))
else:
# 如果是Python脚本,使用脚本所在目录
return os.path.dirname(os.path.abspath(__file__))
def load_config(self):
"""加载配置文件"""
# 获取脚本所在目录,确保exe环境下能正确找到配置文件
script_dir = self._get_script_dir()
# 使用绝对路径加载配置文件
default_config_path = os.path.join(script_dir, "config.json")
user_config_path = os.path.join(script_dir, "user_config.json")
try:
# 优先加载用户配置
if os.path.exists(user_config_path):
with open(user_config_path, 'r', encoding='utf-8') as f:
self.config = json.load(f)
self.log_message(f"用户配置文件加载成功,包含键: {list(self.config.keys())}")
if 'compile_tool' in self.config:
self.log_message(f"用户配置中的compile_tool: {self.config['compile_tool']}")
else:
self.log_message("警告:用户配置中缺少compile_tool字段")
else:
# 如果user_config.json不存在,加载默认配置
if os.path.exists(default_config_path):
with open(default_config_path, 'r', encoding='utf-8') as f:
self.config = json.load(f)
self.log_message("用户配置文件不存在,加载默认配置文件")
else:
self.log_message("用户配置文件和默认配置文件都不存在,使用内置默认配置")
self.config = self.get_default_config()
# 如果默认配置也没有,尝试使用示例配置
if not self.config or not self.config.get('compile_tool'):
example_config_path = os.path.join(script_dir, "user_config.example.json")
if os.path.exists(example_config_path):
with open(example_config_path, 'r', encoding='utf-8') as f:
self.config = json.load(f)
self.log_message("使用示例配置文件")
else:
self.log_message("所有配置文件都不存在,将创建新的用户配置")
self._create_user_config()
# 优先加载语言设置(在界面创建之前)
if 'language' in self.config:
language = self.config['language']
if language in LANGUAGES:
self.set_language(language)
self.log_message(f"语言设置已加载: {LANGUAGES[language]['name']}")
else:
self.log_message(f"不支持的语言设置: {language},使用默认语言")
else:
self.log_message("未找到语言设置,使用默认语言")
# 初始化路径管理器和配置分析器 - 不设置默认项目路径,完全由GUI输入决定
self.log_message("项目路径将由GUI输入决定,不在配置文件中预设")
# 根据编译工具创建相应的路径管理器和信息管理器
compile_tool = self.config.get('compile_tool')
if not compile_tool:
self.log_message("错误:配置文件中缺少compile_tool字段,请检查配置文件")
self.log_message(f"当前配置键: {list(self.config.keys())}")
return
self.log_message(f"使用编译工具: {compile_tool}")
# 不传入项目路径,完全由GUI输入决定
self.path_manager = PathManagerFactory.create_path_manager(compile_tool, None)
self.info_manager = InfoManagerFactory.create_manager(compile_tool, self.config)
# 注意:auto_find_paths需要在设置项目路径后调用
# 自动查找配置文件(需要在设置项目路径后进行)
if not self.config.get('binary_settings', {}).get('config_file'):
info_file_name = self.config.get('info_file', '')
if info_file_name:
self.log_message("配置文件查找将在设置项目路径后进行")
else:
self.log_message("未设置配置文件名称,跳过自动查找")
except Exception as e:
logger.error(f"加载配置文件失败: {e}")
import traceback
logger.error(f"详细错误信息: {traceback.format_exc()}")
self.config = self.get_default_config()
def _create_user_config(self):
"""创建用户配置文件"""
try:
user_config = {
"iar_installation_path": "",
"fw_publish_directory": "./fw_publish",
"remote_publish_directory": "",
"enable_remote_publish": False,
"info_file": "",
"language": "zh_CN",
"enable_git_commit_id": True,
"enable_file_size": True,
"enable_bin_checksum": True,
"enable_hash_value": True,
"git_commit_id_keyword": "__git_commit_id",
"file_size_keyword": "__file_size",
"bin_checksum_keyword": "__bin_checksum",
"hash_value_keyword": "__hash_value",
"firmware_version_keyword": "__Firmware_Version",
"add_timestamp_to_filename": False,
"publish_out_file": False
}
# 获取脚本所在目录
script_dir = self._get_script_dir()
user_config_path = os.path.join(script_dir, "user_config.json")
with open(user_config_path, 'w', encoding='utf-8') as f:
json.dump(user_config, f, indent=4, ensure_ascii=False)
self.log_message("用户配置文件创建成功")
except Exception as e:
self.log_message(f"创建用户配置文件失败: {e}")
def _load_user_config_to_ui(self):
"""将用户配置加载到界面"""
try:
# 项目路径完全由GUI输入决定,不从配置文件加载
# 加载编译工具路径并显示
compile_tool = self.config.get('compile_tool', 'IAR')
if compile_tool == 'IAR':
tool_path = self.config.get('iar_installation_path', '')
tool_name = "IAR"
else: # MDK
tool_path = self.config.get('mdk_installation_path', '')
tool_name = "MDK"
if tool_path:
self.iar_path_display_var.set(tool_path)
self.log_message(f"已加载{tool_name}路径: {tool_path}")
else:
self.iar_path_display_var.set("未配置")
self.log_message(f"{tool_name}路径未配置")
# 加载信息文件信息
info_file = self.config.get('info_file', '')
if info_file:
self.log_message(f"已加载信息文件: {info_file}")
# 加载功能设置信息
enable_git_commit_id = self.config.get('enable_git_commit_id', True)
enable_file_size = self.config.get('enable_file_size', True)
enable_bin_checksum = self.config.get('enable_bin_checksum', True)
self.log_message(f"功能设置 - Git提交ID: {enable_git_commit_id}, 文件大小: {enable_file_size}, 校验和: {enable_bin_checksum}")
except Exception as e:
self.log_message(f"加载用户配置到界面失败: {e}")
def get_default_config(self):
"""获取默认配置"""
return {
"compile_tool": "IAR",
"binary_settings": {
"firmware_version_offset": 0,
"git_commit_id_offset": 0,
"file_size_offset": 0,
"bin_checksum_offset": 0,
"commit_id_size": 7,
"crc_size": 4,
"reserved_area_size": 512
},
"git_settings": {
"check_uncommitted_changes": True,
"auto_commit": False,
"commit_message_template": "Auto build: {timestamp}"
},
"build_settings": {
"build_configuration": "Debug",
"clean_before_build": False,
"timeout_seconds": 300
},
"ui_settings": {
"window_title": "嵌入式固件管理工具",
"window_size": "1000x700",
"theme": "default"
},
"version_settings": {
"version_pattern": r"V(\d)\.(\d)\.(\d)\.(\d)",
"max_version_parts": [9, 9, 9, 9],
"auto_increment": True,
"keep_firmware_count": 10
}
}
def setup_logging(self):
"""设置日志系统"""
# 使用统一的logger,无需额外设置
logger.info("应用程序启动")
def create_widgets(self):
"""创建界面组件"""
# 创建主框架
main_frame = ttk.Frame(self.root, padding="10")
main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
# 配置网格权重
self.root.columnconfigure(0, weight=1)
self.root.rowconfigure(0, weight=1)
main_frame.columnconfigure(1, weight=1)
main_frame.rowconfigure(7, weight=1)
# 标题
title_label = ttk.Label(main_frame, text=self.get_text('app_title'),
font=("Arial", 16, "bold"))
title_label.grid(row=0, column=0, columnspan=3, pady=(0, 20))
# 项目信息框架
info_frame = ttk.LabelFrame(main_frame, text=self.get_text('project_info'), padding="10")
info_frame.grid(row=1, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=(0, 10))
info_frame.columnconfigure(1, weight=1)
# 项目路径
ttk.Label(info_frame, text=self.get_text('project_path')).grid(row=0, column=0, sticky=tk.W, padx=(0, 10))
# 项目路径完全由GUI输入决定,初始为空
initial_project_path = ""
self.project_path_var = tk.StringVar(value=initial_project_path)
ttk.Entry(info_frame, textvariable=self.project_path_var, state="readonly").grid(
row=0, column=1, sticky=(tk.W, tk.E), padx=(0, 10))
ttk.Button(info_frame, text=self.get_text('browse'), command=self.browse_project_path).grid(row=0, column=2)
# 编译配置选择
ttk.Label(info_frame, text=self.get_text('build_configuration')).grid(row=1, column=0, sticky=tk.W, padx=(0, 10))
self.configuration_var = tk.StringVar(value=self.get_text('not_selected'))
self.configuration_combo = ttk.Combobox(info_frame, textvariable=self.configuration_var,
state="readonly", width=20)
self.configuration_combo.grid(row=1, column=1, sticky=(tk.W, tk.E), padx=(0, 10))
self.configuration_combo.bind('<<ComboboxSelected>>', self.on_configuration_selected)
ttk.Button(info_frame, text=self.get_text('refresh_config'), command=self.refresh_configurations).grid(row=1, column=2)
# IAR路径
ttk.Label(info_frame, text=self.get_text('iar_path_display')).grid(row=2, column=0, sticky=tk.W, padx=(0, 10))
self.iar_path_display_var = tk.StringVar(value=self.get_text('not_configured'))
iar_path_label = ttk.Label(info_frame, textvariable=self.iar_path_display_var, foreground="green")
iar_path_label.grid(row=2, column=1, sticky=(tk.W, tk.E))
# Flash起始地址
ttk.Label(info_frame, text=self.get_text('flash_start_addr')).grid(row=3, column=0, sticky=tk.W, padx=(0, 10))
self.flash_start_addr_var = tk.StringVar(value=self.get_text('not_checked'))
ttk.Label(info_frame, textvariable=self.flash_start_addr_var, foreground="purple").grid(
row=3, column=1, sticky=tk.W)
# Git状态
ttk.Label(info_frame, text=self.get_text('git_status')).grid(row=4, column=0, sticky=tk.W, padx=(0, 10))
self.git_status_var = tk.StringVar(value=self.get_text('not_checked'))
ttk.Label(info_frame, textvariable=self.git_status_var, foreground="orange").grid(
row=4, column=1, sticky=tk.W)
# 固件版本
ttk.Label(info_frame, text=self.get_text('firmware_version')).grid(row=5, column=0, sticky=tk.W, padx=(0, 10))
self.firmware_version_var = tk.StringVar(value=self.get_text('not_checked'))
ttk.Label(info_frame, textvariable=self.firmware_version_var, foreground="blue").grid(
row=5, column=1, sticky=tk.W)
# 操作按钮框架
button_frame = ttk.Frame(main_frame)
button_frame.grid(row=5, column=0, columnspan=3, pady=(0, 10))
# 按钮
ttk.Button(button_frame, text=self.get_text('check_git'), command=self.check_git_status).pack(side=tk.LEFT, padx=(0, 10))
ttk.Button(button_frame, text=self.get_text('check_version'), command=self.check_version).pack(side=tk.LEFT, padx=(0, 10))
ttk.Button(button_frame, text=self.get_text('start_build'), command=self.start_build).pack(side=tk.LEFT, padx=(0, 10))
ttk.Button(button_frame, text=self.get_text('open_firmware'), command=self.open_firmware_directory).pack(side=tk.LEFT, padx=(0, 10))
ttk.Button(button_frame, text=self.get_text('open_settings'), command=self.open_settings).pack(side=tk.LEFT)
# 进度条
self.progress_var = tk.DoubleVar()
self.progress_bar = ttk.Progressbar(main_frame, variable=self.progress_var,
mode='indeterminate')
self.progress_bar.grid(row=6, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=(0, 10))
# 日志输出框架
log_frame = ttk.LabelFrame(main_frame, text=self.get_text('log_output'), padding="5")
log_frame.grid(row=7, column=0, columnspan=3, sticky=(tk.W, tk.E, tk.N, tk.S), pady=(0, 10))
log_frame.columnconfigure(0, weight=1)
log_frame.rowconfigure(0, weight=1)
# 日志文本框
self.log_text = scrolledtext.ScrolledText(log_frame, height=15, state="disabled")
self.log_text.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
# 状态栏
self.status_var = tk.StringVar(value=self.get_text('status_ready'))
status_bar = ttk.Label(main_frame, textvariable=self.status_var, relief=tk.SUNKEN)
status_bar.grid(row=8, column=0, columnspan=3, sticky=(tk.W, tk.E))
def log_message(self, message):
"""添加日志消息"""
timestamp = datetime.now().strftime("%H:%M:%S")
log_entry = f"[{timestamp}] {message}\n"
# 添加到队列
self.log_queue.put(log_entry)
def process_log_queue(self):
"""处理日志队列"""
try:
while True:
message = self.log_queue.get_nowait()
self.log_text.config(state="normal")
self.log_text.insert(tk.END, message)
self.log_text.see(tk.END)
self.log_text.config(state="disabled")
except queue.Empty:
pass
# 每100ms检查一次
self.root.after(100, self.process_log_queue)
def update_status(self, message):
"""更新状态栏"""
self.status_var.set(message)
self.log_message(message)
def browse_project_path(self):
"""浏览项目路径"""
try:
# 获取当前项目路径作为初始目录
initial_dir = self.project_path_var.get() or os.path.dirname(os.path.abspath(__file__))
self.log_message(f"文件对话框初始目录: {initial_dir}")
directory = filedialog.askdirectory(
title="选择项目目录",
initialdir=initial_dir
)
if directory:
self.project_path_var.set(directory)
self.clear_info_file_cache() # 清除信息文件缓存
self.log_message(f"选择项目路径: {directory}")
# 设置PathManager的项目路径
self.path_manager.set_project_path(directory)
# 先刷新配置列表,确保有选中的配置
self.refresh_configurations()
self.config = self.path_manager.auto_find_paths(self.config, self.selected_configuration)
self.log_message("已重新搜索项目文件")
# 自动获取flash偏移地址
flash_offset = self.path_manager.get_flash_offset_from_configuration(self.selected_configuration)
if flash_offset:
# 更新配置中的bin起始地址
if 'binary_settings' not in self.config:
self.config['binary_settings'] = {}
self.config['binary_settings']['bin_start_address'] = flash_offset
self.log_message(f"自动获取flash偏移地址: 0x{flash_offset:X}")
else:
self.log_message("无法自动获取flash偏移地址,请手动设置")
else:
self.log_message("用户取消了目录选择")
except Exception as e:
self.log_message(f"选择目录时出错: {e}")
messagebox.showerror(self.get_text('msg_error'), f"{self.get_text('msg_select_directory_error')}: {e}")
def find_iar_executable(self, iar_dir: str) -> str:
"""
在IAR安装目录中查找IarBuild.exe
Args:
iar_dir: IAR安装目录
Returns:
str: IarBuild.exe的完整路径,未找到返回空字符串
"""
possible_paths = [
os.path.join(iar_dir, "bin", "IarBuild.exe"),
os.path.join(iar_dir, "IarBuild.exe"),
os.path.join(iar_dir, "arm", "bin", "IarBuild.exe"),
os.path.join(iar_dir, "EWARM", "bin", "IarBuild.exe")
]
for path in possible_paths:
if os.path.exists(path):
return path
return ""
def find_mdk_executable(self, mdk_dir: str) -> str:
"""
在MDK安装目录中查找UV4.exe
Args:
mdk_dir: MDK安装目录
Returns:
str: UV4.exe的完整路径,未找到返回空字符串
"""
possible_paths = [
os.path.join(mdk_dir, "UV4", "UV4.exe"),
os.path.join(mdk_dir, "UV4.exe"),
os.path.join(mdk_dir, "bin", "UV4.exe"),
os.path.join(mdk_dir, "ARM", "UV4", "UV4.exe"),
os.path.join(mdk_dir, "ARM", "bin", "UV4.exe")
]
for path in possible_paths:
if os.path.exists(path):
return path
return ""
def get_info_file_path_with_details(self, project_path: str) -> tuple[Optional[str], str]:
"""
获取信息文件路径,并返回详细的错误信息
Args:
project_path: 项目路径
Returns:
tuple: (文件路径, 错误信息)
"""
if self.cached_info_file_path and os.path.exists(self.cached_info_file_path):
return self.cached_info_file_path, ""
if not self.path_manager:
compile_tool = self.config.get('compile_tool', 'IAR')
self.path_manager = PathManagerFactory.create_path_manager(compile_tool, project_path)
info_file_name = self.config.get('info_file', 'main.c')
file_path, error_msg = self.path_manager.find_info_file_with_details(info_file_name)
if file_path:
self.cached_info_file_path = file_path
return file_path, error_msg
def clear_info_file_cache(self):
"""清除信息文件路径缓存"""
self.cached_info_file_path = None
def save_config(self):
"""保存用户配置到文件"""
try:
# 读取现有的用户配置文件
script_dir = self._get_script_dir()
user_config_path = os.path.join(script_dir, "user_config.json")
if os.path.exists(user_config_path):
with open(user_config_path, 'r', encoding='utf-8') as f: