Mini Shell
import os
from pathlib import Path
from typing import Union
def find_bin(cmd: str) -> Union[Path, None]:
"""Locate the specified program or return None"""
path = Path(cmd)
if path.is_absolute():
if path.is_file():
return path
return None
for exec_path in os.get_exec_path():
path = Path(exec_path) / cmd
if path.is_file():
return path
return None
def is_vps() -> bool:
"""Check if running on a Virtuozzo container"""
try:
with open("/proc/vz/veinfo", encoding='utf-8') as handle:
ve_data = handle.read().strip()
except IOError:
return False # if veinfo doesn't exist this can't be a vps
if ve_data.count("\n") != 0:
return False
try:
# if veinfo contains >1 line, this is a VZ node
veid = int(ve_data.split()[0])
except ValueError:
return False
return veid != 0
Zerion Mini Shell 1.0