class SpeechUtil(QtGui.QSystemTrayIcon):
    def __init__(self,parent=None):
	    QtGui.QSystemTrayIcon.__init__(self,QtGui.QIcon(ICON_ON),parent)
	    self.state=True
	    #self.icon=QtGui.QSystemTrayIcon(QtGui.QIcon("/home/icon/on.png"),app)
	    self.menu=QtGui.QMenu(parent)
	    self.exitAction=self.menu.addAction("Exit")
	    self.exitAction.triggered.connect(self.quit_app)
	    self.runAction=self.menu.addAction("Run")
	    self.runAction.triggered.connect(self.turnOn)
	    self.killAction=self.menu.addAction("Kill")
	    self.killAction.triggered.connect(self.turnOff)
	    self.setContextMenu(self.menu)
	    self.show()
	    self.remote_access=ServerProxy("http://"+HOST+":"+str(8585)+"/")
	    self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    	    self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
	    self.sock.bind(("0.0.0.0",9898))
	    self.running=True
	    print "done"
    def start(self):
	thread.start_new_thread(self.check,())
	print 'started'
	sys.exit(app.exec_())
    def check(self):
	while self.running:
	    data,addr=self.sock.recvfrom(1024)
	    
	    message=json.loads(data)
	    
	    if message['Data']['Result']==True:
    	        if not self.state:
	    	    self.setIconOn(True)
		    self.state=True
	    elif self.state==True:
	        self.setIconOn(False)
	        self.state=False
	
    def turnOn(self):
	self.remote_access.access('run')
	print "on"

    def turnOff(self):
	self.remote_access.access('kill')
	print "off"

    def setIconOn(self,on_off):
	if on_off:
	    self.setIcon(QtGui.QIcon(ICON_ON))
	else: self.setIcon(QtGui.QIcon(ICON_OFF))
    def quit_app(self):
	self.running=False
	exit()
Exemple #2
0
class OpenNLP:
    def __init__(self, host='localhost', port=8080):
        uri = "http://%s:%d" % (host, port)
        self.server = ServerProxy(uri)

    def parse(self, text):
        return self.server.parse(text)
Exemple #3
0
class OpenNLP:
    def __init__(self, host='localhost', port=8080):
        uri = "http://%s:%d" % (host, port)
        self.server = ServerProxy(uri)

    def parse(self, text):
        return self.server.parse(text)
Exemple #4
0
 def connect(self, str_ip=None, int_port=None):
     '''
     [Function]:
         Used to bind the KCS instance to a certain port. This method can also be used to
         change the IP or port of the KCS interface. And it can even be used to connect to
         another KCS
     [Input   ]:
         str_ip - the IP address of the host OS
         int_port - the JSON RPC port which the target host OS is using. Default is 9009
     [Output  ]:     
         Initialize/Re-initialize the RPC client
     '''
     if str_ip:
         self.str_ip = str_ip
     if int_port:
         self.int_port = int_port
     self.obj_json_client = ServerProxy('http://%s:%s' %
                                        (self.str_ip, self.int_port))
Exemple #5
0
 def connect(self, str_ip = None, int_port = None):
     '''
     [Function]:
         Used to bind the KCS instance to a certain port. This method can also be used to
         change the IP or port of the KCS interface. And it can even be used to connect to
         another KCS
     [Input   ]:
         str_ip - the IP address of the host OS
         int_port - the JSON RPC port which the target host OS is using. Default is 9009
     [Output  ]:     
         Initialize/Re-initialize the RPC client
     '''
     if str_ip:
         self.str_ip = str_ip
     if int_port:
         self.int_port = int_port 
     self.obj_json_client = ServerProxy('http://%s:%s' % (self.str_ip, self.int_port))
    def __init__(self,parent=None):
	    QtGui.QSystemTrayIcon.__init__(self,QtGui.QIcon(ICON_ON),parent)
	    self.state=True
	    #self.icon=QtGui.QSystemTrayIcon(QtGui.QIcon("/home/icon/on.png"),app)
	    self.menu=QtGui.QMenu(parent)
	    self.exitAction=self.menu.addAction("Exit")
	    self.exitAction.triggered.connect(self.quit_app)
	    self.runAction=self.menu.addAction("Run")
	    self.runAction.triggered.connect(self.turnOn)
	    self.killAction=self.menu.addAction("Kill")
	    self.killAction.triggered.connect(self.turnOff)
	    self.setContextMenu(self.menu)
	    self.show()
	    self.remote_access=ServerProxy("http://"+HOST+":"+str(8585)+"/")
	    self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    	    self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
	    self.sock.bind(("0.0.0.0",9898))
	    self.running=True
	    print "done"
