diff options
author | Andy Lutomirski <luto@kernel.org> | 2019-09-27 10:21:26 -0700 |
---|---|---|
committer | Andy Lutomirski <luto@kernel.org> | 2019-09-27 10:21:26 -0700 |
commit | c6ad9bb7cc29ac75ae8a455e38bd82e81d6d4df2 (patch) | |
tree | cb24746c817dc7485561f3b4ec46df808a61059c | |
parent | 065476593886093c4c6e85c7a0cd496aa529875e (diff) | |
download | virtme-c6ad9bb7cc29ac75ae8a455e38bd82e81d6d4df2.tar.gz |
kmod: Improve logic to find and run virtme-prep-kdir-mods
Signed-off-by: Andy Lutomirski <luto@kernel.org>
-rw-r--r-- | virtme/commands/run.py | 3 | ||||
-rw-r--r-- | virtme/guest_tools.py | 25 | ||||
l--------- | virtme/scripts | 1 |
3 files changed, 26 insertions, 3 deletions
diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 740fb99..8bc353b 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -15,6 +15,7 @@ import sys import shlex import re import itertools +import pkg_resources from .. import virtmods from .. import modfinder from .. import mkinitramfs @@ -164,7 +165,7 @@ def find_kernel_and_mods(arch, args): arg_fail("please run virtme-prep-kdir-mods to update virtme's kernel modules directory or use --mods=auto", show_usage=False) else: # Auto-refresh virtme's kernel modules directory - os.system('virtme-prep-kdir-mods') + guest_tools.run_script('virtme-prep-kdir-mods') moddir = os.path.join(virtme_mods, 'lib/modules', '0.0.0') modfiles = modfinder.find_modules_from_install( virtmods.MODALIASES, root=virtme_mods, kver='0.0.0') diff --git a/virtme/guest_tools.py b/virtme/guest_tools.py index 96c1cc2..b84f761 100644 --- a/virtme/guest_tools.py +++ b/virtme/guest_tools.py @@ -1,14 +1,16 @@ # -*- mode: python -*- # resources.py: Find virtme's resources -# Copyright © 2014 Andy Lutomirski +# 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 -"""Helpers to find virtme's guest tools.""" +"""Helpers to find virtme's guest tools and host scripts.""" import os +import shutil import pkg_resources +import subprocess def find_guest_tools(): """Return the path of the guest tools installed with the running virtme. @@ -19,3 +21,22 @@ def find_guest_tools(): # No luck. This is somewhat surprising. return None + +def find_script(name): + # If we're running out of a source checkout, we can find scripts through + # the 'virtme/scripts' symlink. + fn = pkg_resources.resource_filename(__name__, 'scripts/%s' % name) + if os.path.isfile(fn): + return fn + + # Otherwise assume we're actually installed and in PATH. + fn = shutil.which(name) + if fn is not None: + return fn + + # No luck. This is somewhat surprising. + raise Exception('could not find script %s' % name) + +def run_script(name): + fn = find_script(name) + subprocess.check_call(executable=fn, args=[fn]) diff --git a/virtme/scripts b/virtme/scripts new file mode 120000 index 0000000..19f285a --- /dev/null +++ b/virtme/scripts @@ -0,0 +1 @@ +../bin
\ No newline at end of file |