addon.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import xbmcgui
  2. import xbmcaddon
  3. from xbmc import executebuiltin
  4. import traceback
  5. import os
  6. paramiko_available = True
  7. try:
  8. import paramiko
  9. except ImportError:
  10. paramiko_available = False
  11. addon = xbmcaddon.Addon()
  12. addonname = addon.getAddonInfo("name")
  13. sel_shutdown = 0 if paramiko_available else -1
  14. sel_remount = 1 if paramiko_available else 0
  15. if paramiko_available:
  16. selections = [
  17. "Power Off %s" % (addon.getSetting("host")),
  18. "Reount network mounts",
  19. "Cancel"
  20. ]
  21. else:
  22. selections = [
  23. "Reount network mounts",
  24. "Cancel"
  25. ]
  26. selected = xbmcgui.Dialog().contextmenu(list=selections)
  27. if selected == sel_shutdown:
  28. try:
  29. executebuiltin("ActivateWindow(busydialog)")
  30. ssh = paramiko.SSHClient()
  31. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  32. ssh.connect(addon.getSetting("host"),
  33. username=addon.getSetting("username"),
  34. password=addon.getSetting("password"))
  35. sin, out, err = ssh.exec_command(addon.getSetting("command"))
  36. output = "\n".join(out.readlines())
  37. error = "\n".join(err.readlines())
  38. ssh.close()
  39. executebuiltin("Dialog.Close(busydialog)")
  40. xbmcgui.Dialog().ok(addonname, "%s\n%s" % (output, error))
  41. except:
  42. trace = traceback.format_exc()
  43. executebuiltin("Dialog.Close(busydialog)")
  44. xbmcgui.Dialog().ok(addonname, trace)
  45. elif selected == sel_remount:
  46. try:
  47. os.system("/usr/bin/sudo /bin/mount -a")
  48. except:
  49. trace = traceback.format_exc()
  50. xbmcgui.Dialog().ok(addonname, trace)