1# Copyright (c) 2011, Willow Garage, Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7#     * Redistributions of source code must retain the above copyright
8#       notice, this list of conditions and the following disclaimer.
9#     * Redistributions in binary form must reproduce the above copyright
10#       notice, this list of conditions and the following disclaimer in the
11#       documentation and/or other materials provided with the distribution.
12#     * Neither the name of the Willow Garage, Inc. nor the names of its
13#       contributors may be used to endorse or promote products derived from
14#       this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26# POSSIBILITY OF SUCH DAMAGE.
27
28# Author Ken Conley/kwc@willowgarage.com
29
30"""
31Base API for loading rosdep information by package or stack name.
32This API is decoupled from the ROS packaging system to enable multiple
33implementations of rosdep, including ones that don't rely on the ROS
34packaging system.  This is necessary, for example, to implement a
35version of rosdep that works against tarballs of released stacks.
36"""
37
38import yaml
39
40from .core import InvalidData
41
42ROSDEP_YAML = 'rosdep.yaml'
43
44
45class RosdepLoader:
46    """
47    Base API for loading rosdep information by package or stack name.
48    """
49
50    def load_rosdep_yaml(self, yaml_contents, origin):
51        """
52        Utility routine for unmarshalling rosdep data encoded as YAML.
53
54        :param origin: origin of yaml contents (for error messages)
55        :raises: :exc:`yaml.YAMLError`
56        """
57        try:
58            return yaml.safe_load(yaml_contents)
59        except yaml.YAMLError as e:
60            raise InvalidData('Invalid YAML in [%s]: %s' % (origin, e), origin=origin)
61
62    def load_view(self, view_name, rosdep_db, verbose=False):
63        """
64        Load view data into rosdep_db. If the view has already been
65        loaded into rosdep_db, this method does nothing.
66
67        :param view_name: name of ROS stack to load, ``str``
68        :param rosdep_db: database to load stack data into, :class:`RosdepDatabase`
69
70        :raises: :exc:`InvalidData`
71        :raises: :exc:`rospkg.ResourceNotFound` if view cannot be located
72        """
73        raise NotImplementedError(view_name, rosdep_db, verbose)  # pychecker
74
75    def get_loadable_resources(self):
76        raise NotImplementedError()
77
78    def get_loadable_views(self):
79        raise NotImplementedError()
80
81    def get_rosdeps(self, resource_name, implicit=True):
82        """
83        :raises: :exc:`rospkg.ResourceNotFound` if *resource_name* cannot be found.
84        """
85        raise NotImplementedError(resource_name, implicit)  # pychecker
86
87    def get_view_key(self, resource_name):
88        """
89        Map *resource_name* to a view key.  In rospkg, this maps a ROS
90        package name to a ROS stack name.  If *resource_name* is a ROS
91        stack name, it returns the ROS stack name.
92
93        :returns: Name of view that *resource_name* is in, ``None`` if no associated view.
94        :raises: :exc:`rospkg.ResourceNotFound` if *resource_name* cannot be found.
95        """
96        raise NotImplementedError(resource_name)
97