Message145005
Cfrom class():
# see if we can connect to pcPart
try:
self.pcPart = telnetlib.Telnet(IP, PORT)
# clear the buffer
for i in range(10):
self.pcPart.write('\n')
r = self.pcPart.read_until('Prompt>', 1)
except socket.error, e:
logging.debug('socket.error: %d: %s' % (e.args[0], e.args[1]))
self.pcPart.close()
self.pcPart = None
from init():
def talk(self,cmd,ret):
"""talk to the device"""
read_chars = ""
while (read_chars == ""):
try:
read_chars=""
# get to the Prompt> prompt
# logging.debug('seeking prompt')
while (read_chars != 'Prompt>'):
self.pcPart.write("\n")
raw_data = self.pcPart.read_until('Prompt>', 1).split('\n')
# logging.debug('raw_data: %i %s' % (len(raw_data), raw_data))
read_chars = raw_data[2]
# logging.debug('read_chars: %s' % (read_chars))
# send the command
# logging.debug('found prompt')
cmdx = (('xyzzy:%s\n') % cmd)
self.pcPart.write(cmdx)
# logging.debug('command %s, %s' % (cmd, cmdx))
if (ret):
while ((len(raw_data) > 0) and ('{' not in read_chars)):
raw_data = self.pcPart.read_until('Prompt>', 1)
# logging.debug('raw_data: %i %s' % (len(raw_data), raw_data))
try:
read_chars = str(raw_data.split('\n\r')[1][1:-1])
except:
read_chars = ''
# logging.debug('read_chars: %s' % (read_chars))
else:
raw_data = self.pcPart.read_until('Prompt>', 1)
# logging.debug('ret read: %s' % (raw_data))
read_chars = '@'
return read_chars
except IndexError, e:
logging.debug('IndexError: %d: %s' % (e.args[0], e.args[1]))
traceback.print_exc(file=open(LOG_FILENAME, 'a'))
read_chars = '@'
time.sleep(1)
except (IOError, socket.error), e:
logging.debug('socket.error: %d: %s' % (e.args[0], e.args[1]))
traceback.print_exc(file=open(LOG_FILENAME, 'a'))
self.pcPart.close()
self.pcPart = None
logging.debug('reconnecting...')
self.pcPart = telnetlib.Telnet(IP, PORT)
# clear the buffer
for i in range(10):
self.pcPart.write('\n')
r = self.pcPart.read_until('Prompt>', 1)
read_chars = '@'
logging.debug('reconnected')
# clear the buffer
for i in range(2):
self.pcPart.write('\n')
r = self.pcPart.read_until('Prompt>', 1)
# logging.debug('Data Read: ' + read_chars)
return read_chars
called from:
DATA = self.talk('cmd', True)
logging.debug('talk: %s' % (DATA)) |
|
Date |
User |
Action |
Args |
2011-10-06 13:06:03 | xy.zzy | set | recipients:
+ xy.zzy, eric.smith |
2011-10-06 13:06:03 | xy.zzy | set | messageid: <1317906363.83.0.512535489156.issue13109@psf.upfronthosting.co.za> |
2011-10-06 13:06:03 | xy.zzy | link | issue13109 messages |
2011-10-06 13:06:02 | xy.zzy | create | |
|