Exemple #7
0
class OpenNLP:
    def __init__(self, host='localhost', port=8080):
        uri = "http://%s:%d" % (host, port)
        self.server = ServerProxy(uri)

    def parse(self, text):
        p = self.server.parse(text)
        try:
            return _parse_tree(p)
        except:
            print "problem with parse tree:", p
            return None

    def list_nouns(self, text):
        l = []
        p = self.parse(text)
        if p is not None:
            _list_nouns(self.parse(text), l)
        return l
Exemple #8
0
class OpenNLP:
    def __init__(self, host='localhost', port=8080):
        uri = "http://%s:%d" % (host, port)
        self.server = ServerProxy(uri)

    def parse(self, text):
        p = None
        try:
            p = self.server.parse(text)
            return _parse_tree(p)
        except:
            print "problem with parse tree:", p
            return None

    def _list_nouns(self, sentences):
        nouns = []
        for s in sentences:
            l = []
            p = self.parse(s)
            if p is not None:
                try:
                    _list_nouns(p, l)
                    nouns += l
                except:
                    pass
        return nouns

    def list_nouns(self, sentences):
        nouns = []
        for s in sentences:

            tagged = nltk.pos_tag(s.split(' '))
            for word, tag in tagged:
                if tag.startswith('N'):
                    nouns.append(word)
        return nouns
Exemple #9
0
"""Recommendation service client"""
from jsonrpclib.jsonrpc import ServerProxy
from json import load

with open('../config.json') as config_data:
    cfg = load(config_data)

URL = cfg['rpc_client']['recommendation_service']['url']
client = ServerProxy(URL)


def get_preference_for_user(user_id):
    """Get user preference"""
    preference = client.get_preference_for_user(user_id)
    print("Preference list:%s" % str(preference))
    return preference
Exemple #10
0
 def __init__(self, host='localhost', port=8080):
     uri = "http://%s:%d" % (host, port)
     self.server = ServerProxy(uri)
