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