qvm_dvm_nautilus.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. from subprocess import Popen
  3. from gi.repository import Nautilus, GObject
  4. class OpenInDvmItemExtension(GObject.GObject, Nautilus.MenuProvider):
  5. '''Open File(s) in DisposableVM.
  6. Uses the nautilus-python api to provide a context menu within Nautilus which
  7. will enable the user to select file(s) to to open in a disposableVM
  8. '''
  9. def get_file_items(self, window, files):
  10. '''Attaches context menu in Nautilus
  11. '''
  12. if not files:
  13. return
  14. menu_item = Nautilus.MenuItem(name='QubesMenuProvider::OpenInDvm',
  15. label='Open In DisposableVM',
  16. tip='',
  17. icon='')
  18. menu_item.connect('activate', self.on_menu_item_clicked, files)
  19. return menu_item,
  20. def on_menu_item_clicked(self, menu, files):
  21. '''Called when user chooses files though Nautilus context menu.
  22. '''
  23. for file_obj in files:
  24. # Check if file still exists
  25. if file_obj.is_gone():
  26. return
  27. gio_file = file_obj.get_location()
  28. # Use subprocess.DEVNULL in python >= 3.3
  29. devnull = open(os.devnull, 'wb')
  30. # Use Popen instead of subprocess.call to spawn the process
  31. Popen(['nohup', '/usr/bin/qvm-open-in-dvm', gio_file.get_path()], stdout=devnull, stderr=devnull)