Exemple #11
0
class CKCS(CLogger):
    '''
    ************************************************
    [Author]: [email protected]
    [Description]: This class is for supporting KCS interface to IPMI. Is is using
        KCS implemented in Atragon
    [Methods]:    
        - is_valid - check if the interface is valid
        - connect - connect to a target host OS(Atragon)
        - send_ipmi - standard method for IPMI interface
        - log - event logging method
    [History]:                                                                 
    ************************************************  
    Version    Editor      Date        Comments
    ************************************************
    V1.0     Bruce Yang 03/21/2013     First Version                          
    ************************************************
    '''
    def __init__(self, str_ip=None, int_port=_DEFAULT_ATRAGON_PORT):
        CLogger.__init__(self)
        self.obj_json_client = None
        self.str_ip = str_ip
        self.int_port = int_port

    def is_valid(self):
        '''
        [Function]:
            Check the validity of the KCS interface. Checking include:
                - If the JSON RPC client is initialized
        [Input   ]: NA
        [Output  ]:
            True - if valid
            False - if invalid
        '''
        if self.obj_json_client is None:  # The "is" here cannot be replaced by "="
            return False
        return True

    def is_connected(self):
        return self.is_valid()

    def get_ip(self):
        return self.str_ip

    def set_ip(self, str_ip):
        self.str_ip = str_ip

    def get_port(self):
        return self.int_port

    def set_port(self, int_port):
        self.int_port = int_port

    def connect(self, str_ip=None, int_port=None):
        '''
        [Function]:
            Used to bind the KCS instance to a certain port. This method can also be used to
            change the IP or port of the KCS interface. And it can even be used to connect to
            another KCS
        [Input   ]:
            str_ip - the IP address of the host OS
            int_port - the JSON RPC port which the target host OS is using. Default is 9009
        [Output  ]:     
            Initialize/Re-initialize the RPC client
        '''
        if str_ip:
            self.str_ip = str_ip
        if int_port:
            self.int_port = int_port
        self.obj_json_client = ServerProxy('http://%s:%s' %
                                           (self.str_ip, self.int_port))

    def reconnect(self, str_ip=None, int_port=_DEFAULT_ATRAGON_PORT):
        '''
        [Function]:
            Duplicate of connect for compatibility.
        [Input   ]:
            str_ip - the IP address of the host OS(Atragon)
            int_port - the JSON RPC port which the target host OS(Atragon) is using. Default is 9009
        [Output  ]:     
            Initialize/Re-initialize the RPC client
        '''
        return self.connect(str_ip, int_port)

    def send_ipmi(self, list_request, int_retry=3):
        '''         
        [Function]: send ipmi command via KCS interface
        [Input   ]: 
                list_request  - a list of integrates including: 
                                net function, command ID and request data
        [Output  ]:
                int_result    - an integrate indicating if this IPMI interaction is finished
                                if the IPMI command is executed and has return data, int_result = 0
                                or int_result = -1  
                list_response - a list of integrate including:
                                completion code and response data
        '''
        # check if the KCS interface is valid
        if not self.is_valid():
            self.log('WARNING',
                     'Trying to send IPMI while the interface is not valid')
            return -1, []
        # send command
        try:
            for i in range(int_retry):
                dict_atragon_return = self.obj_json_client.ipmi(list_request)
                if dict_atragon_return[_KEY_ATRAGON_EXECUTE_RESULT] != 0:
                    continue
                # the return value of the "ipmi" method in host OS(Atragon) is a dictionary in which the value
                # for "execute_result" is the execution result and the value for "return_value" is the
                # return data of the IPMI command
                # dict_atragon_return = {'execute_result':##, 'return_value':[]}
                return dict_atragon_return[
                    _KEY_ATRAGON_EXECUTE_RESULT], dict_atragon_return[
                        _KEY_ATRAGON_RETURN_VALUE]

            # If fail with all retries, return int_result with an empty list
            return -1, []
        except:
            self.log(
                'WARNING',
                'Failed to send JSONRPC command to RPC server: \n%s' %
                traceback.format_exc())
            return -1, []

    def log(self, str_level, str_message):
        '''
        [Function]: 
            Add KCS prefix before pass the message to the Logger class
        [Input   ]:
            str_level - the log level
            str_message - the log information
        [Output  ]:     
            Will write log in to log file
        '''
        str_message = '(KCS: %s)%s' % (self.str_ip, str_message)
        return CLogger.log(self, str_level, str_message)
Exemple #12
0
 def __init__(self, host='localhost', port=8080):
     uri = "http://%s:%d" % (host, port)
     self.server = ServerProxy(uri)
