This file is indexed.

/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py is in python-rosdep 0.11.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen
import yaml
try:
    import urlparse
except ImportError:
    import urllib.parse as urlparse #py3k
import os

from rospkg.os_detect import OS_DEBIAN
from rospkg.os_detect import OS_FEDORA
from rospkg.os_detect import OS_OSX
from rospkg.os_detect import OS_UBUNTU

create_default_installer_context = None
from .core import InvalidData, DownloadFailure
from .platforms.debian import APT_INSTALLER
from .platforms.osx import BREW_INSTALLER
from .platforms.redhat import YUM_INSTALLER
from .rosdistrohelper import get_targets, get_release_file, PreRep137Warning

from .rep3 import download_targets_data  # deprecated, will output warning

import warnings

#py3k
try:
    unicode
except:
    basestring = unicode = str

# location of an example gbpdistro file for reference and testing
FUERTE_GBPDISTRO_URL = 'https://raw.github.com/ros/rosdistro/' \
                     + 'master/releases/fuerte.yaml'

#seconds to wait before aborting download of gbpdistro data
DOWNLOAD_TIMEOUT = 15.0


def get_owner_name(url):
    """
    Given a gbpdistro url, returns the name of the github user in the url.

    If the url is not a valid github url it returns the default `ros`.

    This information is used to set the homebrew tap name, see:
    https://github.com/ros-infrastructure/rosdep/pull/17

    :returns: The github account in the given gbpdistro url
    """
    result = 'ros'
    try:
        parsed = urlparse.urlparse(url)
        if parsed.netloc == 'github.com':
            result = parsed.path.split('/')[1]
    except (ValueError, IndexError):
        pass
    return result


# For compatability url defaults to ''
def gbprepo_to_rosdep_data(gbpdistro_data, targets_data, url=''):
    """
    DEPRECATED: the rosdistro file format has changed according to REP137
                this function will yield a deprecation warning

    :raises: :exc:`InvalidData`
    """

    warnings.warn("deprecated: see REP137 and rosdistro", PreRep137Warning)
    # Error reporting for this isn't nearly as good as it could be
    # (e.g. doesn't separate gbpdistro vs. targets, nor provide
    # origin), but rushing this implementation a bit.
    try:
        if not type(targets_data) == dict:
            raise InvalidData("targets data must be a dict")
        if not type(gbpdistro_data) == dict:
            raise InvalidData("gbpdistro data must be a dictionary")
        if gbpdistro_data['type'] != 'gbp':
            raise InvalidData('gbpdistro must be of type "gbp"')

        # compute the default target data for the release_name
        release_name = gbpdistro_data['release-name']
        if not release_name in targets_data:
            raise InvalidData("targets file does not contain information "
                            + "for release [%s]" % (release_name))
        else:
            # take the first match
            target_data = targets_data[release_name]

        # compute the rosdep data for each repo
        rosdep_data = {}
        gbp_repos = gbpdistro_data['repositories']
        # Ensure gbp_repos is a dict
        if type(gbp_repos) != dict:
            raise InvalidData("invalid repo spec in gbpdistro data: " + str(gbp_repos)
                            + ". Invalid repositories entry, must be dict.")
        for rosdep_key, repo in gbp_repos.items():
            if type(repo) != dict:
                raise InvalidData("invalid repo spec in gbpdistro data: "
                                + str(repo))

            for pkg in repo.get('packages', {rosdep_key: None}):
                rosdep_data[pkg] = {}

                # for pkg in repo['packages']: indent the rest of the lines here.
                # Do generation for ubuntu
                rosdep_data[pkg][OS_UBUNTU] = {}
                # Do generation for empty OS X entries
                homebrew_name = '%s/%s/%s' % (get_owner_name(url),
                                              release_name, rosdep_key)
                rosdep_data[pkg][OS_OSX] = {
                    BREW_INSTALLER: {'packages': [homebrew_name]}
                }

                # - debian package name: underscores must be dashes
                deb_package_name = 'ros-%s-%s' % (release_name, pkg)
                deb_package_name = deb_package_name.replace('_', '-')

                repo_targets = repo['target'] if 'target' in repo else 'all'
                if repo_targets == 'all':
                    repo_targets = target_data

                for t in repo_targets:
                    if not isinstance(t, basestring):
                        raise InvalidData("invalid target spec: %s" % (t))
                    # rosdep_data[pkg][OS_UBUNTU][t] = {
                    rosdep_data[pkg][OS_UBUNTU][t] = {
                        APT_INSTALLER: {'packages': [deb_package_name]}
                    }

                rosdep_data[pkg]['_is_ros'] = True
        return rosdep_data
    except KeyError as e:
        raise InvalidData("Invalid GBP-distro/targets format: missing key: "
                        + str(e))


# REP137 compliant
def get_gbprepo_as_rosdep_data(gbpdistro):
    """
    :raises: :exc:`InvalidData`
    """
    distro_file = get_release_file(gbpdistro)
    ctx = create_default_installer_context()
    release_name = gbpdistro

    rosdep_data = {}
    default_installers = {}
    gbp_repos = distro_file.repositories
    for rosdep_key, repo in gbp_repos.items():
        for pkg in repo.package_names:
            rosdep_data[pkg] = {}

            # following rosdep pull #17, use env var instead of github organization name
            tap = os.environ.get('ROSDEP_HOMEBREW_TAP', 'ros')
            # Do generation for empty OS X entries
            homebrew_name = '%s/%s/%s' % (tap, release_name, rosdep_key)
            rosdep_data[pkg][OS_OSX] = {
                BREW_INSTALLER: {'packages': [homebrew_name]}
            }

            # - package name: underscores must be dashes
            package_name = 'ros-%s-%s' % (release_name, pkg)
            package_name = package_name.replace('_', '-')

            for os_name in distro_file.platforms:
                if not os_name in rosdep_data[pkg]:
                    rosdep_data[pkg][os_name] = {}
                if not os_name in default_installers:
                    default_installers[os_name] = ctx.get_default_os_installer_key(os_name)
                for os_code_name in distro_file.platforms[os_name]:
                    rosdep_data[pkg][os_name][os_code_name] = {
                        default_installers[os_name]: {'packages': [package_name]}
                    }

            rosdep_data[pkg]['_is_ros'] = True
    return rosdep_data


def download_gbpdistro_as_rosdep_data(gbpdistro_url, targets_url=None):
    """
    Download gbpdistro file from web and convert format to rosdep distro data.

    DEPRECATED: see REP137. This function will output
                (at least) one deprecation warning

    :param gbpdistro_url: url of gbpdistro file, ``str``
    :param target_url: override URL of platform targets file
    :raises: :exc:`DownloadFailure`
    :raises: :exc:`InvalidData` If targets file does not pass cursory
     validation checks.
    """
    # we can convert a gbpdistro file into rosdep data by following a
    # couple rules
    # will output a warning
    targets_data = download_targets_data(targets_url=targets_url)
    try:
        f = urlopen(gbpdistro_url, timeout=DOWNLOAD_TIMEOUT)
        text = f.read()
        f.close()
        gbpdistro_data = yaml.safe_load(text)
        # will output a warning
        return gbprepo_to_rosdep_data(gbpdistro_data,
                                      targets_data,
                                      gbpdistro_url)
    except Exception as e:
        raise DownloadFailure("Failed to download target platform data "
                            + "for gbpdistro:\n\t" + str(e))