From 88f9edcdb70facd679e01351a9ca5d6562ed08a2 Mon Sep 17 00:00:00 2001 From: Ken Conley Date: Tue, 16 Feb 2010 19:53:21 +0000 Subject: [PATCH] roslib: copied makedirs_with_parent_perms to rosenv, as it is common functionality for ROS environment directories --- core/roslib/src/roslib/rosenv.py | 21 +++++++++++++++++++++ core/roslib/src/roslib/roslogging.py | 1 + 2 files changed, 22 insertions(+) diff --git a/core/roslib/src/roslib/rosenv.py b/core/roslib/src/roslib/rosenv.py index 3f81f4d7..c54c3481 100644 --- a/core/roslib/src/roslib/rosenv.py +++ b/core/roslib/src/roslib/rosenv.py @@ -277,3 +277,24 @@ def get_test_results_dir(env=None): return env[ROS_TEST_RESULTS_DIR] else: return os.path.join(get_ros_home(env), 'test_results') + +# this is a copy of the roslogging utility. it's been moved here as it is a common +# routine for programs using accessing ROS directories +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) + os.chown(p, s.st_uid, s.st_gid) + os.chmod(p, s.st_mode) diff --git a/core/roslib/src/roslib/roslogging.py b/core/roslib/src/roslib/roslogging.py index 22e6d580..586b0512 100644 --- a/core/roslib/src/roslib/roslogging.py +++ b/core/roslib/src/roslib/roslogging.py @@ -100,6 +100,7 @@ def configure_logging(logname, level=logging.INFO, filename=None, additional=Non logger.addHandler(handler) return log_filename +# deprecated: replace with rosenv copy def makedirs_with_parent_perms(p): """ Create the directory using the permissions of the nearest