-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
executable file
·121 lines (102 loc) · 3.9 KB
/
install.py
File metadata and controls
executable file
·121 lines (102 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
import os
import sys
import re
import subprocess
global input_function
if sys.version[0] == "2":
input_function = raw_input
else:
input_function = input
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def exit_error(err_msg):
sys.exit(bcolors.FAIL + err_msg + bcolors.ENDC)
def print_success(msg):
print(bcolors.OKGREEN + msg + bcolors.ENDC)
def print_warning(msg):
print(bcolors.WARNING+ msg + bcolors.ENDC)
def get_ros_package_path():
try:
ros_package_path = os.environ['ROS_PACKAGE_PATH']
paths = ros_package_path.split(':')
except KeyError:
exit_error('Set ROS_PACKAGE_PATH correctly')
package_paths = []
for path in paths:
m = re.match(r'^/opt/ros', path)
if m:
break
package_paths.append(path)
return package_paths
def workspace_path():
path = get_ros_package_path()
workspace_path = ""
if len(path) == 1:
workspace_path_confirmation = input_function("Do you really install at " + bcolors.WARNING + "\"" + path[0] + "\""+ bcolors.ENDC + " [Y/n] ") or "Y"
if workspace_path_confirmation == "Y":
workspace_path = path[0]
elif workspace_path_confirmation == "n":
workspace_path = input_function("[Input install path] ")
else:
exit_error("Invalid input, aborted.")
else:
print("Multiple package paths are specified.")
for p in path:
print("\"" + p + "\"")
workspace_path = input_function("[Input install path] ")
if len(workspace_path) == 0:
exit_error("You have to specify 1 install path, aborted.")
return workspace_path
def _clone_into(clone_path):
clone_args = ["clone", "https://github.com/rowma/rowma_ros.git", clone_path]
return subprocess.check_call(["git"] + list(clone_args))
def clone(workspace_path):
rowma_ros_path = os.path.join(workspace_path, "rowma_ros")
if os.path.exists(rowma_ros_path):
clone_confirmation = input_function("rowma_ros already exists, do you override it? [y/N] ") or "N"
if clone_confirmation == "y":
temporary_rowma_path = "/tmp/rowma_ros"
if os.path.exists(temporary_rowma_path):
subprocess.check_call(["rm", "-rf", temporary_rowma_path])
_clone_into(temporary_rowma_path)
subprocess.check_call(["rm", "-rf", workspace_path + "/rowma_ros"])
subprocess.check_call(["mv", "-f", "/tmp/rowma_ros", workspace_path])
else:
print_warning("Skipped git clone rowma_ros.")
else:
_clone_into(rowma_ros_path)
def pip_install(workspace_path):
requirements_txt_pat = os.path.join(workspace_path, "rowma_ros/requirements.txt")
pip_args = ["install", "--user", "-r", requirements_txt_pat]
return subprocess.check_call(["pip"] + list(pip_args))
def install_apt_deps():
try:
distro = os.environ['ROS_DISTRO']
except KeyError:
exit_error('Set ROS_DISTRO correctly.')
return subprocess.check_call(["sudo", "apt-get", "install", "-y", "ros-" + distro + "-rosbridge-server"])
def catkin_make(workspace_path):
working_dir = os.path.join(workspace_path, "..")
return subprocess.check_call(["catkin_make"], shell=True, cwd=working_dir)
def install():
try:
path = workspace_path()
clone(path)
print_success("rowma_ros was successfully downloaded at " + path)
pip_install(path)
print_success("Pip dependencies were installed successfully.")
install_apt_deps()
print_success("Apt packages were installed successfully.")
catkin_make(path)
print_success("rowma_ros was successfully installed!")
except KeyboardInterrupt:
exit_error("\nUser interruptation occurred.")
install()