Skip to content

Commit b487c88

Browse files
authored
Merge pull request #77 from SummerGGift/master
【完善】:新旧版本兼容问题
2 parents b6b2e57 + 63fe4e8 commit b487c88

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
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: 26 additions & 19 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,14 @@ def pre_package_update():
500509
""" Make preparations before updating the software package. """
501510

502511
bsp_root = Import('bsp_root')
512+
env_root = Import('env_root')
513+
from cmd_package import determine_support_chinese
503514

504515
if not os.path.exists('.config'):
505-
print ("\n当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。")
506-
print ("如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\n")
516+
if determine_support_chinese(env_root):
517+
print ("\n当前路径下没有发现 .config 文件,请确保当前目录为 BSP 根目录。")
518+
print ("如果确定当前目录为 BSP 根目录,请先使用 <menuconfig> 命令来生成 .config 文件。\n")
519+
507520
print ('No system configuration file : .config.')
508521
print ('You should use < menuconfig > command to config bsp first.')
509522
return False
@@ -533,7 +546,6 @@ def pre_package_update():
533546
sql = '''CREATE TABLE packagefile
534547
(pathname TEXT ,package TEXT ,md5 TEXT );'''
535548
pkgsdb.create_table(conn, sql)
536-
# print("Create dbsqlite done")
537549

538550
fn = '.config'
539551
pkgs = kconfig.parse(fn)
@@ -696,33 +708,28 @@ 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
"""
714719

720+
sys_value = pre_package_update()
721+
722+
if not sys_value:
723+
return
724+
715725
bsp_root = Import('bsp_root')
716726
env_root = Import('env_root')
717727
flag = True
718728

719729
# According to the env version, whether Chinese output is supported or not
720-
determine_support_chinese(env_root)
721-
722-
sys_value = pre_package_update()
723-
724-
if not sys_value:
725-
return
730+
if determine_support_chinese(env_root):
731+
if platform.system() == "Windows":
732+
os.system('chcp 65001 > nul')
726733

727734
oldpkgs = sys_value[0]
728735
newpkgs = sys_value[1]

0 commit comments

Comments
 (0)