Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
@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
def expand_to_packages(names, env=None):
"""
Expand names into a list of packages. Names can either be of packages or stacks.
@param names: names of stacks or packages
@type names: [str]
@return: ([packages], [not_found]). expand_packages() returns two
lists. The first is of packages names. The second is a list of
names for which no matching stack or package was found. Lists may have duplicates.
@rtype: ([str], [str])
"""
if env is None:
env = os.environ
ros_paths = rospkg.get_ros_paths(env)
rospack = rospkg.RosPack(ros_paths)
rosstack = rospkg.RosStack(ros_paths)
return rospkg.expand_to_packages(names, rospack, rosstack)
def create_local_process_args(node, machine, env=None):
"""
Subroutine for creating node arguments.
:param env: override os.environ. Warning, this does not override
substitution args in node configuration (for now), ``dict``
:returns: arguments for node process, ``[str]``
:raises: :exc:`NodeParamsException` If args cannot be constructed for Node
as specified (e.g. the node type does not exist)
"""
global _rospack
if not node.name:
raise ValueError("node name must be defined")
# create rospack instance if no cached value is available or for custom environments
if not _rospack or env is not None:
rospack = rospkg.RosPack(rospkg.get_ros_paths(env=env))
# cache rospack instance for default environment
if env is None:
_rospack = rospack
else:
rospack = _rospack
# - Construct rosrun command
remap_args = ["%s:=%s"%(src,dst) for src, dst in node.remap_args]
resolve_dict = {}
#resolve args evaluates substitution commands
#shlex parses a command string into a list of args
# - for the local process args, we *do* resolve the anon tag so that the user can execute
# - the node name and args must be resolved together in case the args refer to the anon node name
(node_name) = substitution_args.resolve_args((node.name), context=resolve_dict, resolve_anon=True)
node.name = node_name
def _init_rosstack(env=None):
global _rosstack, _ros_paths
if env is None:
env = os.environ
ros_paths = rospkg.get_ros_paths(env)
if ros_paths != _ros_paths:
_ros_paths = ros_paths
_rosstack = rospkg.RosStack(ros_paths)
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
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