Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def connected_file():
return os.path.join(rospkg.get_ros_home(), 'turtlebot-connected')
def get_ros_home():
'''
Returns the ROS HOME depending on ROS distribution API.
:return: ROS HOME path
:rtype: 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 Exception:
from roslib import rosenv
return rosenv.get_ros_home()
environment.
@param cache: empty dictionary to store package list in.
If no cache argument provided, will use internal _pkg_dir_cache
and will return cached answers if available.
The format of the cache is {package_name: dir_path, ros_root, ros_package_path}.
@type cache: {str: str, str, str}
@param ros_package_path: ROS_ROOT value
@type ros_root: str
@param ros_package_path: ROS_PACKAGE_PATH value or '' if not specified
@type ros_package_path: str
@return: True if on-disk cache matches and was loaded, false otherwise
@rtype: bool
"""
try:
with open(os.path.join(rospkg.get_ros_home(), 'rospack_cache')) as f:
for l in f.readlines():
l = l[:-1]
if not len(l):
continue
if l[0] == '#':
# check that the cache matches our env
if l.startswith('#ROS_ROOT='):
if not l[len('#ROS_ROOT='):] == ros_root:
return False
elif l.startswith('#ROS_PACKAGE_PATH='):
if not l[len('#ROS_PACKAGE_PATH='):] == ros_package_path:
return False
else:
cache[os.path.basename(l)] = l, ros_root, ros_package_path
return True
except Exception:
def get_cwd(cwd, binary=''):
result = ''
if cwd == 'node':
result = os.path.dirname(binary)
elif cwd == 'cwd':
result = os.getcwd()
elif cwd == 'ros-root':
result = rospkg.get_ros_root()
else:
result = rospkg.get_ros_home()
if not os.path.exists(result):
try:
os.makedirs(result)
except OSError:
# exist_ok=True
pass
return result
def get_gopher_home():
'''
Retrieve the location of the gopher home directory.
If it does not exist, create a new directory and return this path.
.. todo:: move this to a common library (currently also used by gopher_customisation)
:return: the gopher home directory (path)
:rtype str:
'''
gopher_home = os.path.join(rospkg.get_ros_home(), 'gopher')
if not os.path.isdir(gopher_home):
os.makedirs(gopher_home)
return os.path.join(rospkg.get_ros_home(), 'gopher')
# the log dir itself should not be symlinked as latest
if logfile_dir != log_dir:
if sys.platform not in ['win32']:
try:
success = renew_latest_logdir(logfile_dir)
if not success:
sys.stderr.write("INFO: cannot create a symlink to latest log directory\n")
except OSError as e:
sys.stderr.write("INFO: cannot create a symlink to latest log directory: %s\n" % e)
config_file = os.environ.get('ROS_PYTHON_LOG_CONFIG_FILE')
if not config_file:
# search for logging config file in ROS_HOME, ROS_ETC_DIR or relative
# to the rosgraph package directory.
config_dirs = [os.path.join(rospkg.get_ros_home(), 'config'),
rospkg.get_etc_ros_dir()]
try:
config_dirs.append(os.path.join(
rospkg.RosPack().get_path('rosgraph'), 'conf'))
except rospkg.common.ResourceNotFound:
pass
for config_dir in config_dirs:
for extension in ('conf', 'yaml'):
f = os.path.join(config_dir,
'python_logging{}{}'.format(os.path.extsep,
extension))
if os.path.isfile(f):
config_file = f
break
if config_file is not None:
break
def get_gopher_home():
'''
Retrieve the location of the gopher home directory.
If it does not exist, create a new directory and return this path.
.. todo:: move this to a common library (currently also used by gopher_customisation)
:return: the gopher home directory (path)
:rtype str:
'''
gopher_home = os.path.join(rospkg.get_ros_home(), 'gopher')
if not os.path.isdir(gopher_home):
os.makedirs(gopher_home)
return os.path.join(rospkg.get_ros_home(), 'gopher')
def get_home():
'''
Retrieve the location of the home directory for the rocon remocon's
temporary storage needs
@return the rocon remocon home directory (path object).
@type str
'''
return os.path.join(rospkg.get_ros_home(), 'rocon', 'remocon')
def get_ros_home(self):
'''
Returns the ROS HOME path 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:
import rospkg
return rospkg.get_ros_home()
except:
import traceback
print traceback.format_exc()
import roslib.rosenv
return roslib.rosenv.get_ros_home()