-
Notifications
You must be signed in to change notification settings - Fork 48
/
extract_all.py
executable file
·50 lines (39 loc) · 1.63 KB
/
extract_all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
from os import path, makedirs
import tarfile
from tqdm import tqdm
subjects = ['S1', 'S5', 'S6', 'S7', 'S8', 'S9', 'S11']
# https://stackoverflow.com/a/6718435
def commonprefix(m):
s1 = min(m)
s2 = max(m)
for i, c in enumerate(s1):
if c != s2[i]:
return s1[:i]
return s1
def extract_tgz(tgz_file, dest):
if path.exists(dest):
return
with tarfile.open(tgz_file, 'r:gz') as tar:
members = [m for m in tar.getmembers() if m.isreg()]
member_dirs = [path.dirname(m.name).split(path.sep) for m in members]
base_path = path.sep.join(commonprefix(member_dirs))
for m in members:
m.name = path.relpath(m.name, base_path)
tar.extractall(dest)
def extract_all():
for subject_id in tqdm(subjects, ascii=True):
out_dir = path.join('extracted', subject_id)
makedirs(out_dir, exist_ok=True)
extract_tgz('archives/Poses_D2_Positions_{}.tgz'.format(subject_id),
path.join(out_dir, 'Poses_D2_Positions'))
extract_tgz('archives/Poses_D3_Positions_{}.tgz'.format(subject_id),
path.join(out_dir, 'Poses_D3_Positions')),
extract_tgz('archives/Poses_D3_Positions_mono_{}.tgz'.format(subject_id),
path.join(out_dir, 'Poses_D3_Positions_mono')),
extract_tgz('archives/Poses_D3_Positions_mono_universal_{}.tgz'.format(subject_id),
path.join(out_dir, 'Poses_D3_Positions_mono_universal')),
extract_tgz('archives/Videos_{}.tgz'.format(subject_id),
path.join(out_dir, 'Videos'))
if __name__ == '__main__':
extract_all()