import xbmcgui import xbmcaddon from xbmc import executebuiltin import traceback import os paramiko_available = True try: import paramiko except ImportError: paramiko_available = False addon = xbmcaddon.Addon() addonname = addon.getAddonInfo("name") sel_shutdown = 0 if paramiko_available else -1 sel_remount = 1 if paramiko_available else 0 if paramiko_available: selections = [ "Power Off %s" % (addon.getSetting("host")), "Reount network mounts", "Cancel" ] else: selections = [ "Reount network mounts", "Cancel" ] selected = xbmcgui.Dialog().contextmenu(list=selections) if selected == sel_shutdown: try: executebuiltin("ActivateWindow(busydialog)") ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(addon.getSetting("host"), username=addon.getSetting("username"), password=addon.getSetting("password")) sin, out, err = ssh.exec_command(addon.getSetting("command")) output = "\n".join(out.readlines()) error = "\n".join(err.readlines()) ssh.close() executebuiltin("Dialog.Close(busydialog)") xbmcgui.Dialog().ok(addonname, "%s\n%s" % (output, error)) except: trace = traceback.format_exc() executebuiltin("Dialog.Close(busydialog)") xbmcgui.Dialog().ok(addonname, trace) elif selected == sel_remount: try: os.system("/usr/bin/sudo /bin/mount -a") except: trace = traceback.format_exc() xbmcgui.Dialog().ok(addonname, trace)