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

[jsk_data][download_data.py] chmod decompressed data #1532

Merged
merged 1 commit into from
Jun 26, 2017
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
23 changes: 15 additions & 8 deletions jsk_data/src/jsk_data/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import rospkg


def extract_file(path, to_directory='.'):
def extract_file(path, to_directory='.', chmod=True):
print("Extracting '{path}'...".format(path=path))
if path.endswith('.zip'):
opener, mode = zipfile.ZipFile, 'r'
opener, mode, getnames = zipfile.ZipFile, 'r', lambda f: f.namelist()
elif path.endswith('.tar.gz') or path.endswith('.tgz'):
opener, mode = tarfile.open, 'r:gz'
opener, mode, getnames = tarfile.open, 'r:gz', lambda f: f.getnames()
elif path.endswith('.tar.bz2') or path.endswith('.tbz'):
opener, mode = tarfile.open, 'r:bz2'
opener, mode, getnames = tarfile.open, 'r:bz2', lambda f: f.getnames()
else:
raise ValueError("Could not extract '%s' as no appropriate "
"extractor is found" % path)
Expand All @@ -32,8 +32,11 @@ def extract_file(path, to_directory='.'):
file = opener(path, mode)
try:
file.extractall()
if chmod:
for fname in getnames(file):
os.chmod(fname, 0777)
root_files = list(set(name.split('/')[0]
for name in file.getnames()))
for name in getnames(file)))
finally:
file.close()
finally:
Expand All @@ -42,12 +45,16 @@ def extract_file(path, to_directory='.'):
return root_files


def decompress_rosbag(path, quiet=False):
def decompress_rosbag(path, quiet=False, chmod=True):
print("Decompressing '{path}'...".format(path=path))
argv = [path]
if quiet:
argv.append('--quiet')
rosbag.rosbag_main.decompress_cmd(argv)
if chmod:
orig_path = osp.splitext(path)[0] + '.orig.bag'
os.chmod(orig_path, 0777)
os.chmod(path, 0777)
print('...done')


Expand Down Expand Up @@ -137,7 +144,7 @@ def download_data(pkg_name, path, url, md5, download_client=None,
return
if extract:
# extract files in cache dir and create symlink for them
extracted_files = extract_file(cache_file, to_directory=cache_dir)
extracted_files = extract_file(cache_file, to_directory=cache_dir, chmod=True)
for file_ in extracted_files:
file_ = osp.join(cache_dir, file_)
dst_path = osp.join(osp.split(path)[0], osp.basename(file_))
Expand All @@ -153,4 +160,4 @@ def download_data(pkg_name, path, url, md5, download_client=None,
rp = rospkg.RosPack()
pkg_path = rp.get_path(pkg_name)
compressed_bag = osp.join(pkg_path, compressed_bag)
decompress_rosbag(compressed_bag, quiet=quiet)
decompress_rosbag(compressed_bag, quiet=quiet, chmod=chmod)