def test_get_ros_home(self):
    from roslib.rosenv import get_ros_root, get_ros_home
    import tempfile, os
    base = tempfile.gettempdir()
    ros_home_dir = os.path.join(base, 'ros_home_dir')
    home_dir = os.path.expanduser('~')

    # ROS_HOME has precedence
    env = {'ROS_ROOT': get_ros_root(), 'ROS_HOME': ros_home_dir }
    self.assertEquals(ros_home_dir, get_ros_home(env=env))

    env = {'ROS_ROOT': get_ros_root()}
    self.assertEquals(os.path.join(home_dir, '.ros'), get_ros_home(env=env))

    # test default assignment of env. Don't both checking return value 
    self.assert_(get_ros_home() is not None)
Exemple #2
0
def write_pid_file(options_pid_fn, options_core, port):
    from roslib.rosenv import get_ros_home
    if options_pid_fn or options_core:
        if options_pid_fn:
            pid_fn = options_pid_fn
        else:
            # NOTE: this assumption is not 100% valid until work on #3097 is complete
            if port is None:
                port = DEFAULT_MASTER_PORT
            #2987
            pid_fn = os.path.join(get_ros_home(), 'roscore-%s.pid'%(port))
        with open(pid_fn, "w") as f:
            f.write(str(os.getpid()))
Exemple #3
0
def get_ros_home():
    '''
    Returns the ROS HOME depending on ROS distribution API.
    @return: ROS HOME path
    @rtype: C{str}
    '''
    try:
        import rospkg.distro
        distro = rospkg.distro.current_distro_codename()
        if distro in ['electric', 'diamondback', 'cturtle']:
            import roslib.rosenv
            return roslib.rosenv.get_ros_home()
        else:
            from rospkg import get_ros_home
            return get_ros_home()
    except:
        from roslib import rosenv
        return rosenv.get_ros_home()
Exemple #4
0
import rosh
rosh.rosh_init()

# import all symbols after initialization
from rosh import *

import os, sys
plugins = sys.argv[1:]

for p in plugins:
    load(p, globals())

# load the user's roshrc file, if present
import roslib.rosenv as _rosenv
_roshrcp = os.path.join(_rosenv.get_ros_home(), 'rosh', 'roshrc.py')
if os.path.isfile(_roshrcp):
    print "loading roshrc"
    try:
        _f = open(_roshrcp)
        _plugins_copy = plugins[:]
        exec _f.read()
        if plugins and plugins != _plugins_copy:
            for p in plugins:
                try:
                    load(p, globals())
                except rosh.impl.exceptions.NoPlugin:
                    print >> sys.stderr, "ERROR: no plugin named [%s]"%(p)
                except rosh.impl.exceptions.InvalidPlugin, e:
                    print >> sys.stderr, "ERROR: plugin [%s] failed to load:\n\t%s"%(p, e)