This file is indexed.

/usr/lib/python2.7/dist-packages/roswtf/context.py is in python-roswtf 1.11.16-3.

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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# Software License Agreement (BSD License)
#
# Copyright (c) 2009, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of Willow Garage, Inc. nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id$

"""
L{WtfContext} object, which is commonly used throughout the roswtf
APIs to pass state.
"""

import os
import sys

import rospkg
import rospkg.environment

import rosgraph

import roslaunch.depends
import roslaunch.substitution_args

from roswtf.model import WtfWarning

class WtfException(Exception):
    """
    Base exception class of roswtf-related issues.
    """
    pass

class WtfContext(object):
    """
    WtfContext stores common state about the ROS filesystem and online
    environment. The primary use of this is for convenience (not
    having to load this state manually) and performance (not having to
    do the same calculation repeatedly).
    """
    __slots__ = ['pkg', 'pkg_dir', 'pkgs',
                 'stack', 'stack_dir', 'stacks',
                 'manifest_file', 'manifest',
                 'env', 'ros_root', 'ros_package_path', 'pythonpath',
                 'ros_master_uri',
                 'roslaunch_uris',
                 'launch_files',
                 'launch_file_deps',
                 'launch_file_missing_deps',
                 'system_state',
                 'service_providers',
                 'topics', 'services',
                 'nodes', 'uri_node_map',
                 'expected_edges',
                 'actual_edges',
                 'unconnected_subscriptions',
                 'use_sim_time',
                 'warnings', 'errors',
                 'rospack', 'rosstack']
    
    def __init__(self):
        # main package we are running 
        self.pkg = None
        self.pkg_dir = None
        # main stack we are running 
        self.stack = None
        self.stack_dir = None
        
        # - list of all packages involved in this check
        self.pkgs = []
        # - list of all stacks involved in this check        
        self.stacks = []        

        # manifest location of package that we are running 
        self.manifest_file = None
        # manifest of package that we are running 
        self.manifest = None

        # environment variables 
        self.env = {}

        # provide these for convenience
        self.ros_root = None
        self.ros_package_path = None
        self.pythonpath = None
        
        # launch file that is being run
        self.launch_files = None
        self.launch_file_deps = None
        self.launch_file_missing_deps = None        
        
        # online state
        self.roslaunch_uris = None 
        self.system_state = None #master.getSystemState
        self.topics = None
        self.services = None
        self.service_providers = None #names of nodes with services
        self.nodes = None
        self.uri_node_map = {}
        self.expected_edges = None
        self.actual_edges = None
        self.unconnected_subscriptions = None
        self.use_sim_time = None
        
        # caching rospack instance
        self.rospack = self.rosstack = None
        
        # warnings that we have collected so far
        self.warnings = []
        # errors that we have collected so far
        self.errors = []

    def as_dictionary(self):
        """
        @return: dictionary representation of context, which is
        useful for producing error messages
        @rtype: dict
        """
        return dict((s, getattr(self, s)) for s in self.__slots__)

    @staticmethod
    def from_roslaunch(roslaunch_files, env=None):
        """
        @param roslaunch_file: roslaunch_file to load from
        @type  roslaunch_file: str
        """
        if env is None:
            env = os.environ

        # can't go any further if launch file doesn't validate
        l, c = roslaunch.XmlLoader(), roslaunch.ROSLaunchConfig()
        for f in roslaunch_files:
            try:
                l.load(f, c, verbose=False) 
            except roslaunch.RLException as e:
                raise WtfException("Unable to load roslaunch file [%s]: %s"%(f, str(e)))

        ctx = WtfContext()
        ctx.rospack = rospkg.RosPack(rospkg.get_ros_paths(env))
        ctx.rosstack = rospkg.RosStack(rospkg.get_ros_paths(env))

        ctx.launch_files = roslaunch_files
        _load_roslaunch(ctx, roslaunch_files)
        # ctx.pkg and ctx.stack initialized by _load_roslaunch
        _load_pkg(ctx, ctx.pkg)
        if ctx.stack:
            _load_stack(ctx, ctx.stack)        
        _load_env(ctx, env)
        return ctx

    @staticmethod
    def from_stack(stack, env=None):
        """
        Initialize WtfContext from stack.
        @param stack: stack name
        @type  stack: str
        @raise WtfException: if context state cannot be initialized
        """
        if env is None:
            env = os.environ

        ctx = WtfContext()
        ctx.rospack = rospkg.RosPack(rospkg.get_ros_paths(env))
        ctx.rosstack = rospkg.RosStack(rospkg.get_ros_paths(env))

        _load_stack(ctx, stack)
        try:
            ctx.pkgs = ctx.rosstack.packages_of(stack)
        except rospkg.ResourceNotFound:
            # this should be handled elsewhere
            ctx.pkgs = []
        _load_env(ctx, env)
        return ctx
    
    @staticmethod
    def from_package(pkg, env=None):
        """
        Initialize WtfContext from package name.

        @param pkg: package name
        @type  pkg: str
        @raise WtfException: if context state cannot be initialized
        """
        if env is None:
            env = os.environ

        ctx = WtfContext()
        ctx.rospack = rospkg.RosPack(rospkg.get_ros_paths(env))
        ctx.rosstack = rospkg.RosStack(rospkg.get_ros_paths(env))
        
        _load_pkg(ctx, pkg)
        stack = ctx.rospack.stack_of(pkg)
        if stack:
            _load_stack(ctx, stack)
        _load_env(ctx, env)
        return ctx

    @staticmethod
    def from_env(env=None):
        """
        Initialize WtfContext from environment.
        
        @raise WtfException: if context state cannot be initialized
        """
        if env is None:
            env = os.environ

        ctx = WtfContext()
        ctx.rospack = rospkg.RosPack(rospkg.get_ros_paths(env))
        ctx.rosstack = rospkg.RosStack(rospkg.get_ros_paths(env))

        _load_env(ctx, env)
        return ctx
    
