Skip to content

Commit

Permalink
Add filter argument for extracting tar in python >=3.12 (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane authored Oct 10, 2023
1 parent 7c53054 commit 0f68187
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sinol_make/oiejq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def install_oiejq():
oiejq_file.write(request.content)

with tarfile.open(oiejq_path) as tar:
tar.extractall(path=tmpdir)
util.extract_tar(tar, tmpdir)
shutil.copy(os.path.join(tmpdir, 'oiejq', 'oiejq.sh'), os.path.expanduser('~/.local/bin/oiejq'))
shutil.copy(os.path.join(tmpdir, 'oiejq', 'sio2jail'), os.path.expanduser('~/.local/bin/'))

Expand Down
8 changes: 8 additions & 0 deletions src/sinol_make/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import glob, importlib, os, sys, requests, yaml
import platform
import tarfile
import tempfile
import shutil
import hashlib
Expand Down Expand Up @@ -362,6 +363,13 @@ def try_fix_config(config):
return config


def extract_tar(tar: tarfile.TarFile, destination: str):
if sys.version_info.major == 3 and sys.version_info.minor >= 12:
tar.extractall(destination, filter='tar')
else:
tar.extractall(destination)


def color_red(text): return "\033[91m{}\033[00m".format(text)
def color_green(text): return "\033[92m{}\033[00m".format(text)
def color_yellow(text): return "\033[93m{}\033[00m".format(text)
Expand Down
7 changes: 4 additions & 3 deletions tests/commands/export/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile

from sinol_make import configure_parsers
from sinol_make import util as sinol_util
from sinol_make.commands.doc import Command as DocCommand
from tests import util
from tests.fixtures import create_package
Expand All @@ -19,7 +20,7 @@ def _test_archive(package_path, out, tar):

with tempfile.TemporaryDirectory() as tmpdir:
with tarfile.open(tar, "r") as tar:
tar.extractall(tmpdir)
sinol_util.extract_tar(tar, tmpdir)

extracted = os.path.join(tmpdir, task_id)
assert os.path.exists(extracted)
Expand Down Expand Up @@ -75,7 +76,7 @@ def test_doc_cleared(create_package):

with tempfile.TemporaryDirectory() as tmpdir:
with tarfile.open(f'{package_util.get_task_id()}.tgz', "r") as tar:
tar.extractall(tmpdir)
sinol_util.extract_tar(tar, tmpdir)

extracted = os.path.join(tmpdir, package_util.get_task_id())
assert os.path.exists(extracted)
Expand All @@ -100,7 +101,7 @@ def test_correct_permissions(create_package, capsys):

with tempfile.TemporaryDirectory() as tmpdir:
with tarfile.open(f'{task_id}.tgz', "r") as tar:
tar.extractall(tmpdir)
sinol_util.extract_tar(tar, tmpdir)

shell_ingen = os.path.join(tmpdir, task_id, 'prog', f'{task_id}ingen.sh')
assert os.path.exists(shell_ingen)
Expand Down

0 comments on commit 0f68187

Please sign in to comment.