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
4 changes: 0 additions & 4 deletions cmds/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions cmds/cmd_package/cmd_package_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,26 @@ 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):
return package_url.endswith('.git')


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']
Expand All @@ -174,21 +179,21 @@ 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])
if os.path.isdir(submodule_path):
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)
Expand Down Expand Up @@ -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] == '\\':
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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.
Expand Down