Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch if package is not found / do not download the data if the target directory is not writeable #1455

Merged
merged 3 commits into from
Sep 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions jsk_data/src/jsk_data/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,19 @@ 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)
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)
Expand All @@ -99,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
Expand Down