1 Star 0 Fork 22

Dozingfiretruck/HeliosSDK

forked from QuecPython/HeliosSDK 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 6.49 KB
一键复制 编辑 原始数据 按行查看 历史
chenchi 提交于 2021-06-03 17:04 +08:00 . first commit
# -*- coding: utf-8 -*-
# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os, sys, json
if os.name == 'nt':
host_spec = ' HOST=win32'
else:
host_spec = ' HOST=linux'
argv = sys.argv
argc = len(argv)
error_occurred = False
build_log_dir = 'output/log'
build_log_file = 'build.log'
platform_json = 'system/platform/platform.json'
# error process
def error_proc(msg, prompt='CommandError', errtype='EARGV'):
global error_occurred
if not error_occurred:
print("! %s: [%s]: `%s'" % (prompt, errtype, msg))
error_occurred = True
# help cmd process
def help_proc():
print('Usage: helios <action> [<app>] [<at>] [<fw_name>]\n')
print('These are common commands used in various situations:')
print(' menuconfig - Do the project configuration')
print(' make <app> [[<at>] [<fw_name>]] - Do the compilation work')
print(' private_clean - Clean the app private target')
print(' clean - Clean the output directory')
print(' help - Show this help page')
# menuconfig cmd process
def menuconfig_proc():
cmd_str = 'make menuconfig PY=' + argv[1] + host_spec
os.system(cmd_str)
# clean cmd process
def clean_proc():
cmd_str = 'make clean PY=' + argv[1]
os.system(cmd_str)
# clean cmd process
def private_clean_proc():
cmd_str = 'make private_clean PY=' + argv[1]
os.system(cmd_str)
# get plat by board
def get_plat_by_board(board):
if not os.path.exists(platform_json):
error_proc(platform_json, 'NotFoundError', 'ECONF')
return ''
with open(platform_json, 'r', encoding='utf-8') as f:
platforms = json.load(f)
for k,v in platforms.items():
if board in v:
return k
return ''
# make cmd process
def make_proc():
global argv
global argc
got_plat = False
got_noos = False
got_verbose = False
got_seq_params = False
got_fw_name = False
app_entry = argv[3].replace('\\', '/')
app_entry_chr_list = list(app_entry)
for i in list(reversed(range(0, len(app_entry_chr_list)))):
if app_entry_chr_list[i-len(app_entry_chr_list)] == '/':
app_entry_chr_list[i-len(app_entry_chr_list)] = ''
else:
break
app_entry = ''.join(app_entry_chr_list)
if not len(app_entry) or not os.path.exists(os.path.abspath(app_entry)):
error_proc(argv[3], 'NotFoundError', 'EARGV')
return
cmd_str = argv[2] + ' APP_ENTRY=' + app_entry
if argc != 4:
for arg in argv[4:]:
if arg.find('@') >= 0: # sequential parameters process
if got_seq_params:
error_proc(arg)
return
else:
seq_params = arg.split('@')
for i in seq_params:
if i == '':
pass
elif get_plat_by_board(i):
if got_plat:
error_proc(i)
return
else:
cmd_str = cmd_str + ' PLAT=' + get_plat_by_board(i) + ' BOARD=' + i
got_plat = True
elif i == 'NOOS':
if got_noos:
error_proc(i)
return
else:
cmd_str = cmd_str + ' NOOS=y'
got_noos = True
elif i == 'verbose':
if got_verbose:
error_proc(i)
return
else:
cmd_str = cmd_str + ' V=1'
got_verbose = True
else:
error_proc(i)
return
got_seq_params = True
else:
if got_fw_name:
error_proc(arg)
return
else:
cmd_str = cmd_str + ' FW_NAME=' + arg
got_fw_name = True
cmd_str = cmd_str + host_spec
cmd_str = cmd_str + ' PY=' + argv[1]
cmd_str = cmd_str + ' 2>&1 | tee ' + build_log_dir + '/' + build_log_file
if not os.path.exists(build_log_dir):
os.makedirs(build_log_dir)
os.system(cmd_str)
# flash cmd process
def flash_proc():
global argv
global argc
if argc != 4:
error_proc('arguments count error')
return
else:
app_entry = argv[3].replace('\\', '/')
app_entry_chr_list = list(app_entry)
for i in list(reversed(range(0, len(app_entry_chr_list)))):
if app_entry_chr_list[i-len(app_entry_chr_list)] == '/':
app_entry_chr_list[i-len(app_entry_chr_list)] = ''
else:
break
app_entry = ''.join(app_entry_chr_list)
if not len(app_entry) or not os.path.exists(os.path.abspath(app_entry)):
error_proc(argv[3], 'NotFoundError', 'EARGV')
return
cmd_str = 'make flash APP_ENTRY=' + app_entry + ' PY=' + argv[1]
os.system(cmd_str)
# main entry:
if __name__ == '__main__':
if argc > 6:
error_proc(argv[6:], 'EARGC')
exit()
if argc == 2:
help_proc()
elif argc == 3:
if argv[2] == 'help':
help_proc()
elif argv[2] == 'menuconfig':
menuconfig_proc()
elif argv[2] == 'clean':
clean_proc()
elif argv[2] == 'private_clean':
private_clean_proc()
else:
error_proc(argv[2])
else:
if argv[2] == 'make':
make_proc()
elif argv[2] == 'flash':
flash_proc()
else:
error_proc(argv[2])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Dozingfiretruck/HeliosSDK.git
git@gitee.com:Dozingfiretruck/HeliosSDK.git
Dozingfiretruck
HeliosSDK
HeliosSDK
master

搜索帮助