Files
.github
LICENSES
android
build
doc
python
build
__init__.py
autotools.py
cmake.py
dirs.py
download.py
ffmpeg.py
libs.py
makeproject.py
meson.py
project.py
quilt.py
tar.py
toolchain.py
verify.py
zlib.py
src
subprojects
systemd
test
win32
.clang-format
.gitignore
.readthedocs.yaml
AUTHORS
COPYING
NEWS
README.md
meson.build
meson_options.txt
mpd.svg
valgrind.suppressions
mpd/python/build/tar.py
2023-09-26 14:28:23 +02:00

21 lines
602 B
Python

import os, shutil, subprocess
def untar(tarball_path: str, parent_path: str, base: str,
lazy: bool=False) -> str:
path = os.path.join(parent_path, base)
if lazy and os.path.isdir(path):
return path
try:
shutil.rmtree(path)
except FileNotFoundError:
pass
os.makedirs(parent_path, exist_ok=True)
try:
subprocess.check_call(['tar', 'xfC', tarball_path, parent_path])
except FileNotFoundError:
import tarfile
tar = tarfile.open(tarball_path)
tar.extractall(path=parent_path)
tar.close()
return path