2021-09-30 01:00:28 +02:00
|
|
|
from shutil import which
|
2021-10-01 18:25:42 +02:00
|
|
|
import atexit
|
|
|
|
import subprocess
|
2021-09-30 01:00:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
def programs_available(programs) -> bool:
|
|
|
|
if type(programs) is str:
|
|
|
|
programs = [programs]
|
|
|
|
for program in programs:
|
|
|
|
if not which(program):
|
|
|
|
return False
|
|
|
|
return True
|
2021-10-01 18:25:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def umount(dest):
|
|
|
|
return subprocess.run(
|
|
|
|
[
|
|
|
|
'umount',
|
|
|
|
'-lc',
|
|
|
|
dest,
|
|
|
|
],
|
2021-10-04 12:57:52 +02:00
|
|
|
capture_output=True,
|
2021-10-01 18:25:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2021-10-04 12:57:52 +02:00
|
|
|
if result.returncode == 0:
|
|
|
|
atexit.register(umount, dest)
|
|
|
|
return result
|