63 lines
1.5 KiB
Python
63 lines
1.5 KiB
Python
#!/usr/bin/python
|
|
|
|
import subprocess
|
|
import argparse
|
|
|
|
palette = {
|
|
"background": "#232c31",
|
|
"foreground": "#c5c8c6",
|
|
"selection": "#425059",
|
|
"line": "#2d3c46",
|
|
"comment": "#777777",
|
|
"red": "#cc6666",
|
|
"orange": "#de935f",
|
|
"yellow": "#f0c674",
|
|
"green": "#b5bd68",
|
|
"aqua": "#8abeb7",
|
|
"blue": "#81a2be",
|
|
"purple": "#b294bb",
|
|
"window": "#303030",
|
|
"darkcolumn": "#1c1c1c",
|
|
"addbg": "#5F875F",
|
|
"addfg": "#d7ffaf",
|
|
"changebg": "#5F5F87",
|
|
"changefg": "#d7d7ff",
|
|
"delbg": "#cc6666",
|
|
"darkblue": "#00005f",
|
|
"darkcyan": "#005f5f",
|
|
"darkred": "#5f0000",
|
|
"darkpurple": "#5f005f",
|
|
}
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--color-running', default='#9f78e1')
|
|
parser.add_argument('--color-zero', default='#777777')
|
|
args = parser.parse_args()
|
|
|
|
|
|
def count_running_vm():
|
|
# For VirtualBox
|
|
# output = subprocess.check_output('VBoxManage list runningvms | wc -l',
|
|
# shell=True)
|
|
# return int(output.decode('UTF-8'))
|
|
|
|
# For libvirt
|
|
output = subprocess.check_output('doas virsh list | wc -l', shell=True)
|
|
libvirt_cnt = int(output.decode('UTF-8')) - 3
|
|
|
|
output = subprocess.check_output('vboxmanage list runningvms | wc -l', shell=True)
|
|
vbox_cnt = int(output.decode('UTF_8'))
|
|
|
|
return f"{libvirt_cnt} {vbox_cnt}"
|
|
|
|
|
|
def get_color(num_str):
|
|
if num_str != "0 0":
|
|
return '%{F' + args.color_running + '}'
|
|
|
|
return '%{F' + args.color_zero + '}'
|
|
|
|
|
|
num = count_running_vm()
|
|
print(get_color(num) + ' ' + num)
|