Esempio n. 1
0
    def run(self):
        """UServer entry"""
        super(UServer, self).run()
        #TODO: below should be set by ConfManager

        if self.isEnableSocket:
            self.sock.bind(('localhost', 8089))
            self.sock.listen(5)

            while self.isRunning:
                try:
                    conn, addr = self.sock.accept()
                    try:
                        conn.settimeout(5)
                        buf = conn.recv(1024) #TODO: should be also in ConfManager
                        req = json.loads(buf)
                        logging.debug('[UniFileSync]: action %s, param %s', req['action'], req['param'])
                        #TODO: make it common for function usage
                        res, data = self.getHandler(req['action'])(req['param'])
                        ret = {'action': req['action'], 'param': {'data': data}, 'res': res, 'type': 'ack'}
                        conn.send(json.dumps(ret))
                    except socket.timeout:
                        logging.info('[UniFileSync]: socket time out from %s', addr)
                    except KeyError, e:
                        logging.error('[%s]: Key Error with param %s', self.getName(), req['param'])
                    finally:
                        conn.close()
                except KeyboardInterrupt:
                    print 'Press Ctrl+C'
                    self.stop()
Esempio n. 2
0
    def stopHandler(self, param):
        """stop handler for actors"""
        logging.debug('[%s]: stopHandler with parm %s', self.getName(), param)

        if param['name']:
            name = param['name'].lower()
        else:
            name = ''

        res = E_ACTOR_DEAD

        if name == 'all' or name == '':
            #The msg is broadcase
            msg = self.initMsg(MSG_TYPE_T_OPER, MSG_ID_T_OPER_STOP, None, True)
            self.notifyListeners(msg)

            for a in self.__startActors:
                rmsg = self.getMsg(2)
                if rmsg:
                    res = rmsg.body['result']

            logging.info('[UniFileSync]: stop server...')
            self.stop()
        elif name == 'monitor':
            if not self.fsMonitor.isRunning:
                res = E_ACTOR_DEAD
            msg = self.initMsg(MSG_TYPE_T_OPER, MSG_ID_T_OPER_STOP,
                               MSG_UNIQUE_ID_T_FS_MONITOR, True)
            self.msgBus.send(msg)
            rmsg = self.getMsg(2)
            if rmsg:
                res = rmsg.body['result']
        elif name == 'cloud':
            if not self.cActor.isRunning:
                res = E_ACTOR_DEAD
            msg = self.initMsg(MSG_TYPE_T_OPER, MSG_ID_T_OPER_STOP,
                               MSG_UNIQUE_ID_T_CLOUD_ACTOR, True)
            self.msgBus.send(msg)
            rmsg = self.getMsg(2)
            if rmsg:
                res = rmsg.body['result']
        else:
            logging.error('[%s]: stopHandler with name %s error',
                          self.getName(), param['name'])
            res = E_INVILD_PARAM

        return res, None
Esempio n. 3
0
    def stopHandler(self, param):
        """stop handler for actors"""
        logging.debug('[%s]: stopHandler with parm %s', self.getName(), param);

        if param['name']:
            name = param['name'].lower()
        else:
            name = ''

        res = E_ACTOR_DEAD

        if name == 'all' or name == '':
            #The msg is broadcase
            msg = self.initMsg(MSG_TYPE_T_OPER, MSG_ID_T_OPER_STOP, None, True)
            self.notifyListeners(msg)

            for a in self.__startActors:
                rmsg = self.getMsg(2)
                if rmsg:
                    res = rmsg.body['result']

            logging.info('[UniFileSync]: stop server...')
            self.stop()
        elif name == 'monitor':
            if not self.fsMonitor.isRunning:
                res = E_ACTOR_DEAD
            msg = self.initMsg(MSG_TYPE_T_OPER, MSG_ID_T_OPER_STOP, MSG_UNIQUE_ID_T_FS_MONITOR, True)
            self.msgBus.send(msg)
            rmsg = self.getMsg(2)
            if rmsg:
                res = rmsg.body['result']
        elif name == 'cloud':
            if not self.cActor.isRunning:
                res = E_ACTOR_DEAD
            msg = self.initMsg(MSG_TYPE_T_OPER, MSG_ID_T_OPER_STOP, MSG_UNIQUE_ID_T_CLOUD_ACTOR, True)
            self.msgBus.send(msg)
            rmsg = self.getMsg(2)
            if rmsg:
                res = rmsg.body['result']
        else:
            logging.error('[%s]: stopHandler with name %s error', self.getName(), param['name'])
            res = E_INVILD_PARAM

        return res, None
Esempio n. 4
0
    def run(self):
        """UServer entry"""
        super(UServer, self).run()
        #TODO: below should be set by ConfManager

        if self.isEnableSocket:
            self.sock.bind(('localhost', 8089))
            self.sock.listen(5)

            while self.isRunning:
                try:
                    conn, addr = self.sock.accept()
                    try:
                        conn.settimeout(5)
                        buf = conn.recv(
                            1024)  #TODO: should be also in ConfManager
                        req = json.loads(buf)
                        logging.debug('[UniFileSync]: action %s, param %s',
                                      req['action'], req['param'])
                        #TODO: make it common for function usage
                        res, data = self.getHandler(req['action'])(
                            req['param'])
                        ret = {
                            'action': req['action'],
                            'param': {
                                'data': data
                            },
                            'res': res,
                            'type': 'ack'
                        }
                        conn.send(json.dumps(ret))
                    except socket.timeout:
                        logging.info('[UniFileSync]: socket time out from %s',
                                     addr)
                    except KeyError, e:
                        logging.error('[%s]: Key Error with param %s',
                                      self.getName(), req['param'])
                    finally:
                        conn.close()
                except KeyboardInterrupt:
                    print 'Press Ctrl+C'
                    self.stop()
Esempio n. 5
0
        TaskBarIcon()
        return True

class UniFileSyncUIThread(threading.Thread):
    """UniFileSync UI thread"""
    def __init__(self, name):
        super(UniFileSyncUIThread, self).__init__()
        if not name:
            self.setName(name)

    def run(self):
        """thread entry"""
        self.app = UniFileSyncUI()
        self.app.MainLoop()

    def stop(self):
        """stop GUI thread"""
        self.app.ExitMainLoop()
        wx.WakeUpMainThread()

if __name__ == '__main__':
    u = UniFileSyncUIThread('UniFileSyncUI thread Test')
    u.start()

    try:
        while True:
            pass
    except KeyboardInterrupt:
        logging.info('[UniFileSyncUIThread Test]: User press Ctrl+C')
        u.stop()
Esempio n. 6
0
 def active(self):
     """Make plugin active"""
     self.manager.loadPlugin(self)
     logging.info('[%s] is active', self.name)
     return True
Esempio n. 7
0
 def unload(self):
     """Plugin unload"""
     logging.info('[%s] is unloading', self.name)
Esempio n. 8
0
 def active(self):
     """Make plugin active"""
     self.manager.loadPlugin(self)
     logging.info('[%s] is active', self.name)
     return True
Esempio n. 9
0
 def unload(self):
     """Plugin unload"""
     logging.info('[%s] is unloading', self.name)