def __init__(self, lock): """ This is a constructor method for an updater class of the Arius output module. In creates a HTTP-client instance to communicate with server in order to get commands and takes give instance of RLock and sets it as its lock. Also, it creates a flag 'running' which allwos to kill this thread. """ threading.Thread.__init__(self) self._server_host = config["output_server_host"] self._server_port = config["output_server_port"] self._server_url = config["output_server_url"] self._server_connection = RESTClient(self._server_host, self._server_port, self._server_url) self._command_queue = [] self._current_command_type = None self._current_command_body = None self._lock = lock self.running = True
def __init__(self, server_host, server_port, commands_url, lock): """ This constructor method makes connection with the server, gets Rlock object and use it like its own lock and creates a flag "running" which allows to kill thread """ super(CommandReceiver, self).__init__() self._server_connection = RESTClient( server_host, server_port, commands_url) self._is_running = True self._command_queue = [] self._lock = lock
class CommandReceiver(threading.Thread): """ This class connect to the server and get new commands to execute """ def __init__(self, server_host, server_port, commands_url, lock): """ This constructor method makes connection with the server, gets Rlock object and use it like its own lock and creates a flag "running" which allows to kill thread """ super(CommandReceiver, self).__init__() self._server_connection = RESTClient( server_host, server_port, commands_url) self._is_running = True self._command_queue = [] self._lock = lock def run(self): """ This is the main method of an receiver. It checks if there`re any new commands on the server and in case if there are it returns these commands as self._current_commnad_type & self._current_command_body. """ while self._is_running: self._receive_command() sleep(.05) def _receive_command(self): """ It gets response from the server. If data is in command format then we add it to command queue """ data = self._server_connection.GET_request(True, 0) if data['type'] != 'none': self._lock.acquire() try: self._command_queue.append(Command(data['type'], data['command'])) logger.info('Command received: {} : {}'.format(data['type'], data['command'])) finally: self._lock.release() def get_state(self): """ It return the first command from the queue if it exist """ if not self._command_queue: return None command = self._command_queue.pop(0) return command def is_state(self): """ Return True if the command queue is not empty """ if not self._command_queue: return False else: return True
class OutputUpdater(threading.Thread): def __init__(self, lock): """ This is a constructor method for an updater class of the Arius output module. In creates a HTTP-client instance to communicate with server in order to get commands and takes give instance of RLock and sets it as its lock. Also, it creates a flag 'running' which allwos to kill this thread. """ threading.Thread.__init__(self) self._server_host = config["output_server_host"] self._server_port = config["output_server_port"] self._server_url = config["output_server_url"] self._server_connection = RESTClient(self._server_host, self._server_port, self._server_url) self._command_queue = [] self._current_command_type = None self._current_command_body = None self._lock = lock self.running = True def run(self): """ This is the main method of an updater. It checks if there`re any new commands on the server and in case if there are it returns these commands as self._current_commnad_type & self._current_command_body. """ while self.running: # print "updated" data = self._server_connection.GET_request(True, 0) if data['type'] != 'none': logger.debug('Received data {}'.format(data)) self._lock.acquire() try: self._command_queue.append( Command(data['type'], data['command'])) logger.info('Command received: {} : {}'.format( data['type'], data['command'])) finally: self._lock.release() else: pass time.sleep(.05) def reset(self): """ Just reset all values. """ self._lock.acquire() self._command_queue[:] = [] self._lock.release() def get_state(self): """ Return current values. Pure try to provide incapsulation. """ if not self._command_queue: return None, None data = self._command_queue.pop(0) return data.c_type, data.c_body def _is_command(self): """ Return True if there is command which output have to execue """ if self._command_queue: return True else: return False
import sys sys.path.append("../") from client import RESTClient #input_connection = RESTClient('127.0.0.1', 5000, '/core/input') output_connection = RESTClient('127.0.0.1', 5000, '/core/output') while True: t = raw_input() data = raw_input() command = { "type": t, # "type": "SPEECH", "command": data } response = output_connection.send_data_in_POST(command, True, 0) print '======='
sys.path.append("../") from client import RESTClient from config import config host = config['flask_server_address'] port = config['flask_server_port'] input_url = config['flask_server_input_client'] parser = argparse.ArgumentParser() parser.add_argument('-f', '--filename', default='none', help="Send first phrases from file") args = parser.parse_args() input_client = RESTClient(host, port, input_url) activation = ['ok arius'] search_request = [ 'what is abiliton', 'data science', 'mylko', 'iot', 'softserve' ] commands = [ 'zoom in', 'enlagre bitch', 'zoom out', 'scroll down now!', 'could you please scroll up' ] cancel = ['bye', 'thanks'] activated = False while True: request = []
def request(testcase_spec): request_obj = RESTCase.Get_request_obj(testcase_spec) with RESTClient() as client: responseInfo = client.request(request_obj) return responseInfo
import random import sys sys.path.append("../") from client import RESTClient from config import config host = config['flask_server_address'] port = config['flask_server_port'] input_url = config['flask_server_input_client'] parser = argparse.ArgumentParser() parser.add_argument('-f', '--filename', default='none', help="Send first phrases from file") args = parser.parse_args() input_client = RESTClient(host, port, input_url) activation = ['ok arius'] search_request = ['what is abiliton', 'data science', 'mylko', 'iot', 'softserve'] commands = ['zoom in', 'enlagre bitch', 'zoom out', 'scroll down now!', 'could you please scroll up'] cancel = ['bye', 'thanks'] activated = False while True: request = [] choice = random.random() delay = (random.random() * 10) + 1 if not activated: