From dc73c882d8018c685456f99f514fcf51e4340e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E9=A6=99ROS?= <87068644+fishros@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:25:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E5=A4=9A=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E6=94=AF=E6=8C=81&=E4=BC=98=E5=8C=96=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ install | 12 ++++-------- install.py | 30 +++++++----------------------- tools/base.py | 14 ++++++++------ tools/translation/translator.py | 17 +++++++++++++---- 5 files changed, 34 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 35e52e2..0151281 100644 --- a/README.md +++ b/README.md @@ -138,3 +138,5 @@ class Tool(BaseTool): - 一键安装nodejs [小鱼](https://github.com/fishros) - 一键安装vscode [小鱼](https://github.com/fishros) - 一键安装:Docker(支持amd64和arm64) [@alyssa](https://github.com/alyssa1024) + + diff --git a/install b/install index b557285..d59683b 100644 --- a/install +++ b/install @@ -1,17 +1,13 @@ mkdir -p /tmp/fishinstall/tools/translation/assets -wget http://mirror.fishros.com/install/install.py -O /tmp/fishinstall/install.py 2>>/dev/null +export FISHROS_URL="http://mirror.fishros.com/install" +wget `echo $FISHROS_URL`/install.py -O /tmp/fishinstall/install.py 2>>/dev/null source /etc/profile -# 强制解锁,太多用户遇到这个问题了,没办法,后续想个办法解决下 -# 强解可能会有依赖问题 -# sudo rm /var/cache/apt/archives/lock -# sudo rm /var/lib/dpkg/lock -# sudo rm /var/lib/dpkg/lock-frontend if [ $UID -eq 0 ];then apt-get install sudo fi sudo apt install python3-distro python3-yaml -y -sudo python3 /tmp/fishinstall/install.py +sudo -E python3 /tmp/fishinstall/install.py sudo rm -rf /tmp/fishinstall/ sudo rm fishros . ~/.bashrc -. ~/.zshrc 2>/dev/null +. ~/.zshrc 2>/dev/null \ No newline at end of file diff --git a/install.py b/install.py index 6697f1d..1724f89 100644 --- a/install.py +++ b/install.py @@ -2,14 +2,9 @@ import os import importlib -url_prefix = 'http://mirror.fishros.com/install/' - +url_prefix = os.environ.get('FISHROS_URL')+'/' base_url = url_prefix+'tools/base.py' - -_suported_languages = ['zh_CN', 'en_US'] -lang_url = url_prefix+'tools/translation/assets/{}.py' -_translator_files = ['translator'] -translator_url = url_prefix+'tools/translation/{}.py' +translator_url = url_prefix+'tools/translation/translator.py' INSTALL_ROS = 0 # 安装ROS相关 INSTALL_SOFTWARE = 1 # 安装软件 @@ -65,22 +60,17 @@ def main(): from tools.base import CmdTask,FileUtils,PrintUtils,ChooseTask,ChooseWithCategoriesTask from tools.base import encoding_utf8,osversion,osarch from tools.base import run_tool_file,download_tools - from tools.base import config_helper + from tools.base import config_helper,tr # download translations - for files in _translator_files: - os.system("wget {} -O /tmp/fishinstall/{} --no-check-certificate".format(translator_url.format(files),translator_url.format(files).replace(url_prefix,''))) - - for lang in _suported_languages: - os.system("wget {} -O /tmp/fishinstall/{} --no-check-certificate".format(lang_url.format(lang),lang_url.format(lang).replace(url_prefix,''))) + CmdTask("wget {} -O /tmp/fishinstall/{} --no-check-certificate".format(translator_url,translator_url.replace(url_prefix,''))).run() + importlib.import_module("tools.translation.translator").Linguist() + from tools.base import tr - # Import translations - tr = importlib.import_module("tools.translation.translator").Linguist() - - # PrintUtils.print_delay(f"检测到你的系统版本信息为{osversion.get_codename()},{osarch}",0.001) # 使用量统计 CmdTask("wget https://fishros.org.cn/forum/topic/1733 -O /tmp/t1733 -q && rm -rf /tmp/t1733").run() + PrintUtils.print_success(tr.tr("已为您切换语言至当前所在国家语言:")+tr._currentLocale) # check base config if not encoding_utf8: print("Your system encoding not support ,will install some packgaes..") @@ -122,12 +112,6 @@ def main(): code,result = ChooseWithCategoriesTask(tool_categories, tips=tr.tr("---众多工具,等君来用---"),categories=tools_type_map).run() if code==0: PrintUtils().print_success(tr.tr("是觉得没有合胃口的菜吗?那快联系的小鱼增加菜单吧~")) - elif code==77: - code,result = ChooseTask(choose_dic, tr.tr("请选择你要测试的程序:")).run() - if code<0 and code>=77: return False - # CmdTask("cp tools/* /tmp/fishinstall/tools/").run - print(tools[code]['tool'].replace(url_prefix,'').replace("/",".")) - run_tool_file(tools[code]['tool'].replace(url_prefix,'').replace("/",".")) else: download_tools(code,tools) run_tool_file(tools[code]['tool'].replace(url_prefix,'').replace("/",".")) diff --git a/tools/base.py b/tools/base.py index efce25f..9a6ae90 100644 --- a/tools/base.py +++ b/tools/base.py @@ -25,8 +25,8 @@ encoding = locale.getpreferredencoding() encoding_utf8 = encoding.find("UTF")>-1 -# Import translations -tr = importlib.import_module("tools.translation.translator").Linguist() + +tr = None class ConfigHelper(): def __init__(self,record_file=None): @@ -975,12 +975,14 @@ def run_command(self,executable='/bin/sh'): self.command_thread = threading.Thread(target=self.command_thread) self.command_thread.start() time.sleep(0.5) # 等待线程启动 - while self.is_command_finish()!=0: + while self.is_command_finish()==-1: self.bar.update_time() time.sleep(0.1) + return (self.ret_code,self.ret_out,self.ret_err) def is_command_finish(self): + # poll 是返回码 if self.sub.poll() == None: return -1 return self.sub.poll() @@ -1411,17 +1413,17 @@ def run_tool_file(file,autorun=True): return tool def run_tool_url(url,url_prefix): - os.system("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])) + CmdTask("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])).run() run_tool_file(url.replace(url_prefix,'').replace("/",".")) def download_tools(id,tools): # download tool url = tools[id]['tool'] - os.system("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])) + CmdTask("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])).run() # download dep for dep in tools[id]['dep']: url = tools[dep]['tool'] - os.system("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])) + CmdTask("wget {} -O /tmp/fishinstall/tools/{} --no-check-certificate".format(url,url[url.rfind('/')+1:])).run() diff --git a/tools/translation/translator.py b/tools/translation/translator.py index 285846c..d92159b 100644 --- a/tools/translation/translator.py +++ b/tools/translation/translator.py @@ -6,6 +6,13 @@ import locale import json import os +import tools.base +from tools.base import CmdTask + +_suported_languages = ['zh_CN', 'en_US'] +url_prefix = os.environ.get('FISHROS_URL') +lang_url = url_prefix+'tools/translation/assets/{}.py' + COUNTRY_CODE_MAPPING = { "CN": "zh_CN", @@ -21,9 +28,12 @@ def __init__(self): self._currentLocale = self.getLocalFromIP() if self._currentLocale is None: self._currentLocale = locale.getdefaultlocale()[0] - # Load the translation file. + for lang in _suported_languages: + CmdTask("wget {} -O /tmp/fishinstall/{} --no-check-certificate".format(lang_url.format(lang),lang_url.format(lang).replace(url_prefix,''))).run() + self.loadTranslationFlile() + tools.base.tr = self def loadTranslationFlile(self): # Load the translation file. @@ -47,11 +57,10 @@ def tr(self, string) -> str: def getLocalFromIP(self) -> str: local_str = "" try: - os.system("""wget --header="Accept: application/json" --no-check-certificate "https://ip.renfei.net/" -O /tmp/fishros_check_country.json""") - + os.system("""wget --header="Accept: application/json" --no-check-certificate "https://ip.renfei.net/" -O /tmp/fishros_check_country.json -qq""") with open('/tmp/fishros_check_country.json', 'r') as json_file: data = json.loads(json_file.read()) - + self.ip_info = data if data['location']['countryCode'] in COUNTRY_CODE_MAPPING: local_str = COUNTRY_CODE_MAPPING[data['location']['countryCode']] else: