def __updatePluginsList(self): parser = PluginParser() data = parser.parse() with open('%s/plugins.yml' % Board.pluginPath(), 'w') as fd: yaml.dump(data, fd, default_flow_style=False) # Notify clients through websocket Server(self.context).webSocketSend('plugins', 'storePluginsUpdated', None)
def installRemotePlugin(self, name, url, size, sha1): del sha1 # Install in a separate thread since calls are blocking filename = '%s/staging.zip' % Board.pluginPath() server = Server(self.context) def downloadFile(): urlFd = urllib2.urlopen(url) meta = urlFd.info() fileSize = int(meta.getheaders("Content-Length")[0]) if size is not None and fileSize != size: raise Exception("Size mismatch") fd = open(filename, 'wb') fileSizeDl = 0 blockSz = 8192 server.webSocketSend('plugins', 'downloadProgress', { 'downloaded': fileSizeDl, 'size': fileSize }) while True: buff = urlFd.read(blockSz) if not buff: break fileSizeDl += len(buff) fd.write(buff) server.webSocketSend('plugins', 'downloadProgress', { 'downloaded': fileSizeDl, 'size': fileSize }) fd.close() return True def install(): logging.warning('Install plugin %s from %s', name, url) try: downloadFile() except Exception as exception: server.webSocketSend('plugins', 'downloadFailed', {'msg': str(exception)}) return try: msg = self.importPlugin(filename) server.webSocketSend('plugins', 'install', msg) except ImportError as error: os.unlink(filename) server.webSocketSend( 'plugins', 'install', { 'success': False, 'msg': 'Error importing plugin: %s' % error }) thread = threading.Thread(name='Plugin installer', target=install) thread.daemon = True # Kill if needed thread.start()
def setState(self, newState): if newState == Hue.STATE_NO_BRIDGE: self.bridge = None self.username = None self.activated = False self.saveConfig() elif newState == Hue.STATE_UNAUTHORIZED: Application().queue(self.authorize) elif newState == Hue.STATE_AUTHORIZED: pass self.state = newState # Notify websocket Server(self.context).webSocketSend('hue', 'status', {'state': self.state})
def verifyAndLoad(self): try: if not self.verify(): return except Exception as e: logging.warning("Could not load plugin %s: %s", self.name, str(e)) return for p in self.packages: self.__loadEgg(p) # TODO: Do not just set the loaded flag here. Make sure the eggs where loaded and store any # backtrace if the loading failed. self.loaded = True # Push new info to web Server(self.context).webSocketSend('plugins', 'pluginInfo', self.infoObject())
def refreshClient(self): data = self._getData() if self.last_sent_data != data: self.last_sent_data = data Server(self.context).webSocketSend('shelly', 'refresh', data)
def p(self, msg, *args): try: logMsg = msg % args except: logMsg = msg Server(self.context).webSocketSend('lua', 'log', logMsg)
def __notifyFrontend(self, action, data): # pylint: disable=too-many-function-args Server(self.context).webSocketSend('plugins', action, data) TelldusLive(self.context).pushToWeb('plugins', action, data)
def log(self, msg, *args): try: logMsg = msg % args except Exception as __error: logMsg = msg Server(self.context).webSocketSend('lua', 'log', logMsg)