Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmds/cmd_menuconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import platform
import re
from vars import Import
from .cmd_package.cmd_package_utils import find_macro_in_config
from .cmd_package.cmd_package_utils import find_bool_macro_in_config


def is_pkg_special_config(config_str):
Expand Down Expand Up @@ -222,18 +222,18 @@ def cmd(args):
if not os.path.isfile(fn):
return

if find_macro_in_config(fn, 'SYS_AUTO_UPDATE_PKGS'):
if find_bool_macro_in_config(fn, 'SYS_AUTO_UPDATE_PKGS'):
os.system('pkgs --update')
print("==============================>The packages have been updated completely.")

if find_macro_in_config(fn, 'SYS_CREATE_MDK_IAR_PROJECT'):
if find_macro_in_config(fn, 'SYS_CREATE_MDK4'):
if find_bool_macro_in_config(fn, 'SYS_CREATE_MDK_IAR_PROJECT'):
if find_bool_macro_in_config(fn, 'SYS_CREATE_MDK4'):
os.system('scons --target=mdk4 -s')
print("Create mdk4 project done")
elif find_macro_in_config(fn, 'SYS_CREATE_MDK5'):
elif find_bool_macro_in_config(fn, 'SYS_CREATE_MDK5'):
os.system('scons --target=mdk5 -s')
print("Create mdk5 project done")
elif find_macro_in_config(fn, 'SYS_CREATE_IAR'):
elif find_bool_macro_in_config(fn, 'SYS_CREATE_IAR'):
os.system('scons --target=iar -s')
print("Create iar project done")

Expand Down
11 changes: 10 additions & 1 deletion cmds/cmd_package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@
# 2020-04-08 SummerGift Optimize program structure
#

import os
from .cmd_package_printenv import package_print_env, package_print_help
from .cmd_package_list import list_packages
from .cmd_package_wizard import package_wizard
from .cmd_package_update import package_update
from .cmd_package_upgrade import package_upgrade, package_upgrade_modules
from .cmd_package_utils import find_IAR_EXEC_PATH, find_MDK_EXEC_PATH

iar_exec_path = find_IAR_EXEC_PATH()
if iar_exec_path:
os.environ['RTT_EXEC_PATH'] = iar_exec_path

mdk_exec_path = find_MDK_EXEC_PATH()
if mdk_exec_path:
os.environ['RTT_EXEC_PATH'] = mdk_exec_path

def run_env_cmd(args):
"""Run packages command."""
Expand Down Expand Up @@ -117,4 +127,3 @@ def add_parser(sub):
dest='package_print_env')

parser.set_defaults(func=run_env_cmd)

2 changes: 1 addition & 1 deletion cmds/cmd_package/cmd_package_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from package import PackageOperation, Bridge_SConscript
from vars import Import, Export
from .cmd_package_utils import get_url_from_mirror_server, execute_command, git_pull_repo, user_input, \
find_macro_in_config
find_bool_macro_in_config


def determine_support_chinese(env_root):
Expand Down
5 changes: 2 additions & 3 deletions cmds/cmd_package/cmd_package_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import os
import uuid
from vars import Import
from .cmd_package_utils import git_pull_repo, get_url_from_mirror_server, find_macro_in_config
from .cmd_package_utils import git_pull_repo, get_url_from_mirror_server, find_bool_macro_in_config
from .cmd_package_update import need_using_mirror_download

try:
Expand Down Expand Up @@ -130,12 +130,11 @@ def get_mac_address():

def Information_statistics():
env_root = Import('env_root')

# get the .config file from env
env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
env_config_file = os.path.join(env_kconfig_path, '.config')

if find_macro_in_config(env_config_file, 'SYS_PKGS_USING_STATISTICS'):
if find_bool_macro_in_config(env_config_file, 'SYS_PKGS_USING_STATISTICS'):
mac_addr = get_mac_address()
response = requests.get('https://www.rt-thread.org/studio/statistics/api/envuse?userid='+str(mac_addr)+'&username='+str(mac_addr)+'&envversion=1.0&studioversion=2.0&ip=127.0.0.1')
if response.status_code != 200:
Expand Down
62 changes: 56 additions & 6 deletions cmds/cmd_package/cmd_package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import requests
import logging


def execute_command(cmd_string, cwd=None, shell=True):
"""Execute the system command at the specified address."""

Expand Down Expand Up @@ -139,13 +138,17 @@ def user_input(msg=None):
return value


def find_macro_in_config(filename, macro_name):
# Find the string after '='
# e.g CONFIG_SYS_AUTO_UPDATE_PKGS=y
# this function will return True and 'y'
# True means this macro has been set and y is the string after '='
def find_string_in_config(filename, macro_name):
try:
config = open(filename, "r")
except Exception as e:
print('Error message:%s' % e)
print('open .config failed')
return False
return (False, None)

empty_line = 1

Expand Down Expand Up @@ -179,12 +182,59 @@ def find_macro_in_config(filename, macro_name):
if setting[0].startswith('CONFIG_'):
setting[0] = setting[0][7:]

if setting[0] == macro_name and setting[1] == 'y':
if setting[0] == macro_name:
config.close()
return True
return (True, setting[1])

config.close()
return False
return (False, None)


# check if the bool macro is set or not
# e.g CONFIG_SYS_AUTO_UPDATE_PKGS=y
# will return True because this macro has been set
# If this macro cannot find or the .config cannot find or the macro is not set (n),
# the function will return False
def find_bool_macro_in_config(filename, macro_name):
rst, str = find_string_in_config(filename, macro_name)
if rst == True and str == 'y':
return True
else:
return False


# find a string macro is defined or not
# e.g. CONFIG_SYS_CREATE_IAR_EXEC_PATH="C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3"
# will return "C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.3"
# If this macro cannot find or .config cannot find
# the function will return None
def find_string_macro_in_config(filename, macro_name):
rst, str = find_string_in_config(filename, macro_name)
if rst == True:
str = str.strip('"')
return str
else:
return None


# return IAR execution path string or None for failure
def find_IAR_EXEC_PATH():
env_root = os.getenv("ENV_ROOT")
# get the .config file from env
env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
env_config_file = os.path.join(env_kconfig_path, '.config')

return find_string_macro_in_config(env_config_file, 'SYS_CREATE_IAR_EXEC_PATH')


# return Keil-MDK execution path string or None for failure
def find_MDK_EXEC_PATH():
env_root = os.getenv("ENV_ROOT")
# get the .config file from env
env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
env_config_file = os.path.join(env_kconfig_path, '.config')

return find_string_macro_in_config(env_config_file, 'SYS_CREATE_MDK_EXEC_PATH')


def remove_folder(folder_path):
Expand Down
2 changes: 1 addition & 1 deletion statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def Information_statistics():
return
except Exception as e:
exit(0)
elif os.path.isfile(env_config_file) and cmd_package.find_macro_in_config(env_config_file, 'SYS_PKGS_NOT_USING_STATISTICS'):
elif os.path.isfile(env_config_file) and cmd_package.find_bool_macro_in_config(env_config_file, 'SYS_PKGS_NOT_USING_STATISTICS'):
return True


Expand Down