Browse Source

Merge branch 'release/0.6.0'

liuyuqi-dellpc 1 month ago
parent
commit
0f2863fd79
1 changed files with 9 additions and 3 deletions
  1. 9 3
      client.py

+ 9 - 3
client.py

@@ -46,9 +46,9 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
         
     def read_config(self):
         """ read config """
-        current_dir = get_app_path()
         dotenv.load_dotenv(self.env_file_path)
         fgit_host = os.getenv('FGH_HOST')
+        print("当前host: " + fgit_host)
         try:
             if fgit_host[-1] == '/':
                 self.fgit_host = fgit_host[:-1]
@@ -59,6 +59,10 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
     @staticmethod
     def ping(host: str) -> None|int:
         """ ping host """
+        if host.startswith('https://') or host.startswith('http://'):
+            host = host.split('://')[1]
+        host = host.split(':')[0]
+        host = host.split('/')[0]
         try:
             if platform.system().lower() == 'windows':
                 command = ['ping', '-n', '1', '-w', '1000', host]
@@ -82,6 +86,7 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
     @staticmethod
     def parse_args():
         """ parse args """
+        print("解析参数...")
         parser = argparse.ArgumentParser(description='fgit client')
         parser.add_argument('command', type=str, help='fgit command', 
                             choices=['git','wget','curl','clone', 'push', 'pull', 'commit', 'add', 'status', 'log', 'diff', 'branch', 'checkout', 'merge', 'rebase', 'reset', 'tag', 'fetch', 'remote', 'init', 'config', 'help'])
@@ -91,11 +96,12 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
 
     def update_host(self):
         """update host"""
+        print("正在更新host...")
         res = []
         try:
             res = self.sess.get('https://git.yoqi.me/lyq/fgh/raw/master/docs/fgh_host.json')
             fgh_hosts= res.json()["hosts"]
-            fgh_host= self._get_best_host()
+            fgh_host= self._get_best_host(fgh_hosts)
             dotenv.set_key(self.env_file_path, 'FGH_HOST', fgh_host)
         except Exception as e:
             print(e)
@@ -108,7 +114,7 @@ fgh curl -O https://ghproxy.org/https://raw.githubusercontent.com/microsoft/vsco
             res.append({'host': host, 'delay': self.ping(host) if self.ping(host) else 999999})
             print("正在ping "+ host + " 延迟为:" + str(res[-1]['delay']) + "ms")
         min_delay = 999999
-        min_host = ''
+        min_host = res[0]['host']
         for item in res:
             if item['delay'] and item['delay'] < min_delay:
                 min_delay = item['delay']