def run_audio_stream(robot_uid, sock, proc): logger = InfoLogger(__name__).get_logger() logger.info('[Audio] run_audio_stream start') try: while True: if proc.poll(): break output = proc.stdout.read(ConfigAudio.buffer_size) try: select.select([], [sock], []) except socket.error: logger.info('[Audio] socket shutdown') break format_data = format_send_data(robot_uid, output) sock.sendall(format_data) # logger.info('[Audio] send output : %s' % format_data) except Exception as e: logger.info('[Audio] run_audio_stream error : %s' % e) if not proc.poll(): proc.terminate() # proc.kill() logger.info('[Audio] run_audio_stream exit done')
def stop_servers(): logger = InfoLogger(__name__).get_logger() # logger.info('Servers to stop: %d' % len(Servers.server_threads)) for ins_name, thread in Servers.server_threads.iteritems(): thread.stop() logger.info('Stop server : %s' % ins_name)
def run_video_feed(robot_uid, sock, func, handle): logger = InfoLogger(__name__).get_logger() logger.info('[Video] run_video_feed start') try: while True: try: select.select([], [sock], []) except socket.error: logger.info('[Video] socket shutdown') break # image_container = yield func(handle) image_container = func(handle) image_data_lst = format_image_data(image_container) image_uid = uuid.uuid4().hex for image_dct in image_data_lst: send_data = format_send_data(robot_uid, image_uid, image_dct) sock.sendall(send_data) # logger.info('[Video] run_video_feed done') except Exception as e: logger.info('[Video] run_video_feed error : %s' % e) logger.info('[Video] run_video_feed exit done')
def __init__(self, robot_uid): self.logger = InfoLogger(__name__).get_logger() self.robot_uid = robot_uid self.host = ConfigMedia.host self.port = ConfigMedia.port self.path = ConfigMedia.path self.a_format = ConfigMedia.a_format self.analyze_duration = ConfigMedia.analyze_duration self.v_format = ConfigMedia.v_format self.pix_fmt = ConfigMedia.pix_fmt self.v_resolution = ConfigMedia.v_resolution self.audio_codec = ConfigMedia.audio_codec self.audio_bitrate = ConfigMedia.audio_bitrate self.strict_lvl = ConfigMedia.strict_lvl self.video_bitrate = ConfigMedia.video_bitrate self.output_format = ConfigMedia.output_format self.a_proc = None self.v_thread = None self.a_thread = None self.ff = None self.m_thread = None self.image_pipe = None self.audio_pipe = None
def __init__(self, robot_uid): self.logger = InfoLogger(__name__).get_logger() self.host = ConfigVideo.host self.port = ConfigVideo.port self.robot_uid = robot_uid self.sock = None
def __init__(self, port, connection): super(BaseTCPServer, self).__init__() self.name = self.__class__.__name__ self.logger = InfoLogger(self.name).get_logger() self.port = port self.connection = connection
def __init__(self, ip='127.0.0.1', port=9559): self.qi_ip = ip self.qi_port = port self.full_path = 'tcp://%s:%s' % (self.qi_ip, self.qi_port) self.session = None self.logger = InfoLogger(__name__).get_logger() self.set_session() self.setup_qi_services()
class QiSession(object): session = None logger = InfoLogger('QiSession').get_logger() service_dct = { 'ALAudioDevice': None, 'ALBasicAwareness': None, 'ALBattery': None, 'ALBehaviorManager': None, 'ALConnectionManager': None, 'ALMemory': None, 'ALMotion': None, 'ALSystem': None, 'ALTextToSpeech': None, 'ALVideoDevice': None, 'PackageManager': None, } @classmethod def log(cls, msg): cls.logger.info(msg) @classmethod def get_session(cls, qi_path): if not cls.session or not cls.session.isConnected(): cls.log('QiSession is setting up new session') try: try: # If no session is connecting, start an session app = qi.Application(url=qi_path) app.start() s = app.session except: # Another session is connecting(maybe AXMService), connect directly s = qi.Session() s.connect(qi_path) cls.session = s except Exception as e: cls.log('QiSession get_session error : %s' % e) return cls.session @classmethod def get_session_service(cls, qi_path): if None in cls.service_dct.values(): s = cls.get_session(qi_path) for k, v in cls.service_dct.items(): cls.service_dct[k] = s.service(k) return cls.service_dct
def __init__(self, stream, address, delimiter): self.logger = InfoLogger(__name__).get_logger() self.name = self.__class__.__name__ self.delimiter = delimiter self._stream = stream self._address = address self._stream.set_close_callback(self.on_close) self.read_message()
def run_media_stream(robot_uid, ff_obj): logger = InfoLogger(__name__).get_logger() logger.info('[Media] run_media_stream start') try: ff_obj.run() except Exception as e: logger.info('[Media] run_media_stream error : %s' % e) logger.info('[Media] run_media_stream exit done')
def __init__(self, robot_uid=None): self.logger = InfoLogger(__name__).get_logger() self.host = ConfigAudio.host self.port = ConfigAudio.port self.file_type = ConfigAudio.file_type self.rate = ConfigAudio.rate self.robot_uid = robot_uid self.sock = None self.proc = None
def run_audio_feed(proc, audio_pipe): logger = InfoLogger(__name__).get_logger() logger.info('[Media] run_audio_feed start') try: while not audio_pipe.is_closed(): # audio_pipe.write(proc.stdout.read(80)) audio_pipe.write(proc.stdout.readline()) except Exception as e: logger.info('[Media] run_audio_feed error : %s' % e) logger.info('[Media] run_audio_feed exit done')
def run_video_feed(func, handle, image_pipe): logger = InfoLogger(__name__).get_logger() logger.info('[Media] run_video_feed start') try: while not image_pipe.is_closed(): image_container = func(handle) image_pipe.write(image_container[6]) except Exception as e: logger.info('[Media] run_video_feed error : %s' % e) logger.info('[Media] run_video_feed exit done')
def __init__(self): self.logger = InfoLogger(__name__).get_logger() # self.ioloop = IOLoop() self.shell = ConfigSSH.local_ws_shell self.port = ConfigSSH.local_ws_port self.height = ConfigSSH.height self.width = ConfigSSH.width self.winheight = ConfigSSH.winheight self.winwidth = ConfigSSH.winwidth self.max_terminals = ConfigSSH.max_terminals self.running = False
def __init__(self): self.server_host = ConfigServer.host self.server_port = ConfigServer.port self.delimiter = ConfigServer.delimiter self.timeout = ConfigServer.timeout self.reconnect_delta = ConfigServer.reconnect_delta self.collector_handle_delta = ConfigCollector.handle_delta self.logger = InfoLogger(__name__).get_logger() self.thread_stop = False self.collector = Collector() self.executor = Executor()
def start_server_thread(cls, server_ins): ins_name = server_ins.__class__.__name__ if ins_name in cls.server_threads: return thread = ServerThread(server_ins) thread.setName('Thread-%s' % ins_name) cls.server_threads[ins_name] = thread logger = InfoLogger(__name__).get_logger() logger.info('server_threads count : %d' % len(cls.server_threads)) thread.start()
def run_write_client(sock, ws_connect): logger = InfoLogger(__name__).get_logger() logger.info('[writer] start') ws = yield ws_connect while True: try: recv_sock = sock.recv(1024) # logger.info('[writer] recv_sock : %r' % recv_sock) if recv_sock: msg_list = recv_sock.split(ConfigSSH.delimiter) for msg_str in msg_list: # msg_str may be '', if json loads failed, continue to next one try: msg_dict = json.loads(msg_str) except: continue msg = msg_dict.get('msg', None) if msg: # yield ws.write_message(msg) ws.write_message(msg) # logger.info('[writer] write to ws : %r' % msg) else: logger.info('[writer] read no msg from sock : %r' % msg) else: # sock.shutdown(socket.SHUT_RDWR) is called logger.info('[writer] socket shutdown') # send to ws, let run_read_client know and exit ws.write_message(r'["stdin", "\r"]') break except Exception as e: logger.info('[writer] error: %s' % e) break logger.info('[writer] exit done')
def run_read_client(sock, ws_connect, robot_uid, term_id): logger = InfoLogger(__name__).get_logger() logger.info('[reader] start') ws = yield ws_connect pairs = SocketMap.pairs.get(term_id, None) if pairs: pairs['websocket'] = ws SocketMap.pairs[term_id] = pairs while True: try: msg = yield ws.read_message() # logger.info('[reader] ws.read_message : %r' % msg) # ws server may return None after UnicodeDecodeError raised # if msg is None: # break if msg: # make sure the socket is not closed try: select.select([], [sock], []) except socket.error: logger.info('[reader] socket shutdown') break sock_msg = format_sock_msg(robot_uid, term_id, msg) sock.sendall(sock_msg) # logger.info('[reader] send to sock : %r' % sock_msg) else: logger.info('[reader] read no msg from ws : %r' % msg) break except Exception as e: logger.info('[reader] error: %s' % e) # break continue logger.info('[reader] exit done')
def __init__(self): self.logger = InfoLogger(__name__).get_logger() self.sys_command = SystemCommand() self.behavior_command = BehaviorCommand() self.package_command = PackageCommand() self.video_command = VideoCommand() self.demo_command = DemoCommand() self.ssh_command = SSHCommand() self.audio_command = AudioCommand() self.media_command = MediaCommand() self.command_maps = ( self.sys_command, self.behavior_command, self.package_command, self.video_command, self.demo_command, self.ssh_command, self.audio_command, self.media_command, )
class ClientManager(object): logger = InfoLogger("ClientManager").get_logger() @classmethod def clean_defunct_client(cls): for uid,iostream_obj in ConnectionMap.clients.items(): cls.logger.info('Cleanning %s' % uid) cls.logger.info('closed %s' % str(iostream_obj._stream.closed())) if iostream_obj._stream.closed(): cls.logger.info('%s is shutdown, clean' % uid) if ConnectionMap.clients.has_key(uid): cls.logger.info('ConnectionMap clients pop: %s' % uid) ConnectionMap.clients.pop(uid) if ConnectionMap.client_status.has_key(uid): cls.logger.info('ConnectionMap client_status pop: %s' % uid) ConnectionMap.client_status.pop(uid) for conn in ConnectionMap.ws_conn.values(): conn.refresh_client_status()
with open(self.pid_file, 'w') as f: f.write('') return "Done" except OSError, err: # if err.errno == errno.ESRCH: # return "Not running" if err.errno == errno.EPERM: return "No permission to signal this process!" else: return "Unknown error" if args.run: logger = InfoLogger(__name__).get_logger() start_servers() pid = os.getpid() manager = Manager() result = manager.kill_process() logger.info('Stop clients : %s' % result) manager.set_pid(pid) client = Client() client.connect() elif args.restart: logger = InfoLogger(__name__).get_logger()
def __init__(self, robot_uid): self.logger = InfoLogger(__name__).get_logger() self.robot_uid = robot_uid self.running = False
def __init__(self): self.logger = InfoLogger(__name__).get_logger() self.host = ConfigWebSocket.host self.port = ConfigWebSocket.port
def initialize(self): self.name = self.__class__.__name__ self.logger = InfoLogger(self.name).get_logger()
def __init__(self): self.pid_file = ConfigManager.pid_file self.logger = InfoLogger(__name__).get_logger()
def stop_servers(): logger = InfoLogger(__name__).get_logger() for server_name, thread in Servers.server_threads.items(): thread.stop() logger.info('Stop server : %s' % server_name)
def set_init_attr(self, uid=None): self.logger = InfoLogger(__name__).get_logger() self.uid = uid or uuid.uuid4().hex
def __init__(self, server_ins): super(ServerThread, self).__init__() self.server_ins = server_ins self._stop = threading.Event() self.logger = InfoLogger(__name__).get_logger()
def __init__(self, port): self.name = self.__class__.__name__ self.logger = InfoLogger(self.name).get_logger() self.port = port