Exemple #13
0
class CKCS(CLogger):
    '''
    ************************************************
    [Author]: [email protected]
    [Description]: This class is for supporting KCS interface to IPMI. Is is using
        KCS implemented in Atragon
    [Methods]:    
        - is_valid - check if the interface is valid
        - connect - connect to a target host OS(Atragon)
        - send_ipmi - standard method for IPMI interface
        - log - event logging method
    [History]:                                                                 
    ************************************************  
    Version    Editor      Date        Comments
    ************************************************
    V1.0     Bruce Yang 03/21/2013     First Version                          
    ************************************************
    '''
    def __init__(self, str_ip = None, int_port = _DEFAULT_ATRAGON_PORT):
        CLogger.__init__(self)
        self.obj_json_client = None
        self.str_ip = str_ip
        self.int_port = int_port
    
    def is_valid(self):
        '''
        [Function]:
            Check the validity of the KCS interface. Checking include:
                - If the JSON RPC client is initialized
        [Input   ]: NA
        [Output  ]:
            True - if valid
            False - if invalid
        '''
        if self.obj_json_client is None: # The "is" here cannot be replaced by "="
            return False
        return True
    
    def is_connected(self):
        return self.is_valid()
    
    def get_ip(self):
        return self.str_ip
    
    def set_ip(self, str_ip):
        self.str_ip = str_ip
        
    def get_port(self):
        return self.int_port
    
    def set_port(self, int_port):
        self.int_port = int_port
    
    def connect(self, str_ip = None, int_port = None):
        '''
        [Function]:
            Used to bind the KCS instance to a certain port. This method can also be used to
            change the IP or port of the KCS interface. And it can even be used to connect to
            another KCS
        [Input   ]:
            str_ip - the IP address of the host OS
            int_port - the JSON RPC port which the target host OS is using. Default is 9009
        [Output  ]:     
            Initialize/Re-initialize the RPC client
        '''
        if str_ip:
            self.str_ip = str_ip
        if int_port:
            self.int_port = int_port 
        self.obj_json_client = ServerProxy('http://%s:%s' % (self.str_ip, self.int_port))

    def reconnect(self, str_ip = None, int_port = _DEFAULT_ATRAGON_PORT):
        '''
        [Function]:
            Duplicate of connect for compatibility.
        [Input   ]:
            str_ip - the IP address of the host OS(Atragon)
            int_port - the JSON RPC port which the target host OS(Atragon) is using. Default is 9009
        [Output  ]:     
            Initialize/Re-initialize the RPC client
        '''
        return self.connect(str_ip, int_port)
    
    def send_ipmi(self, list_request, int_retry = 3):
        '''         
        [Function]: send ipmi command via KCS interface
        [Input   ]: 
                list_request  - a list of integrates including: 
                                net function, command ID and request data
        [Output  ]:
                int_result    - an integrate indicating if this IPMI interaction is finished
                                if the IPMI command is executed and has return data, int_result = 0
                                or int_result = -1  
                list_response - a list of integrate including:
                                completion code and response data
        '''
        # check if the KCS interface is valid
        if not self.is_valid():
            self.log('WARNING', 'Trying to send IPMI while the interface is not valid')
            return -1, []
        # send command
        try:
            for i in range(int_retry):
                dict_atragon_return = self.obj_json_client.ipmi(list_request)
                if dict_atragon_return[_KEY_ATRAGON_EXECUTE_RESULT] != 0:
                    continue
                # the return value of the "ipmi" method in host OS(Atragon) is a dictionary in which the value
                # for "execute_result" is the execution result and the value for "return_value" is the 
                # return data of the IPMI command
                # dict_atragon_return = {'execute_result':##, 'return_value':[]}
                return dict_atragon_return[_KEY_ATRAGON_EXECUTE_RESULT], dict_atragon_return[_KEY_ATRAGON_RETURN_VALUE]
            
            # If fail with all retries, return int_result with an empty list
            return -1, []
        except:
            self.log('WARNING', 'Failed to send JSONRPC command to RPC server: \n%s' % traceback.format_exc())
            return -1, []
        
    def log(self, str_level, str_message):
        '''
        [Function]: 
            Add KCS prefix before pass the message to the Logger class
        [Input   ]:
            str_level - the log level
            str_message - the log information
        [Output  ]:     
            Will write log in to log file
        '''
        str_message = '(KCS: %s)%s' % (self.str_ip, str_message)
        return CLogger.log(self, str_level, str_message)
Exemple #14
0
from jsonrpclib.jsonrpc import ServerProxy

atragon_server = ServerProxy('http://%s:%s' % ('192.168.1.21', 9009))

atragon_server.send_command('cli IpmiSend RAW_SEND 0x06 0x01', 'bruce', '0601')
atragon_server.send_command('cli ls', 'bruce', '11111')
return_value = atragon_server.get_results('bruce')
for each_result in return_value['return_value']:
    print each_result