diff --git a/cmds/Kconfig b/cmds/Kconfig index ac43c61d..a3dd8f54 100644 --- a/cmds/Kconfig +++ b/cmds/Kconfig @@ -27,10 +27,6 @@ if SYS_CREATE_MDK_IAR_PROJECT endif -config SYS_PKGS_DOWNLOAD_ACCELERATE - bool "Use China Mainland server" - default n - config SYS_PKGS_USING_STATISTICS bool "Send usage data for improve product" default y diff --git a/cmds/cmd_package/cmd_package_update.py b/cmds/cmd_package/cmd_package_update.py index 9bd80389..ec0be6a2 100644 --- a/cmds/cmd_package/cmd_package_update.py +++ b/cmds/cmd_package/cmd_package_update.py @@ -134,13 +134,18 @@ def is_user_mange_package(bsp_package_path, pkg): return False -def need_using_mirror_download(config_file): - """default using mirror url to download packages""" - - if not os.path.isfile(config_file): - return True - elif os.path.isfile(config_file) and find_macro_in_config(config_file, 'SYS_PKGS_DOWNLOAD_ACCELERATE'): - return True +def need_using_mirror_download(): + try: + ip = requests.get('http://ip.42.pl/raw').content.decode() + url = 'http://www.ip-api.com/json/' + ip + if requests.get(url).json()['country'] == 'China': + print("Use gitee mirror sever") + return True + else: + return False + except: + print('Fail to get the ip location!') + return False def is_git_url(package_url): @@ -148,7 +153,7 @@ def is_git_url(package_url): def install_git_package(bsp_package_path, package_name, package_info, package_url, ver_sha, upstream_changed, - url_origin, env_config_file): + url_origin): try: repo_path = os.path.join(bsp_package_path, package_name) repo_path = repo_path + '-' + package_info['ver'] @@ -174,13 +179,13 @@ def install_git_package(bsp_package_path, package_name, package_info, package_ur submodule_path = os.path.join(repo_path, '.gitmodules') if os.path.isfile(submodule_path): print("Start to update submodule") - if need_using_mirror_download(env_config_file): + if need_using_mirror_download(): replace_list = modify_submod_file_to_mirror(submodule_path) # Modify .gitmodules file cmd = 'git submodule update --init --recursive' execute_command(cmd, cwd=repo_path) - if need_using_mirror_download(env_config_file): + if need_using_mirror_download(): if len(replace_list): for item in replace_list: submodule_path = os.path.join(repo_path, item[2]) @@ -188,7 +193,7 @@ def install_git_package(bsp_package_path, package_name, package_info, package_ur cmd = 'git remote set-url origin ' + item[0] execute_command(cmd, cwd=submodule_path) - if need_using_mirror_download(env_config_file): + if need_using_mirror_download(): if os.path.isfile(submodule_path): cmd = 'git checkout .gitmodules' execute_command(cmd, cwd=repo_path) @@ -241,9 +246,6 @@ def install_package(env_root, pkgs_root, bsp_root, package_info, force_update): else: logging.info("NOT User managed package {0}, {1} need install. \n".format(bsp_package_path, package_info)) - # get the .config file from env - env_config_file = os.path.join(env_root, r'tools\scripts\cmds', '.config') - package = PackageOperation() pkg_path = package_info['path'] if pkg_path[0] == '/' or pkg_path[0] == '\\': @@ -267,7 +269,7 @@ def install_package(env_root, pkgs_root, bsp_root, package_info, force_update): # noinspection PyBroadException try: - if need_using_mirror_download(env_config_file): + if need_using_mirror_download(): get_package_url, get_ver_sha = get_url_from_mirror_server(pkgs_name_in_json, package_info['ver']) # Check whether the package package url is valid @@ -284,7 +286,7 @@ def install_package(env_root, pkgs_root, bsp_root, package_info, force_update): if is_git_url(package_url): if not install_git_package(bsp_package_path, pkgs_name_in_json, package_info, package_url, ver_sha, upstream_changed, - url_from_json, env_config_file): + url_from_json): result = False else: if not install_not_git_package(package, package_info, local_pkgs_path, package_url, bsp_package_path, @@ -360,8 +362,6 @@ def update_latest_packages(sys_value): env_root = Import('env_root') pkgs_root = Import('pkgs_root') - env_config_file = os.path.join(env_root, r'tools\scripts\cmds', '.config') - with open(package_filename, 'r') as f: read_back_pkgs_json = json.load(f) @@ -384,7 +384,7 @@ def update_latest_packages(sys_value): # noinspection PyBroadException try: # If mirror acceleration is enabled, get the update address from the mirror server. - if need_using_mirror_download(env_config_file): + if need_using_mirror_download(): payload_pkgs_name_in_json = pkgs_name_in_json.encode("utf-8") # Change repo's upstream address.