def prime(fifoname): l1=sc.get_session_list() cmd='screen -S "MANAGER_NOATTACH" -m -d -c /dev/null python %s %s %s'%(sys.argv[0],'ui',fifoname) sys.stderr.write(cmd+'\n') os.popen(cmd) l2=sc.get_session_list() sys.stderr.write('searching for target session..\n') session=sc.find_new_session(l1,l2) sys.stderr.write('target session = %s\n'%session) print ('session: %s'%session) return session
def prime(fifoname): l1 = sc.get_session_list() cmd = SCREEN + \ ' -S "GNU_SCREEN_SESSIONS_MANAGER" -m -d -c /dev/null "%s" "%s" "%s" "%s"' % \ (os.getenv('PYTHONBIN'), (sys.argv)[0], 'ui', fifoname) sys.stderr.write(cmd + "\n") os.popen(cmd) l2 = sc.get_session_list() sys.stderr.write('searching for target session..\n') session = sc.find_new_session(l1, l2) sys.stderr.write('target session = %s\n' % session) print 'session: %s' % session return session
def eval_command(scs,command,last_session,psession): command=command.split(' ',1) mode=command[0] if len(command)>1: args=[] for arg in command[1].split(' '): args.append(arg) else: args=[''] #print2ui('command: %s args: %s'%(command,str(args))) if mode.startswith('a'): # attach return tui_attach_session(scs,args[0],psession) if mode.startswith('d'): # deselect print2ui('LOGIC: deselecting' ) scs.focus('bottom') scs.select('-') scs.focus('top') return None,'\0' elif mode=='kill': if last_session: print2ui('LOGIC: killing session \"%s\"'%last_session) scs=ScreenSaver(last_session,'/dev/null','/dev/null') scs.quit() elif mode.startswith('q'): # quit print2ui('LOGIC: quiting...' ) return 'quit',None elif mode.startswith('h'): # help usage() elif mode.startswith('e'): # enter return 'enter',None elif mode=='restart': # restart print2ui('LOGIC: restarting') return 'restart',None elif mode.startswith('r'): # refresh print2ui('LOGIC: refreshing') elif mode.startswith('l'): # layout global tui print2ui('LOGIC: toggling layout') scs.focus('bottom') cnum=scs.get_number_and_title()[0] scs.focus('top') if tui!=maxtui: tui+=1 else: tui=1 reset_tui(scs) if int(cnum)>1: scs.focus('bottom') scs.select(cnum) scs.focus('top') elif mode.startswith('w'): # wipe print2ui('LOGIC: wiping out dead sessions') scs.wipe() elif mode.startswith('save'): # save if args[0]: arg_out='%s'%args[0] else: arg_out='%s'%last_session print2ui('LOGIC: saving session as %s'%arg_out) os.popen('screen-session save --force --log /dev/null --in \"%s\" --out \"%s\"'%(last_session,arg_out)) elif mode.startswith('s'): # screen if args and len(args[0])>0: arg=" ".join(["%s"%v for v in args]) else: arg=' ' cmd='screen -d -m %s'%arg print2ui('LOGIC: creating new session: [%s]'%(cmd.strip())) l1=sc.get_session_list() os.popen(cmd) l2=sc.get_session_list() newsession=sc.find_new_session(l1,l2) return tui_attach_session(scs,newsession,psession) elif mode.startswith('n'): # name if last_session: print2ui('LOGIC: renaming session to \"%s\"'%args[0]) if scs.sessionname() == last_session: scs_target=scs else: scs_target=ScreenSaver(last_session,'/dev/null','/dev/null') nsessionname=scs_target.sessionname(args[0]) print2ui('LOGIC: new sessionname is now [%s]'%nsessionname) scs.focus('bottom') cnum=scs.get_number_and_title()[0] if (psession and psession==last_session): psession=nsessionname print2ui('LOGIC: parent session is now [%s]'%nsessionname) elif nsessionname==scs.sessionname(): print2ui('LOGIC: THIS is session [%s]'%nsessionname) else: scs.screen('screen -x \"%s\"'%nsessionname) scs.title(nsessionname) if int(cnum)>1: #print2ui('LOGIC: killing window \"%s\"'%cnum) scs.kill(cnum) scs.focus('top') return None,nsessionname,psession else: print2ui('LOGIC: no such command')
def eval_command(scs, command, last_session, psession, fifoname2, ui_pid): global menu_tmp_last_selection global tui command = command.split(" ", 1) mode = command[0] if len(command) > 1: args = [] for arg in command[1].split(" "): args.append(arg) else: args = [""] #print2ui('pid: %d command: %s args: %s'%(ui_pid,command,str(args))) #print2ui('trying to send SIGINT to %s'% type(ui_pid)) #os.kill(ui_pid, signal.SIGINT) if mode.startswith('a'): # attach return tui_attach_session(scs, args[0], psession) if mode.startswith('d'): # deselect scs.focus('bottom') scs.select('-') scs.focus('top') return (None, '\0') elif mode == 'kill' or mode == 'K': if last_session: menu_tmp_last_selection = -1 print2ui('LOGIC: killing session \"%s\"' % last_session) scst = ScreenSaver(last_session) scst.quit() scs.focus('top') elif mode.startswith('p'): # print print2ui((" ").join(["%s" % v for v in args])) elif mode.startswith('q'): # quit print2ui('LOGIC: quiting...') return ("quit", '\0') elif mode.startswith('h') or mode == '?': # help scs.focus('bottom') cnum = scs.get_number_and_title()[0] if int(cnum) > 2: #print2ui('LOGIC: killing window \"%s\"'%cnum) scs.kill(cnum) #scs.command_at(False,'eval "select 2" "focus top"') scs.select('2') #scs.screen('sh -c "screen-session help manager | less"') scs.focus('top') elif mode.startswith('e'): # enter return ("enter", None) elif mode == 'restart': # restart print2ui('LOGIC: restarting') return ('restart', None) elif mode.startswith('f'): # focus top|bottom global tui_focus if tui_focus == 0: scs.focus('bottom') tui_focus = 1 print2ui('LOGIC: focus bottom') else: scs.focus('top') tui_focus = 0 print2ui('LOGIC: focus top') elif mode.startswith('r'): # refresh print2ui('LOGIC: refreshing') elif mode.startswith('l'): # layout print2ui('LOGIC: toggling layout') scs.focus('bottom') cnum = scs.get_number_and_title()[0] scs.focus('top') if tui != maxtui: tui += 1 else: tui = 1 reset_tui(scs) if int(cnum) > 1: scs.focus('bottom') scs.select(cnum) scs.focus('top') elif mode.startswith('L'): # layout print2ui('LOGIC: toggling layout') scs.focus('bottom') cnum = scs.get_number_and_title()[0] scs.focus('top') if tui != 1: tui -= 1 else: tui = maxtui reset_tui(scs) if int(cnum) > 1: scs.focus('bottom') scs.select(cnum) scs.focus('top') elif mode.startswith('w'): # wipe print2ui('LOGIC: wiping out dead sessions') menu_tmp_last_selection = -1 scs.wipe() elif mode.startswith('save') or mode == 'S': # save if args[0]: arg_out = "%s" % args[0] else: arg_out = "%s" % last_session print2ui('LOGIC: saving session as %s' % arg_out) os.system('screen-session save -S \"%s\" --force --log \"%s\" \"%s\" 1>&- 2>&-' % (last_session, fifoname2, arg_out)) elif mode.startswith('s'): # screen if args and len(args[0]) > 0: arg = (" ").join(["%s" % v for v in args]) else: arg = " " cmd = SCREEN + ' -d -m %s' % arg print2ui('LOGIC: creating a new session: [%s]' % cmd.strip()) l1 = sc.get_session_list() os.popen(cmd) l2 = sc.get_session_list() newsession = sc.find_new_session(l1, l2) menu_tmp_last_selection = newsession print2ui('LOGIC: "%s"' % menu_tmp_last_selection) return tui_attach_session(scs, newsession, psession) elif mode.startswith('n'): # name if last_session: print2ui('LOGIC: renaming session to \"%s\"' % args[0]) if scs.sessionname() == last_session: scs_target = scs else: scs_target = ScreenSaver(last_session, '/dev/null', '/dev/null') nsessionname = scs_target.sessionname(args[0]) print2ui('LOGIC: new sessionname is now [%s]' % nsessionname) scs.focus('bottom') cnum = scs.get_number_and_title()[0] if psession and psession == last_session: psession = nsessionname print2ui('LOGIC: parent session is now [%s]' % nsessionname) elif nsessionname == scs.sessionname(): print2ui('LOGIC: THIS is session [%s]' % nsessionname) else: scs.screen(SCREEN + ' -x \"%s\"' % nsessionname) scs.title(nsessionname) if int(cnum) > 1: #print2ui('LOGIC: killing window \"%s\"'%cnum) scs.kill(cnum) scs.focus('top') return (None, nsessionname, psession) elif mode == 'pid': return ('pid', int(args[0])) else: print2ui('LOGIC: no such command')