def handle_mpd_output(fd, fd2idx, hostsAndInfo): global myHost, fullDirName, rshCmd, user, mpdCmd, debug, verbose idx = fd2idx[fd] host = hostsAndInfo[idx]['host'] port = fd.readline().strip() if debug: print "debug: mpd on %s on port %s" % (host, port) if port.isdigit(): hostsAndInfo[idx]['list_port'] = int(port) tempSock = MPDSock(name='temp_to_mpd') try: tempSock.connect((host, int(port))) except: tempSock.close() tempSock = 0 if tempSock: msgToSend = {'cmd': 'ping', 'ifhn': 'dummy', 'port': 0} tempSock.send_dict_msg(msgToSend) msg = tempSock.recv_dict_msg() # RMB: WITH TIMEOUT ?? if not msg or not msg.has_key('cmd') or msg['cmd'] != 'challenge': mpd_print(1,'failed to ping mpd on %s; recvd output=%s' % \ (host,msg) ) tempOut = tempSock.recv(1000) print tempOut try: getoutput('%s/mpdallexit.py' % (fullDirName)) except: pass exit(-1) tempSock.close() else: mpd_print(1, 'failed to connect to mpd on %s' % (host)) try: getoutput('%s/mpdallexit.py' % (fullDirName)) except: pass exit(-1) else: mpd_print(1, 'from mpd on %s, invalid port info:' % (host)) print port print fd.read() try: getoutput('%s/mpdallexit.py' % (fullDirName)) except: pass exit(-1) if verbose: print "RUNNING: mpd on", hostsAndInfo[fd2idx[fd]]['host'] if debug: print "debug: info for running mpd:", hostsAndInfo[fd2idx[fd]]
def handle_mpd_output(fd,fd2idx,hostsAndInfo): global myHost, fullDirName, rshCmd, user, mpdCmd, debug, verbose idx = fd2idx[fd] host = hostsAndInfo[idx]['host'] # port = fd.readline().strip() port = 'no_port' for line in fd.readlines(): # handle output from shells that echo stuff line = line.strip() splitLine = line.split('=') if splitLine[0] == 'mpd_port': port = splitLine[1] break if debug: print "debug: mpd on %s on port %s" % (host,port) if port.isdigit(): hostsAndInfo[idx]['list_port'] = int(port) tempSock = MPDSock(name='temp_to_mpd') try: tempSock.connect((host,int(port))) except: tempSock.close() tempSock = 0 if tempSock: msgToSend = { 'cmd' : 'ping', 'ifhn' : 'dummy', 'port' : 0} tempSock.send_dict_msg(msgToSend) msg = tempSock.recv_dict_msg() # RMB: WITH TIMEOUT ?? if not msg or not msg.has_key('cmd') or msg['cmd'] != 'challenge': mpd_print(1,'failed to handshake with mpd on %s; recvd output=%s' % \ (host,msg) ) tempOut = tempSock.recv(1000) print tempOut try: getoutput('%s/mpdallexit.py' % (fullDirName)) except: pass exit(-1) tempSock.close() else: mpd_print(1,'failed to connect to mpd on %s' % (host) ) try: getoutput('%s/mpdallexit.py' % (fullDirName)) except: pass exit(-1) else: mpd_print(1,'from mpd on %s, invalid port info:' % (host) ) print port print fd.read() try: getoutput('%s/mpdallexit.py' % (fullDirName)) except: pass exit(-1) if verbose: print "RUNNING: mpd on", hostsAndInfo[fd2idx[fd]]['host'] if debug: print "debug: info for running mpd:", hostsAndInfo[fd2idx[fd]]