This repository has been archived by the owner on Jan 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
rosdep.py
63 lines (51 loc) · 2.03 KB
/
rosdep.py
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
import os
from common import apt_get_install, call, check_output
class RosDepResolver:
def __init__(self, ros_distro, sudo=False, no_chroot=False):
self.r2a = {}
self.a2r = {}
self.env = os.environ
self.env['ROS_DISTRO'] = ros_distro
if no_chroot:
print("Skip initializing and updating rosdep database")
else:
print("Ininitalize rosdep database")
apt_get_install(['lsb-release', 'python-rosdep'], sudo=sudo)
try:
call("rosdep init", self.env)
except:
print("Rosdep is already initialized")
call("rosdep update", self.env)
print("Building dictionaries from a rosdep's db")
raw_db = check_output("rosdep db", self.env, verbose=False).split('\n')
for entry in raw_db:
split_entry = entry.split(' -> ')
if len(split_entry) < 2:
continue
ros_entry = split_entry[0]
if split_entry[1]:
apt_entries = split_entry[1].split(' ')
else:
apt_entries = []
self.r2a[ros_entry] = apt_entries
for a in apt_entries:
self.a2r[a] = ros_entry
def to_aptlist(self, ros_entries):
res = []
for r in ros_entries:
for a in self.to_apt(r):
if not a in res:
res.append(a)
return res
def to_ros(self, apt_entry):
if apt_entry not in self.a2r:
print("Could not find %s in rosdep keys. Rosdep knows about these keys: %s" % (apt_entry, ', '.join(sorted(self.a2r.keys()))))
return self.a2r[apt_entry]
def to_apt(self, ros_entry):
if ros_entry not in self.r2a:
print("Could not find %s in keys. Have keys %s" % (ros_entry, ', '.join(sorted(self.r2a.keys()))))
return self.r2a[ros_entry]
def has_ros(self, ros_entry):
return ros_entry in self.r2a
def has_apt(self, apt_entry):
return apt_entry in self.a2r