Move mounting code to utils.py, move a lot of chroot-logic from packages to chroot.py, cmd_chroot
also moar crossdirect Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
parent
a4c06446e3
commit
d85c00fa12
8 changed files with 207 additions and 110 deletions
32
utils.py
32
utils.py
|
@ -1,4 +1,6 @@
|
|||
from shutil import which
|
||||
import atexit
|
||||
import subprocess
|
||||
|
||||
|
||||
def programs_available(programs) -> bool:
|
||||
|
@ -8,3 +10,33 @@ def programs_available(programs) -> bool:
|
|||
if not which(program):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def umount(dest):
|
||||
return subprocess.run(
|
||||
[
|
||||
'umount',
|
||||
'-lc',
|
||||
dest,
|
||||
],
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
|
||||
def mount(src: str, dest: str, options=['bind'], type=None) -> subprocess.CompletedProcess:
|
||||
opts = []
|
||||
type = []
|
||||
|
||||
for opt in options:
|
||||
opts += ['-o', opt]
|
||||
|
||||
if type:
|
||||
type = ['-t', type]
|
||||
|
||||
result = subprocess.run(['mount'] + type + opts + [
|
||||
src,
|
||||
dest,
|
||||
])
|
||||
if result.returncode == 0:
|
||||
atexit.register(umount, dest)
|
||||
return result
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue