def exec_trans(em,history,key='enter'): request = tn3270.Screen response = tn3270.Screen check = tn3270.Screen request = update_screen(em,request) keypress = '' hostinfo = em.exec_command('Query(Host)').data[0].split(' ') host = hostinfo[1]+':'+hostinfo[2] data = request.modified_fields if key == 'enter': em.send_enter() keypress = key # PF1=1, PF24=24, PA1=25, PA3=27 elif key > 0 and key < 25: keypress = 'PF(' + str(key) + ')' em.exec_command(keypress) elif key > 25 and key < 28: keypress = 'PA(' + str(key - 24) + ')' em.exec_command(keypress) response = update_screen(em,response) trans = tn3270.Transaction(request,response,data,keypress,host) history.append(trans) return trans
def interactive(em,history): if not em.is_connected(): logger(Fore.RED+"Emulator not connected, interactive mode prevented."+Fore.RESET,kind="err") return key = '' trans = '' screen = '' data = '' logger("Interactive mode started! Hit ESC to exit",kind="info") logger("Hit Ctrl-h for help. Start typing ...",kind="info") while key != getch.KEY_ESC: key = getch() if key == getch.KEY_UP: # Up em.exec_command('Up()') elif key == getch.KEY_DOWN: # Down em.exec_command('Down()') elif key == getch.KEY_LEFT: # Left em.exec_command('Left()') elif key == getch.KEY_RIGHT: # Right em.exec_command('Right()') elif key == getch.KEY_ENTER: # Enter trans = exec_trans(em,history,'enter') print trans.response.colorbuffer logger('Enter entered',kind='info') elif key == getch.KEY_CTRLr: # Ctrl-r print screen screen = update_screen(em,screen) print screen.colorbuffer logger('Screen refreshed',kind='info') elif key == getch.KEY_CTRLu: # Ctrl-u manually push transaction screen = update_screen(em,screen) data = screen.modified_fields hostinfo = em.exec_command('Query(Host)').data[0].split(' ') host = hostinfo[1]+':'+hostinfo[2] trans = tn3270.Transaction(history.last().response,screen,data,'manual',host) history.append(trans) print screen.colorbuffer logger('Transaction added',kind='info') elif key == getch.KEY_CTRLh: # Ctrl-h help print interactive_help elif key == getch.KEY_CTRLk: # Ctrl-k color key print color_key elif key == getch.KEY_CTRLp: # Ctrl-p python shell embed() elif key == getch.KEY_CTRLs: # Ctrl-s screenshot em.save_screen(str(trans.timestamp.date())+'_'+str(trans.timestamp.time())+'.html') logger('Screenshot saved',kind='info') elif key == getch.KEY_TAB: # Tab 9 em.exec_command('Tab()') elif key == getch.KEY_BACKSPACE: # Backspace em.exec_command('BackSpace()') elif key == getch.KEY_DELETE: # Delete em.exec_command('Delete()') elif key == getch.KEY_CTRLc: # Ctrl-c Clear em.exec_command('Clear()') elif key == getch.KEY_CTRLq: # Ctrl-q PA1 trans = exec_trans(em,history,25) print trans.response.colorbuffer elif key == getch.KEY_CTRLw: # Ctrl-w PA2 trans = exec_trans(em,history,26) print trans.response.colorbuffer elif key == getch.KEY_CTRLe: # Ctrl-e PA3 trans = exec_trans(em,history,27) print trans.response.colorbuffer elif key > 31 and key < 127: # Alphanumeric em.safe_send(chr(key)) elif key == getch.KEY_F1: trans = exec_trans(em,history,1) print trans.response.colorbuffer elif key == getch.KEY_F2: trans = exec_trans(em,history,2) print trans.response.colorbuffer elif key == getch.KEY_F3: trans = exec_trans(em,history,3) print trans.response.colorbuffer elif key == getch.KEY_F4: trans = exec_trans(em,history,4) print trans.response.colorbuffer elif key == getch.KEY_F5: trans = exec_trans(em,history,5) print trans.response.colorbuffer elif key == getch.KEY_F6: trans = exec_trans(em,history,6) print trans.response.colorbuffer elif key == getch.KEY_F7: trans = exec_trans(em,history,7) print trans.response.colorbuffer elif key == getch.KEY_F8: trans = exec_trans(em,history,8) print trans.response.colorbuffer elif key == getch.KEY_F9: trans = exec_trans(em,history,9) print trans.response.colorbuffer elif key == getch.KEY_F10: trans = exec_trans(em,history,10) print trans.response.colorbuffer elif key == getch.KEY_F11: trans = exec_trans(em,history,11) print trans.response.colorbuffer elif key == getch.KEY_F12: trans = exec_trans(em,history,12) print trans.response.colorbuffer elif key == getch.KEY_AltF8: trans = exec_trans(em,history,13) print trans.response.colorbuffer elif key == getch.KEY_AltF9: trans = exec_trans(em,history,14) print trans.response.colorbuffer elif key == getch.KEY_AltF10: trans = exec_trans(em,history,15) print trans.response.colorbuffer elif key == getch.KEY_AltF11: trans = exec_trans(em,history,16) print trans.response.colorbuffer elif key == getch.KEY_AltF12: trans = exec_trans(em,history,24) print trans.response.colorbuffer