Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Backports:SLE-15-SP4
virtme
0007-Add-util.find_binary-to-find-binaries.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0007-Add-util.find_binary-to-find-binaries.patch of Package virtme
From 73bb57a4e1b08e61bc290c282c787d8e0719135e Mon Sep 17 00:00:00 2001 From: Andy Lutomirski <luto@kernel.org> Date: Wed, 13 Nov 2019 13:06:48 -0800 Subject: [PATCH 7/9] Add util.find_binary() to find binaries This factors the logic out from find_busybox() Signed-off-by: Andy Lutomirski <luto@kernel.org> --- virtme/mkinitramfs.py | 22 +++------------------- virtme/util.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 virtme/util.py diff --git a/virtme/mkinitramfs.py b/virtme/mkinitramfs.py index 98c7528..1a21c9b 100644 --- a/virtme/mkinitramfs.py +++ b/virtme/mkinitramfs.py @@ -13,6 +13,7 @@ import os.path import shlex import itertools from . import cpiowriter +from . import util def make_base_layout(cw): for dir in (b'lib', b'bin', b'var', b'etc', b'newroot', b'dev', b'proc', @@ -167,22 +168,5 @@ def mkinitramfs(out, config) -> None: cw.write_trailer() def find_busybox(root, is_native) -> Optional[str]: - names = ['busybox-static', 'busybox.static', 'busybox'] - dirs = [os.path.join(*i) for i in itertools.product( - ['usr/local', 'usr', ''], - ['bin', 'sbin'])] - - for n in names: - if is_native: - # Search PATH first - path = shutil.which(n) - if path is not None: - return path - - for d in dirs: - path = os.path.join(root, d, n) - if os.path.isfile(path): - return path - - # We give up. - return None + return util.find_binary(['busybox-static', 'busybox.static', 'busybox'], + root=root, use_path=is_native) diff --git a/virtme/util.py b/virtme/util.py new file mode 100644 index 0000000..16b7ef7 --- /dev/null +++ b/virtme/util.py @@ -0,0 +1,33 @@ +# -*- mode: python -*- +# util.py: Misc helpers +# Copyright © 2014-2019 Andy Lutomirski +# Licensed under the GPLv2, which is available in the virtme distribution +# as a file called LICENSE with SHA-256 hash: +# 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643 + +from typing import Optional, Sequence + +import os +import shutil +import itertools + +def find_binary(names: Sequence[str], root: str = '/', + use_path: bool = True) -> Optional[str]: + dirs = [os.path.join(*i) for i in itertools.product( + ['usr/local', 'usr', ''], + ['bin', 'sbin'])] + + for n in names: + if use_path: + # Search PATH first + path = shutil.which(n) + if path is not None: + return path + + for d in dirs: + path = os.path.join(root, d, n) + if os.path.isfile(path): + return path + + # We give up. + return None -- 2.26.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor