From 9053490239c17246788011edb2aef537c3aad541 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 15 Sep 2022 21:20:21 -0400 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=E5=8F=AA=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=80=E6=AC=A1IP=E5=BD=92=E5=B1=9E=E5=9C=B0=20=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E9=87=87=E7=94=A8=E7=B1=BB=E7=9A=84=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E6=95=88=E6=9E=9C=E4=B8=8D=E5=A5=BD?= =?UTF-8?q?=EF=BC=8C=E9=87=87=E7=94=A8global=E5=8F=98=E9=87=8F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=A0=87=E5=BF=97=E4=BD=8D=E8=A6=81=E6=AF=94=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=87=BD=E6=95=B0=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmds/cmd_package/cmd_package_update.py | 46 +++++++++++--------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/cmds/cmd_package/cmd_package_update.py b/cmds/cmd_package/cmd_package_update.py index 30466c9c..01d63c6f 100644 --- a/cmds/cmd_package/cmd_package_update.py +++ b/cmds/cmd_package/cmd_package_update.py @@ -133,36 +133,30 @@ def is_user_mange_package(bsp_package_path, pkg): break return False +is_China_ip = None -class GeographyLocation(): - _is_china = False - - def __init__(self): - try: - ip = requests.get('https://ifconfig.me/ip').content.decode() - url = 'http://www.ip-api.com/json/' + ip - if requests.get(url).json()['country'] == 'China': - self._is_china = True - else: - self._is_china = False - except: - if (-time.timezone)/3600 == 8: - self._is_china = True - else: - self._is_china = False - - if(self._is_china): - print("[Use Gitee server]") +def need_using_mirror_download(): + global is_China_ip + if is_China_ip != None: + return is_China_ip + try: + ip = requests.get('https://ifconfig.me/ip').content.decode() + url = 'http://www.ip-api.com/json/' + ip + if requests.get(url).json()['country'] == 'China': + is_China_ip = True else: - print("[Use Github server]") - - def isChina (self): - return self._is_china + is_China_ip = False + except: + if (-time.timezone)/3600 == 8: + is_China_ip = True + else: + is_China_ip = False -iplocation = GeographyLocation() + if(is_China_ip): + print("[Use Gitee server]") + else: + print("[Use Github server]") -def need_using_mirror_download(): - return iplocation.isChina() def is_git_url(package_url): return package_url.endswith('.git')