def _load_roslaunch(ctx, roslaunch_files):
    """
    Utility for initializing WtfContext state from roslaunch file
    """
    try:
        base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps(roslaunch_files)
        ctx.pkg = base_pkg
        ctx.launch_file_deps = file_deps
        ctx.launch_file_missing_deps = missing
    except roslaunch.substitution_args.SubstitutionException as se:
        raise WtfException("Cannot load roslaunch file(s): "+str(se))
    except roslaunch.depends.RoslaunchDepsException as e:
        raise WtfException(str(e))

def _load_pkg(ctx, pkg):
    """
    Utility for initializing WtfContext state
    @raise WtfException: if context state cannot be initialized
    """
    r = ctx.rospack
    ctx.pkg = pkg
    try:
        ctx.pkgs = [pkg] + r.get_depends(pkg)
    except rospkg.ResourceNotFound as e:
        raise WtfException("Cannot find dependencies for package [%s]: missing %s"%(pkg, e))
    try:
        ctx.pkg_dir = r.get_path(pkg)
        ctx.manifest_file = os.path.join(ctx.pkg_dir, 'manifest.xml')
        ctx.manifest = r.get_manifest(pkg)
    except rospkg.ResourceNotFound:
        raise WtfException("Cannot locate manifest file for package [%s]"%pkg)
    except rospkg.InvalidManifest as e:
        raise WtfException("Package [%s] has an invalid manifest: %s"%(pkg, e))

def _load_stack(ctx, stack):
    """
    Utility for initializing WtfContext state
    @raise WtfException: if context state cannot be initialized
    """
    r = ctx.rosstack
    ctx.stack = stack
    try:
        ctx.stacks = [stack] + r.get_depends(stack, implicit=True)
    except rospkg.ResourceNotFound as e:
        raise WtfException("Cannot load dependencies of stack [%s]: %s"%(stack, e))
    try:
        ctx.stack_dir = r.get_path(stack)
    except rospkg.ResourceNotFound:
        raise WtfException("[%s] appears to be a stack, but it's not on your ROS_PACKAGE_PATH"%stack)
    
    
def _load_env(ctx, env):
    """
    Utility for initializing WtfContext state

    @raise WtfException: if context state cannot be initialized
    """
    ctx.env = env
    try:
        ctx.ros_root = env.get(rospkg.environment.ROS_ROOT, '/usr/share/ros')
    except KeyError:
        raise WtfException("ROS_ROOT is not set")
    ctx.ros_package_path = env.get(rospkg.environment.ROS_PACKAGE_PATH, '/usr/share/ros')
    ctx.pythonpath = env.get('PYTHONPATH', '/usr/lib/python2.7/dist-packages/')
    ctx.ros_master_uri = env.get(rosgraph.ROS_MASTER_URI, 'http://localhost:11311')