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


ros_introspection
Author(s):
autogenerated on Wed Mar 3 2021 03:56:00