blob: 7cb7db67c03d48f772845b2dc7e59316cdae5740 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import os, shutil, subprocess
def untar(tarball_path, parent_path, base):
path = os.path.join(parent_path, base)
try:
shutil.rmtree(path)
except FileNotFoundError:
pass
os.makedirs(parent_path, exist_ok=True)
try:
subprocess.check_call(['/bin/tar', 'xfC', tarball_path, parent_path])
except FileNotFoundError:
import tarfile
tar = tarfile.open(tarball_path)
tar.extractall(path=parent_path)
tar.close()
return path
|