Skip to content

Commit 836b22f

Browse files
committed
【修改】:解决旧版本输出中文提示出现乱码的问题
1 parent b6b2e57 commit 836b22f

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

cmds/cmd_menuconfig.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def find_macro_in_config(filename, macro_name):
152152

153153

154154
def cmd(args):
155+
156+
from cmd_package import determine_support_chinese
155157
env_root = Import('env_root')
156158
currentdir = os.getcwd()
157159
dirname = os.path.split(os.path.split(currentdir)[0])[0]
@@ -162,8 +164,9 @@ def cmd(args):
162164

163165
if not os.getenv("RTT_ROOT"):
164166
if get_rtt_name != 'rt-thread':
165-
print("\n<menuconfig> 命令应当在某一特定 BSP 目录下执行,例如:\"rt-thread/bsp/stm32/stm32f091-st-nucleo\"")
166-
print("请确保当前目录为 BSP 根目录,并且该目录中有 Kconfig 文件。\n")
167+
if determine_support_chinese(env_root):
168+
print("\n<menuconfig> 命令应当在某一特定 BSP 目录下执行,例如:\"rt-thread/bsp/stm32/stm32f091-st-nucleo\"")
169+
print("请确保当前目录为 BSP 根目录,并且该目录中有 Kconfig 文件。\n")
167170

168171
print ("<menuconfig> command should be used in a bsp root path with a Kconfig file.")
169172
print ("Example: \"rt-thread/bsp/stm32/stm32f091-st-nucleo\"")
@@ -173,9 +176,10 @@ def cmd(args):
173176
print ('string')
174177
print ('option env="RTT_ROOT"')
175178
print ('default "../.."\n')
176-
print ('例如修改 default 这一项为 rt-thread 所在路径: default "F:/git_repositories/rt-thread"')
177179

178-
print ('\n下面的警告信息提示与找不到正确的 Kconfig 文件有关:')
180+
if determine_support_chinese(env_root):
181+
print ('例如修改 default 这一项为 rt-thread 所在路径: default "F:/git_repositories/rt-thread"')
182+
print ('\n下面的警告信息提示与找不到正确的 Kconfig 文件有关:')
179183

180184
# if not args.menuconfig_easy:
181185
# return
@@ -221,8 +225,9 @@ def cmd(args):
221225

222226
os.chdir(beforepath)
223227

224-
from cmd_package import determine_support_chinese
225-
determine_support_chinese(env_root)
228+
if determine_support_chinese(env_root):
229+
if platform.system() == "Windows":
230+
os.system('chcp 65001 > nul')
226231
return
227232

228233
else:
@@ -242,8 +247,9 @@ def cmd(args):
242247
if mtime != mtime2:
243248
mk_rtconfig(fn)
244249

245-
from cmd_package import determine_support_chinese
246-
determine_support_chinese(env_root)
250+
if determine_support_chinese(env_root):
251+
if platform.system() == "Windows":
252+
os.system('chcp 65001 > nul')
247253

248254
if platform.system() == "Windows":
249255
env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')

cmds/cmd_package.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def execute_command(cmdstring, cwd=None, shell=True):
7272

7373
return stdout_str
7474

75+
def determine_support_chinese(env_root):
76+
get_flag_file_path = os.path.join(env_root, 'tools', 'bin', 'env_above_ver_1_1')
77+
if os.path.isfile(get_flag_file_path):
78+
return True
79+
else:
80+
return False
7581

7682
def user_input(msg, default_value):
7783
"""Gets the user's keyboard input."""
@@ -350,8 +356,11 @@ def package_list():
350356
env_root = Import('env_root')
351357

352358
if not os.path.isfile(fn):
353-
print ("\n当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。")
354-
print ("如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\n")
359+
360+
if determine_support_chinese(env_root):
361+
print ("\n当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。")
362+
print ("如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\n")
363+
355364
print ('No system configuration file : .config.')
356365
print ('You should use < menuconfig > command to config bsp first.')
357366
return
@@ -500,10 +509,13 @@ def pre_package_update():
500509
""" Make preparations before updating the software package. """
501510

502511
bsp_root = Import('bsp_root')
512+
from cmd_package import determine_support_chinese
503513

504514
if not os.path.exists('.config'):
505-
print ("\n当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。")
506-
print ("如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\n")
515+
if determine_support_chinese(env_root):
516+
print ("\n当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。")
517+
print ("如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\n")
518+
507519
print ('No system configuration file : .config.')
508520
print ('You should use < menuconfig > command to config bsp first.')
509521
return False
@@ -696,18 +708,11 @@ def write_storage_file(pkgs_fn, newpkgs):
696708
pkgs_file.close()
697709

698710

699-
def determine_support_chinese(env_root):
700-
get_flag_file_path = os.path.join(env_root, 'tools', 'bin', 'env_above_ver_1_1')
701-
if os.path.isfile(get_flag_file_path):
702-
# change code page to 65001
703-
if platform.system() == "Windows":
704-
os.system('chcp 65001 > nul')
705-
706711
def package_update(isDeleteOld=False):
707712
"""Update env's packages.
708713
709714
Compare the old and new software package list and update the package.
710-
Remove unwanted packages and download the newly selected package.
715+
Remove unwanted packages and download the newly selected package.-
711716
Check if the files in the deleted packages have been changed, and if so,
712717
remind the user saved the modified file.
713718
"""
@@ -716,14 +721,16 @@ def package_update(isDeleteOld=False):
716721
env_root = Import('env_root')
717722
flag = True
718723

719-
# According to the env version, whether Chinese output is supported or not
720-
determine_support_chinese(env_root)
721-
722724
sys_value = pre_package_update()
723725

724726
if not sys_value:
725727
return
726728

729+
# According to the env version, whether Chinese output is supported or not
730+
if determine_support_chinese(env_root):
731+
if platform.system() == "Windows":
732+
os.system('chcp 65001 > nul')
733+
727734
oldpkgs = sys_value[0]
728735
newpkgs = sys_value[1]
729736
pkgs_delete_error_list = sys_value[2]

0 commit comments

Comments
 (0)