Go to the documentation of this file.00001 import os
00002 import yaml
00003 import rospkg
00004 import datetime
00005 import requests
00006 from rosmsg import list_types
00007
00008 DOT_ROS_FOLDER = os.path.expanduser('~/.ros')
00009 PY_DEP_FILENAME = os.path.join(DOT_ROS_FOLDER, 'py_deps.yaml')
00010
00011 PYTHON_DEPS = {}
00012
00013
00014 def maybe_download_python_deps():
00015 global PYTHON_DEPS
00016 if os.path.exists(PY_DEP_FILENAME):
00017 PYTHON_DEPS = yaml.load(open(PY_DEP_FILENAME))
00018 if 'last_download' in PYTHON_DEPS:
00019 now = datetime.datetime.now()
00020 if now - PYTHON_DEPS['last_download'] < datetime.timedelta(days=3):
00021 return
00022
00023 try:
00024 ff = requests.get('https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml').text
00025 except requests.exceptions.ConnectionError:
00026 print('Cannot retrieve latest python dependencies')
00027 return
00028
00029 PYTHON_DEPS = yaml.load(ff)
00030 PYTHON_DEPS['last_download'] = datetime.datetime.now()
00031
00032 if not os.path.exists(DOT_ROS_FOLDER):
00033 os.mkdir(DOT_ROS_FOLDER)
00034 yaml.dump(PYTHON_DEPS, open(PY_DEP_FILENAME, 'w'))
00035
00036
00037 def get_python_dependency(key):
00038 for var in [key, 'python-' + key, 'python3-' + key, key.replace('python-', 'python3-'), key.replace('python-', ''),
00039 key.replace('python-', '').replace('-', '_')]:
00040 if var in PYTHON_DEPS:
00041 return var
00042
00043
00044 maybe_download_python_deps()
00045
00046
00047 PACKAGES = set()
00048 MESSAGES = set()
00049 SERVICES = set()
00050
00051 rospack = rospkg.RosPack()
00052 for pkg in rospack.list():
00053 PACKAGES.add(pkg)
00054 for mode, ros_set in [('.msg', MESSAGES), ('.srv', SERVICES)]:
00055 for gen_key in list_types(pkg, mode, rospack):
00056 pkg, gen = gen_key.split('/')
00057 ros_set.add((pkg, gen))
00058
00059
00060 def is_package(pkg):
00061 return pkg in PACKAGES
00062
00063
00064 def is_message(pkg, msg):
00065 return (pkg, msg) in MESSAGES
00066
00067
00068 def is_service(pkg, srv):
00069 return (pkg, srv) in SERVICES