Skip to content

Commit

Permalink
[feat]:增加自动输入选项支持,实现真正一键
Browse files Browse the repository at this point in the history
  • Loading branch information
fishros committed May 27, 2022
1 parent d081538 commit 9e4fae1
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
wget http://fishros.com/install -O fishros && . fishros
```

## 如何自动选择

目前一键安装支持从配置文件自动输入选项,你需要手动运行一次一键安装,使用完毕后会自动产生 `/tmp/fishros.yaml`

使用下面的指令将配置文件拷贝到当前终端即可。

```
cp /tmp//tmp/fishros.yaml ./
```


## 贡献指南

Expand Down
2 changes: 2 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def main():
from tools.base import CmdTask,FileUtils,PrintUtils,ChooseTask
from tools.base import encoding_utf8,osversion,osarch
from tools.base import run_tool_file,download_tools
from tools.base import config_helper

# check base config
if not encoding_utf8:
Expand Down Expand Up @@ -77,6 +78,7 @@ def main():
download_tools(code,tools)
run_tool_file(tools[code]['tool'].replace(url_prefix,'').replace("/","."))

config_helper.gen_config_file()
PrintUtils.print_delay("欢迎加入机器人学习交流QQ群:139707339(入群口令:一键安装)",0.1)
PrintUtils.print_success("如在使用过程中遇到问题,请打开:https://fishros.org.cn/forum 进行反馈",0.001)

Expand Down
84 changes: 81 additions & 3 deletions tools/base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from calendar import c
import os
import re
import sys
import time
import subprocess
import locale
from queue import Queue
import yaml


encoding = locale.getpreferredencoding()
encoding_utf8 = encoding.find("UTF")>-1


class ConfigHelper():
def __init__(self,record_file=None):
self.record_input_queue = Queue()

self.record_file = record_file
if self.record_file==None: self.record_file = "./fish_install.yaml"
self.default_input_queue = self.get_default_queue(self.record_file)

def record_input(self,item):
self.record_input_queue.put(item)

def gen_config_file(self):
"""生产配置文件
"""
config_yaml = {}

chooses = []

while self.record_input_queue.qsize()>0:
chooses.append(self.record_input_queue.get())

config_yaml['chooses'] = chooses
config_yaml['time'] = str(time.time())

with open("/tmp/fish_install.yaml", "w", encoding="utf-8") as f:
yaml.dump(config_yaml, f,allow_unicode=True)

def get_input_value(self):
if self.default_input_queue.qsize()>0:
return self.default_input_queue.get()

def record_choose(self,data):
self.record_input_queue.put(data)

def get_default_queue(self,param_file_path):
"""获取默认的配置
Args:
param_file_path (string, optional): 参数文件路径. Defaults to None.
Returns:
Queue: 数据队列
"""
config_data = None
choose_queue = Queue()

if not os.path.exists(param_file_path):
return choose_queue

with open(param_file_path,"r",encoding="utf-8") as f:
config_data = f.read()

if config_data == None: return choose_queue
config_yaml = yaml.load(config_data,Loader=yaml.FullLoader)
for choose in config_yaml['chooses']:
choose_queue.put(choose)

return choose_queue

config_helper = ConfigHelper()
# config_helper.record_choose({"choose":1,"desc":"一键安装ROS"})
# config_helper.record_choose({"choose":2,"desc":"还愿"})
# print(config_helper.get_input_value())
# config_helper.gen_config_file()

def GetOsVersion():
"""
Library for detecting the current OS, including detecting specific
Expand Down Expand Up @@ -883,12 +952,23 @@ def __choose(data,tips,array):
choose = -1
for key in dic:
PrintUtils.print_delay('[{}]:{}'.format(key,dic[key]),0.005)

choose = None
choose_item = config_helper.get_input_value()

while True:
choose = input("请输入[]内的数字以选择:")
if choose_item:
choose = str(choose_item['choose'])
print("为您从配置文件找到默认选项:",choose_item)
else:
choose = input("请输入[]内的数字以选择:")
choose_item = None
# Input From Queue
if choose.isdecimal() :
if (int(choose) in dic.keys() ) or (int(choose)==0):
choose = int(choose)
break
config_helper.record_choose({"choose":choose,"desc":dic[choose]})
PrintUtils.print_fish()
return choose,dic[choose]

Expand Down Expand Up @@ -1105,6 +1185,4 @@ def download_tools(id,tools):





osarch = AptUtils.getArch()
10 changes: 9 additions & 1 deletion tools/tool_install_ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,18 @@ def choose_and_install_ros(self):
for a in dic_base.keys():
ros_name[RosVersions.get_version_string(a)] = a

_,rosname = ChooseTask(ros_name.keys(),"请选择你要安装的ROS版本名称(请注意ROS1和ROS2区别):",True).run()
code,rosname = ChooseTask(ros_name.keys(),"请选择你要安装的ROS版本名称(请注意ROS1和ROS2区别):",True).run()
if code==0:
print("你选择退出。。。。")
return

version_dic = {1:rosname+"桌面版",2:rosname+"基础版(小)"}
code,name = ChooseTask(version_dic,"请选择安装的具体版本(如果不知道怎么选,请选1桌面版):",False).run()

if code==0:
print("你选择退出。。。。")
return

install_tool = 'aptitude'
if osversion.get_version() == "16.04":
install_tool = 'apt'
Expand Down

0 comments on commit 9e4fae1

Please sign in to comment.