From adcd4477aa843218d38c0be0397581f1538c83ea Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Wed, 14 Sep 2016 11:20:29 +0900 Subject: [PATCH 1/3] do not download the data if the target directory is not writeable From 58422083eea5c6ab26013da4e6c317928cfbe6d9 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Wed, 14 Sep 2016 11:34:53 +0900 Subject: [PATCH 2/3] catch resourceNotFound --- jsk_data/src/jsk_data/download_data.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jsk_data/src/jsk_data/download_data.py b/jsk_data/src/jsk_data/download_data.py index eaa252d15..956dfb834 100644 --- a/jsk_data/src/jsk_data/download_data.py +++ b/jsk_data/src/jsk_data/download_data.py @@ -81,6 +81,11 @@ def download_data(pkg_name, path, url, md5, download_client=None, if not osp.isabs(path): # get package path rp = rospkg.RosPack() + try: + pkg_path = rp.get_path(pkg_name) + except rospkg.ResourceNotFound: + print('\033[31m{name} is not found in {path}\033[0m'.format(name=pkg_name, path=rp.list())) + return pkg_path = rp.get_path(pkg_name) path = osp.join(pkg_path, path) # prepare cache dir From 1edb896440a2bd56400b902e9d923f68aa162a79 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Wed, 14 Sep 2016 12:33:23 +0900 Subject: [PATCH 3/3] create path direcotory before download data and return if permission denied --- jsk_data/src/jsk_data/download_data.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jsk_data/src/jsk_data/download_data.py b/jsk_data/src/jsk_data/download_data.py index 956dfb834..2c1c842a0 100644 --- a/jsk_data/src/jsk_data/download_data.py +++ b/jsk_data/src/jsk_data/download_data.py @@ -88,6 +88,12 @@ def download_data(pkg_name, path, url, md5, download_client=None, return pkg_path = rp.get_path(pkg_name) path = osp.join(pkg_path, path) + if not osp.exists(osp.dirname(path)): + try: + os.makedirs(osp.dirname(path)) + except OSError as e: + print('\033[31mCould not make direcotry {dir} {err}\033[0m'.format(dir=osp.dirname(path), err=e)) + return # prepare cache dir ros_home = os.getenv('ROS_HOME', osp.expanduser('~/.ros')) cache_dir = osp.join(ros_home, 'data', pkg_name) @@ -104,8 +110,6 @@ def download_data(pkg_name, path, url, md5, download_client=None, os.remove(path) os.symlink(cache_file, path) elif not osp.exists(path): - if not osp.exists(osp.dirname(path)): - os.makedirs(osp.dirname(path)) os.symlink(cache_file, path) # create link else: # not link and exists so skipping