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

Log more startup info #199

Merged
merged 7 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
staticx: Add which_exec()
  • Loading branch information
JonathonReinhart committed Oct 9, 2021
commit 474e422a5e4bc61097b48749098d2c544e28b40a
9 changes: 9 additions & 0 deletions staticx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def copy_fileobj_to_tempfile(fsrc, **kwargs):
fdst.seek(0)
return fdst


def which_exec(name, env=None):
for path in os.get_exec_path(env=env):
xp = os.path.join(path, name)
if os.access(xp, os.X_OK):
return xp
return None


def is_iterable(x):
"""Returns true if x is iterable but not a string"""
return isinstance(x, Iterable) and not isinstance(x, str)
Expand Down
12 changes: 12 additions & 0 deletions unittest/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tempfile
import os
import pytest
import subprocess

from staticx import utils

Expand Down Expand Up @@ -63,3 +64,14 @@ def test_single_empty_default():

def test_single_key_none_default():
assert utils.single([1, 2, 3], key=lambda x: x<0, default='ok') == 'ok'

# which_exec
def test_which_exec_common():
def ext_which(name):
return subprocess.check_output(['which', name]).decode().strip()

for name in ('true', 'date', 'bash', 'python3'):
assert ext_which(name) == utils.which_exec(name)

def test_which_exec_bogus():
assert utils.which_exec('zZzZzZzZzZzZzZz') == None