Skip to content

k-spit/virsh-interactor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

virsh-interactor

Usage:

Add the following command to Startup Applications (Ubuntu):
python /path/to/script/virsh-interactor.py

Now with a right-click on the icon choose between:

  • Toggle domain (win10) - this will start/stop the virsh domain
  • Toggle Focusrite - this will attach/detach Focusrite device to/from domain
  • Toggle Medusa - this will attach/detach Speedlink Medusa Headset device to/from domain
  • Quit - this will shutdown the application

How it works

init method:

Define appindicator with svg icon.

self.indicator = appindicator.Indicator.new(APPINDICATOR_ID, CURRPATH+"/windows-logo.svg", appindicator.IndicatorCategory.SYSTEM_SERVICES)

Define Thread and daemonize it to make the indicator stopable.

self.update = Thread(target=self.show_seconds)
self.update.setDaemon(True)

Define thread-update function, check virsh domain status and if necessary change icon.

def update(self):
  t = 2
  while True:
      x = os.system(CURRPATH+"/focusrite-status.sh")
      if x == 256:
          print("attached")
          self.indicator.set_icon(CURRPATH+"/attached.svg")
      else:
          print("not attached")
          self.indicator.set_icon(CURRPATH+"/detached.svg")
      time.sleep(1)
      t += 1

Define functions for attaching/detaching the interface. Each of these function is used to execute a underlying shell script with the help of os.system.

vendorid="0x1235" # device vendorid
domain="win10" # virsh domain
devicedesc=usb-focusrite.xml

# to attach a device to a domain
virsh attach-device $domain --file $devicedesc

# to detach a device from a domain
virsh detach-device $domain --file $devicedesc

For updating the status (icon) update function is call every second by thread. To get the current status (is the device attached, or not ?), focusrite-status.sh is called by os.system.

status=$(virsh domstate $domain)
if [ "$status" = "shut off" ];then
  echo -e "shut off"
  exit 2
fi
virsh dumpxml $domain > "$domain".xml
if grep -q $vendorid "$domain".xml; then
  echo -e "vendorid: $vendorid found"
  exit 1
else
  echo -e "no vendorid found"
  exit 2
fi

If the domain is not running focusrite-status.sh exits with exit 2 (x == 512 in virsh-interactor.py). If the device is already attached, focusrite-status.sh exits with exit 1 (x == 256 in virsh-interactor.py).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published