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

Autoupdate oiejq #222

Merged
merged 10 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def configure_parsers():

def check_oiejq():
if util.is_linux() and not oiejq.check_oiejq():
print(util.warning('`oiejq` in `~/.local/bin/` not found, installing now...'))
print(util.warning('`Up to date `oiejq` in `~/.local/bin/` not found, installing new version...'))
MasloMaslane marked this conversation as resolved.
Show resolved Hide resolved
try:
if oiejq.install_oiejq():
print(util.info('`oiejq` was successfully installed.'))
Expand Down
28 changes: 20 additions & 8 deletions src/sinol_make/oiejq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ def _check_if_oiejq_executable(path):
if not os.access(path, os.X_OK):
return False

try:
p = subprocess.Popen([path], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
return p.returncode == 0
except FileNotFoundError:
return False
oiejq = subprocess.Popen([path], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
oiejq.wait()
return oiejq.returncode == 0


def _check_sio2jail(path):
sio2jail = subprocess.Popen(path + " --version", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = sio2jail.communicate()
return out == (b"SIO2jail v1.5.0 compiled on Apr 15 2024 12:34:31 Linux 6.1.0-20-amd64 with gcc 10.2.1 20210110\n"
b"libseccomp 2.5.4\n")


def _check_oiejq(path):
return util.get_file_md5(path) == '7225efe59cb3052fa533b9fbc9ebf099'


def check_oiejq(path = None):
Expand All @@ -29,9 +38,12 @@ def check_oiejq(path = None):
return False

if path is not None:
return _check_if_oiejq_executable(path)
return _check_if_oiejq_executable(path) and _check_sio2jail(os.path.join(os.path.dirname(path), 'sio2jail')) \
and _check_oiejq(path)

if _check_if_oiejq_executable(os.path.expanduser('~/.local/bin/oiejq')):
if _check_if_oiejq_executable(os.path.expanduser('~/.local/bin/oiejq')) and \
_check_sio2jail(os.path.expanduser('~/.local/bin/sio2jail')) and \
_check_oiejq(os.path.expanduser('~/.local/bin/oiejq')):
return True
else:
return False
Expand Down
37 changes: 33 additions & 4 deletions tests/test_oiejq.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
import sys
from urllib.request import urlretrieve
import pytest

from sinol_make import oiejq, util
Expand All @@ -15,7 +16,7 @@ def test_install_oiejq():
os.remove(os.path.expanduser('~/.local/bin/oiejq'))
os.remove(os.path.expanduser('~/.local/bin/sio2jail'))
except IsADirectoryError:
shutil.rmtree(os.path.expanduser('~/.local/bin/oiejq'), ignore_errors=True)
shutil.rmtree(os.path.expanduser('~/.local/bin/oiejq'), ignore_errors=True)
except FileNotFoundError:
pass
assert not oiejq.check_oiejq()
Expand All @@ -27,7 +28,7 @@ def test_install_oiejq():
os.remove(os.path.expanduser('~/.local/bin/sio2jail'))
except FileNotFoundError:
pass

assert not oiejq.check_oiejq()
os.makedirs(os.path.expanduser('~/.local/bin/oiejq'))
with pytest.raises(SystemExit):
Expand All @@ -43,7 +44,7 @@ def test_check_oiejq():
os.remove(os.path.expanduser('~/.local/bin/oiejq'))
os.remove(os.path.expanduser('~/.local/bin/sio2jail'))
except IsADirectoryError:
shutil.rmtree(os.path.expanduser('~/.local/bin/oiejq'), ignore_errors=True)
shutil.rmtree(os.path.expanduser('~/.local/bin/oiejq'), ignore_errors=True)
except FileNotFoundError:
pass

Expand All @@ -58,7 +59,7 @@ def test_check_oiejq():
assert not oiejq.check_oiejq()
with open(os.path.expanduser('~/.local/bin/oiejq'), 'w') as f:
f.write('#!/bin/bash\necho "test"')
assert oiejq.check_oiejq()
assert oiejq._check_if_oiejq_executable(os.path.expanduser('~/.local/bin/oiejq'))


@pytest.mark.github_runner
Expand All @@ -69,6 +70,7 @@ def test_perf_counters_not_set():
if sys.platform != 'linux':
return

oiejq.install_oiejq()
with pytest.raises(SystemExit):
oiejq.check_perf_counters_enabled()

Expand All @@ -81,3 +83,30 @@ def test_perf_counters_set():
if not util.is_linux():
return
oiejq.check_perf_counters_enabled()


@pytest.mark.github_runner
def test_updating():
"""
Test updating oiejq
"""
if sys.platform != 'linux':
return
try:
os.remove(os.path.expanduser('~/.local/bin/oiejq'))
os.remove(os.path.expanduser('~/.local/bin/sio2jail'))
except IsADirectoryError:
shutil.rmtree(os.path.expanduser('~/.local/bin/oiejq'), ignore_errors=True)
except FileNotFoundError:
pass
assert not oiejq.check_oiejq()
assert oiejq.install_oiejq()
assert oiejq.get_oiejq_path() == os.path.expanduser('~/.local/bin/oiejq')

# Download older sio2jail
urlretrieve('https://github.com/sio2project/sio2jail/releases/download/v1.4.3/sio2jail',
os.path.expanduser('~/.local/bin/sio2jail'))
os.chmod(os.path.expanduser('~/.local/bin/sio2jail'), 0o777)
assert not oiejq.check_oiejq()
assert oiejq.install_oiejq()
assert oiejq.check_oiejq()
Loading