Skip to content

Commit

Permalink
Merge pull request #1467 from wkentaro/download_data-multiple-workspace
Browse files Browse the repository at this point in the history
[jsk_data] Create softlink for extracted files in download_data
  • Loading branch information
k-okada authored Oct 25, 2016
2 parents 61ec855 + 361bd7b commit 89dc7e5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion jsk_data/src/jsk_data/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import shlex
import subprocess
import shutil
import sys
import tarfile
import zipfile
Expand All @@ -26,15 +27,19 @@ def extract_file(path, to_directory='.'):

cwd = os.getcwd()
os.chdir(to_directory)
root_files = []
try:
file = opener(path, mode)
try:
file.extractall()
root_files = list(set(name.split('/')[0]
for name in file.getnames()))
finally:
file.close()
finally:
os.chdir(cwd)
print('...done')
return root_files


def decompress_rosbag(path, quiet=False):
Expand Down Expand Up @@ -116,7 +121,16 @@ def download_data(pkg_name, path, url, md5, download_client=None,
sys.stderr.write("WARNING: '{0}' exists\n".format(path))
return
if extract:
extract_file(path, to_directory=osp.dirname(path))
# extract files in cache dir and create symlink for them
extracted_files = extract_file(cache_file, to_directory=cache_dir)
for file_ in extracted_files:
file_ = osp.join(cache_dir, file_)
dst_dir = osp.join(osp.split(path)[0], osp.basename(file_))
if osp.islink(dst_dir):
os.remove(dst_dir)
elif osp.exists(dst_dir):
shutil.rmtree(dst_dir)
os.symlink(file_, dst_dir)
for compressed_bag in compressed_bags:
if not osp.isabs(compressed_bag):
rp = rospkg.RosPack()
Expand Down

0 comments on commit 89dc7e5

Please sign in to comment.