roslib: continuing to unwind the ball of yarn of interdepends

This commit is contained in:
Ken Conley 2011-10-06 02:51:15 +00:00
parent e13cf1b5ad
commit 5b08cc8a64
6 changed files with 48 additions and 32 deletions

View File

@ -52,12 +52,12 @@ import sys
import re
import string
import roslib.exceptions
import rospkg
import roslib.manifest
import roslib.packages
import roslib.names
import roslib.resources
import roslib.rospack
VERBOSE = False
@ -76,7 +76,7 @@ SEP = '/' #e.g. std_msgs/String
CONSTCHAR = '='
COMMENTCHAR = '#'
class MsgSpecException(roslib.exceptions.ROSLibException): pass
class MsgSpecException(Exception): pass
#TODOXXX: unit test
def base_msg_type(type_):
@ -471,7 +471,7 @@ def load_package_dependencies(package, load_recursive=False):
m = roslib.manifest.parse_file(manifest_file)
depends = [d.package for d in m.depends] # #391
else:
depends = roslib.rospack.rospack_depends(package)
depends = rospkg.RosPack().get_depends(package, implicit=True)
msgs = []
failures = []

View File

@ -61,8 +61,9 @@ try:
except ImportError:
import urlparse
import roslib.exceptions
import roslib.rosenv
#TODO: change this to rosgraph equivalents once we have ported this module
ROS_IP = 'ROS_IP'
ROS_HOSTNAME = 'ROS_HOSTNAME'
SIOCGIFCONF = 0x8912
SIOCGIFADDR = 0x8915
@ -137,10 +138,10 @@ def get_address_override():
# check ROS_HOSTNAME and ROS_IP environment variables, which are
# aliases for each other
if roslib.rosenv.ROS_HOSTNAME in os.environ:
return os.environ[roslib.rosenv.ROS_HOSTNAME]
elif roslib.rosenv.ROS_IP in os.environ:
return os.environ[roslib.rosenv.ROS_IP]
if ROS_HOSTNAME in os.environ:
return os.environ[ROS_HOSTNAME]
elif ROS_IP in os.environ:
return os.environ[ROS_IP]
return None
def is_local_address(hostname):
@ -298,7 +299,7 @@ def create_local_xmlrpc_uri(port):
## handshake utils ###########################################
class ROSHandshakeException(roslib.exceptions.ROSLibException):
class ROSHandshakeException(Exception):
"""
Exception to represent errors decoding handshake
"""

View File

@ -42,11 +42,10 @@ import sys
import logging
import logging.config
import roslib.rosenv
from roslib.rosenv import get_ros_root, ROS_LOG_DIR, ROS_HOME, makedirs_with_parent_perms
import roslib.exceptions
from rospkg import get_ros_root, get_log_dir
from rospkg.environment import ROS_LOG_DIR
get_log_dir = roslib.rosenv.get_log_dir
import roslib.exceptions
def configure_logging(logname, level=logging.INFO, filename=None, env=None):
"""
@ -101,3 +100,26 @@ def configure_logging(logname, level=logging.INFO, filename=None, env=None):
logging.config.fileConfig(config_file, disable_existing_loggers=False)
return log_filename
def makedirs_with_parent_perms(p):
"""
Create the directory using the permissions of the nearest
(existing) parent directory. This is useful for logging, where a
root process sometimes has to log in the user's space.
@param p: directory to create
@type p: str
"""
p = os.path.abspath(p)
parent = os.path.dirname(p)
# recurse upwards, checking to make sure we haven't reached the
# top
if not os.path.exists(p) and p and parent != p:
makedirs_with_parent_perms(parent)
s = os.stat(parent)
os.mkdir(p)
# if perms of new dir don't match, set anew
s2 = os.stat(p)
if s.st_uid != s2.st_uid or s.st_gid != s2.st_gid:
os.chown(p, s.st_uid, s.st_gid)
if s.st_mode != s2.st_mode:
os.chmod(p, s.st_mode)

View File

@ -41,20 +41,23 @@ import os
import sys
import subprocess
import roslib.exceptions
import roslib.rosenv
import rospkg
if sys.hexversion > 0x03000000: #Python3
python3 = True
else:
python3 = False
import warnings
warnings.warn("roslib.rospack is deprecated, please use rospkg", stacklevel=2)
def rospackexec(args):
"""
@return: result of executing rospack command (via subprocess). string will be strip()ed.
@rtype: str
@raise roslib.exceptions.ROSLibException: if rospack command fails
"""
rospack_bin = os.path.join(roslib.rosenv.get_ros_root(), 'bin', 'rospack')
rospack_bin = os.path.join(rospkg.get_ros_root(), 'bin', 'rospack')
if python3:
val = subprocess.Popen([rospack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
val = val.decode().strip()
@ -119,7 +122,7 @@ def rosstackexec(args):
@rtype: str
@raise roslib.exceptions.ROSLibException: if rosstack command fails
"""
rosstack_bin = os.path.join(roslib.rosenv.get_ros_root(), 'bin', 'rosstack')
rosstack_bin = os.path.join(rospkg.get_ros_root(), 'bin', 'rosstack')
if python3:
val = subprocess.Popen([rosstack_bin] + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
val = val.decode().strip()

View File

@ -47,16 +47,8 @@ import string
import subprocess
import sys
import roslib.exceptions
import roslib.launcher
import roslib.message
import roslib.msgs
import roslib.names
import roslib.network
import roslib.packages
import roslib.rosenv
PRODUCT = 'ros'
## caller ID for master calls where caller ID is not vital
_GLOBAL_CALLER_ID = '/script'
@ -142,18 +134,20 @@ def get_master():
@return: XML-RPC proxy to ROS master
@rtype: xmlrpclib.ServerProxy
@raises ValueError if master URI is invalid
"""
try:
import xmlrpc.client as xmlrpcclient #Python 3.x
except ImportError:
import xmlrpclib as xmlrpcclient #Python 2.x
# changed this to not look as sys args and remove dependency on roslib.rosenv for cleaner cleanup
uri = os.environ['ROS_MASTER_URI']
# #1730 validate URL for better error messages
uri = roslib.rosenv.get_master_uri()
try:
roslib.network.parse_http_host_and_port(uri)
except ValueError:
raise roslib.exceptions.ROSLibException("invalid master URI: %s"%uri)
raise ValueError("invalid master URI: %s"%uri)
return xmlrpcclient.ServerProxy(uri)
@deprecated

View File

@ -42,10 +42,6 @@ import sys
import os
import getopt
import roslib.exceptions
import roslib.packages
import roslib.rosenv
STACK_FILE = 'stack.xml'
import roslib.manifestlib