resource_list.py
Go to the documentation of this file.
1 import os
2 import yaml
3 import rospkg
4 import datetime
5 import requests
6 from rosmsg import list_types
7 
8 DOT_ROS_FOLDER = os.path.expanduser('~/.ros')
9 PY_DEP_FILENAME = os.path.join(DOT_ROS_FOLDER, 'py_deps.yaml')
10 
11 PYTHON_DEPS = {}
12 
13 
15  global PYTHON_DEPS
16  if os.path.exists(PY_DEP_FILENAME):
17  PYTHON_DEPS = yaml.load(open(PY_DEP_FILENAME))
18  if 'last_download' in PYTHON_DEPS:
19  now = datetime.datetime.now()
20  if now - PYTHON_DEPS['last_download'] < datetime.timedelta(days=3):
21  return
22 
23  try:
24  ff = requests.get('https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml').text
25  except requests.exceptions.ConnectionError:
26  print('Cannot retrieve latest python dependencies')
27  return
28 
29  PYTHON_DEPS = yaml.load(ff)
30  PYTHON_DEPS['last_download'] = datetime.datetime.now()
31 
32  if not os.path.exists(DOT_ROS_FOLDER):
33  os.mkdir(DOT_ROS_FOLDER)
34  yaml.dump(PYTHON_DEPS, open(PY_DEP_FILENAME, 'w'))
35 
36 
38  for var in [key, 'python-' + key, 'python3-' + key, key.replace('python-', 'python3-'), key.replace('python-', ''),
39  key.replace('python-', '').replace('-', '_')]:
40  if var in PYTHON_DEPS:
41  return var
42 
43 
45 
46 
47 PACKAGES = set()
48 MESSAGES = set()
49 SERVICES = set()
50 
51 rospack = rospkg.RosPack()
52 for pkg in rospack.list():
53  PACKAGES.add(pkg)
54  for mode, ros_set in [('.msg', MESSAGES), ('.srv', SERVICES)]:
55  for gen_key in list_types(pkg, mode, rospack):
56  pkg, gen = gen_key.split('/')
57  ros_set.add((pkg, gen))
58 
59 
60 def is_package(pkg):
61  return pkg in PACKAGES
62 
63 
64 def is_message(pkg, msg):
65  return (pkg, msg) in MESSAGES
66 
67 
68 def is_service(pkg, srv):
69  return (pkg, srv) in SERVICES


ros_introspection
Author(s):
autogenerated on Wed Jun 19 2019 19:56:52