当前位置: 首页>>代码示例>>Python>>正文


Python GNUScreen类代码示例

本文整理汇总了Python中GNUScreen的典型用法代码示例。如果您正苦于以下问题:Python GNUScreen类的具体用法?Python GNUScreen怎么用?Python GNUScreen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GNUScreen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: dump

def dump(ss,minwin,maxwin):
    for win,type,title in sc.gen_all_windows(minwin,maxwin,ss.pid):
        if type==0:
            type_string="basic"
        elif type==1:
            type_string="group"
        elif type==-1:
            type_string="zombie"
        else:
            type_string="unknown"

        print("%s %s"%(win,type_string))
        print("%s %s"%(win,title))
        filter=ss.get_exec(win)
        if filter!=-1:
            print("%s %s"%(win,filter))
        tty=ss.tty(win)
        print("%s %s"%(win,tty))
        if type==0:
            try:
                pids=sc.get_tty_pids(tty)
            except:
                print ("%s No access"%win)
                pass
            for pid in pids:
                try:
                    print ("%s %s %s"%(win,pid,sc.get_pid_info(pid)))
                except:
                    print ("%s No permission"%(win))
        print("\n")
开发者ID:testacc,项目名称:screen-session,代码行数:30,代码来源:tools.py

示例2: kill_current_group

def kill_current_group(ss,bKillHomeWindow=False,other_wins=[],homewindow=-1):
    if homewindow<0:
        cwin,ctitle=ss.get_number_and_title()
        homewindow=int(cwin)
    else:
        homewindow=int(homewindow)
    protected=tuple([(homewindow)]+other_wins)
    print (protected)
    cgroup=ss.get_group()
    print ('removing windows from group %s'%cgroup)
    while True:
        wins=sc.parse_windows(sc.get_windows(ss.pid))[0]
        print( wins)
        if len(wins)<=len(protected):
            break
        for w in wins:
            if w not in protected:
                print('removing %s'%w)
                ss.kill(w)
    for w in other_wins:
        ss.kill(w)
    for w in protected:
        if w != homewindow:
            print('removing protected %s'%w)
            ss.kill(w)
    if bKillHomeWindow:
        print('removing homewindow %s'%homewindow)
        ss.kill(homewindow)
开发者ID:testacc,项目名称:screen-session,代码行数:28,代码来源:tools.py

示例3: find_pids_in_windows

def find_pids_in_windows(session, datadir, pids):
    import getpass
    import os
    tty_and_pids = sc._get_tty_pids_ps_with_cache_gen(getpass.getuser())

    #print(tty_and_pids)

    ttys = []
    for (tty, tpids) in tty_and_pids.items():

        #print('%s %s %s'%(pids,tty,tpids))

        for pid in pids:
            if pid in tpids:
                ttys.append(tty)
    wins = []
    for (cwin, cgroupid, ctype, ctty, ctitle) in sc.gen_all_windows_fast(session,
            datadir):
        try:
            ctty = int(os.path.split(ctty)[1])
            if ctty in ttys:
                wins.append(tuple([cwin, ctitle]))
        except Exception:
            pass
    return wins
开发者ID:chronidev,项目名称:screen-session,代码行数:25,代码来源:tools.py

示例4: load

    def load(self):
        if "all" in self.force_start:
            self.primer_arg += "S"
            self.force_start = []
        if "all" in self.scroll:
            self._scrollfile = None
        out('session "%s" loading "%s"' % (self.pid, os.path.join(self.basedir, self.savedir)))

        # check if the saved session exists and get the biggest saved window number and a number of saved windows

        maxnewwindow = 0
        newwindows = 0
        try:
            winlist = list(glob.glob(os.path.join(self.basedir, self.savedir, "win_*")))
            newwindows = len(winlist)
            out("%d new windows" % newwindows)
        except Exception:
            sys.stderr.write("Unable to open winlist.\n")
            return 1

        # keep original numbering, move existing windows

        self.homewindow = self.number()

        if self.exact:
            maxnewwindow = -1
            for w in winlist:
                try:
                    w = int(w.rsplit("_", 1)[1])
                    if w > maxnewwindow:
                        maxnewwindow = w
                except:
                    pass

            out("Biggest new window number: %d" % maxnewwindow)
            if self.enable_layout:
                self.__remove_all_layouts()
            self.__move_all_windows(maxnewwindow + 1, self.group_other, False)

        out("\nLoading windows:")
        self.__load_screen()

        if self.enable_layout:
            out("\nLoading layouts:")
            try:
                self.__load_layouts()
            except:
                sys.stderr.write("Layouts loading failed!\n")
                # raise

        self.__restore_mru()
        sc.cleanup()

        return 0
开发者ID:rlabok,项目名称:screen-session,代码行数:54,代码来源:ScreenSaver.py

示例5: kill_win_last_proc

def kill_win_last_proc(session,win="-1",sig="TERM"):
    import signal,os,platform
    ss=ScreenSaver(session,'/dev/null','/dev/null')
    ctty=ss.tty(win)
    if platform.system() == 'FreeBSD':
        pids=sc.get_tty_pids(ctty)
    else:
        pids=sc._get_tty_pids_pgrep(ctty)
    pid = pids[-1]

    sig=eval('signal.SIG'+sig)
    os.kill(int(pid),sig)
开发者ID:brendoncrawford,项目名称:screen-session,代码行数:12,代码来源:tools.py

示例6: kill_group

def kill_group(session,win):
    print ('killing group %s'%win)
    ss=ScreenSaver(session,'/dev/null','/dev/null')
    tty=ss.tty(win)
    if tty!="telnet":
        print('This window is not a group. Aborting.')
        return
    ss.select(win)
    wins=sc.parse_windows(sc.get_windows(session))[0]
    print wins
    for w in wins:
       print('killing %s'%w)
开发者ID:testacc,项目名称:screen-session,代码行数:12,代码来源:tools.py

示例7: prime

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
开发者ID:testacc,项目名称:screen-session,代码行数:12,代码来源:manager.py

示例8: prime

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
开发者ID:chronidev,项目名称:screen-session,代码行数:14,代码来源:manager.py

示例9: dump

def dump(ss,showpid=True,reverse=True,sort=False,groupids=[]):
    from sys import stdout
    bShow=True
    windows=[]
    if groupids:
        windows=subwindows(ss.pid,groupids)[1]
    for cwin,cgroupid,cgroup,ctty,ctype,ctypestr,ctitle,cfilter,cscroll,ctime in sc.gen_all_windows_full(ss.pid,reverse,sort):
        if groupids:
            if cwin in windows:
                bShow=True
            else:
                bShow=False
        if bShow:
            print("----------------------------------------")
            lines=[]
            lines.append("%s TYPE  %s\n"%(cwin,ctypestr))
            if cgroupid=='-1':
                groupstr='-1'
            else:
                groupstr=cgroupid+' '+cgroup
            lines.append("%s GRP   %s\n"%(cwin,groupstr))
            lines.append("%s TITL  %s\n"%(cwin,ctitle))
            if cfilter!='-1':
                lines.append("%s EXEC  %s\n"%(cwin,cfilter))
            if ctype==0:
                lines.append("%s TTY   %s\n"%(cwin,ctty))
                if showpid:
                    try:
                        pids=sc.get_tty_pids(ctty)
                    except:
                        lines.append ("%s No access\n"%cwin)
                        pass
                    for pid in pids:
                        try:
                            cwd,exe,cmd=sc.get_pid_info(pid)
                            lines.append ("%s PID   %s CWD %s\n"%(cwin,pid,cwd))
                            lines.append ("%s PID   %s EXE %s\n"%(cwin,pid,exe))
                            cmd=cmd.split('\0')[:-1]
                            lines.append ("%s PID   %s CMD %s\n"%(cwin,pid,cmd))
                            try:
                                if cmd[0].endswith('screen-session-primer') and cmd[1]=='-p':
                                    lines[0]=lines[0][:-1]+" / primer\n"
                                elif cmd[0] in ('vi','vim','viless','vimdiff'): 
                                    lines[0]=lines[0][:-1]+" / VIM\n"
                            except:
                                pass
                        except:
                            lines.append ("%s PID > %s < No permission\n"%(cwin,pid))
            map(stdout.write,lines)
开发者ID:brendoncrawford,项目名称:screen-session,代码行数:49,代码来源:tools.py

示例10: sort

def sort(session,min,max,key=None):
    ss=ScreenSaver(session,'/dev/null','/dev/null')
    wins=[]
    wins_trans={}
    groups={}
    cgroup=None
    for win,type,title in sc.gen_all_windows(min,max,session):
        iwin=int(win)
        group=ss.get_group(win)

        lastval=(group,iwin,type,title)
        try:
            groups[group].append(lastval)
        except:
            groups[group]=[lastval]
            
    win_biggest=lastval[1]
    for i in range(0,win_biggest+1):
        wins_trans[i]=i

    i=0
    for group,props in groups.items():
        props.sort(key=lambda wins:wins[3].lower())
        #print( str(len(props))+' : '+group + ' : ' + str(props))
        for group,win,type,title in props:
            if wins_trans[win]!=i:
                #print("win %d(%d)(%s) as %d"%(wins_trans[win],win,group,i))
                ss.number(str(i),str(wins_trans[win]))
                tmp=wins_trans[win]
                wins_trans[win]=wins_trans[i]
                wins_trans[i]=tmp
            i+=1
    return
开发者ID:testacc,项目名称:screen-session,代码行数:33,代码来源:tools.py

示例11: __move_all_windows

    def __move_all_windows(self,shift,group,kill=False):
        homewindow=int(self.homewindow)
        # create wrap group for existing windows
        if not self.bNoGroupWrap:
            self.screen('-t \"%s\" //group' % ('%s_%s'%(group,self.__unique_ident)) )
            self.group(False,self.none_group)
            self.wrap_group_id=self.number()

        # move windows by shift and put them in a wrap group
        #for cwin,cgroupid,ctype,ctty in sc.gen_all_windows_fast(self.pid):
        for cwin,cgroupid,cgroup,ctty,ctype,ctypestr,ctitle,cfilter,cscroll,ctime in sc.gen_all_windows_full(self.pid):
            iwin=int(cwin)
            if iwin==homewindow:
                homewindow=iwin+shift
                self.homewindow=str(homewindow)
            
            cgroupid,cgroup = self.get_group(cwin)
            if not self.bNoGroupWrap and cgroup==self.none_group:
                self.select(self.wrap_group_id)
                self.group(False,group,str(cwin))
            command='%s -p %s -X number +%d' % (self.sc,cwin,shift)
            if not self.bNoGroupWrap and str(cwin)==str(self.wrap_group_id):
                out('Moving wrap group %s to %d'%(cwin,iwin+shift))
                self.wrap_group_id=str(iwin+shift)
            else:
                out('Moving window %s to %d'%(cwin,iwin+shift))
            os.system(command)
        self.select('%d'%(homewindow))
开发者ID:brendoncrawford,项目名称:screen-session,代码行数:28,代码来源:ScreenSaver.py

示例12: cleanup

def cleanup():
    cmd = ''
    f = open(sourcefile, 'w')
    for (i, w) in enumerate(win_history):
        if w == "-1":
            w = "-"
        f.write("""select %s
at \"%s\#\" kill
focus
""" % (w, wins[i]))
    f.flush()
    f.close()
    scs.source(sourcefile)
    scs.focusminsize(focusminsize)
    sc.cleanup()
    remove(sourcefile)
开发者ID:chronidev,项目名称:screen-session,代码行数:16,代码来源:regions.py

示例13: renumber

def renumber(session, datadir):
    ss = ScreenSaver(session, '/dev/null', '/dev/null')
    wins = []
    wins_trans = {}
    for (cwin, cgroupid, ctype, ctty, ctitle) in sc.gen_all_windows_fast(session,
            datadir):
        iwin = int(cwin)
        wins.append((iwin, cgroupid, ctype))
        wins_trans[iwin] = iwin

    wins.sort(key=lambda wins: wins[0])
    print wins_trans
    i = 0
    for (win, groupid, ctype) in wins:
        if wins_trans[win] != i:

            #print("win %d(%d)(%s) as %d"%(wins_trans[win],win,group,i))

            ss.number(str(i), str(wins_trans[win]))
            tmp = wins_trans[win]
            try:
                wins_trans[win] = wins_trans[i]
            except:
                wins_trans[win] = -1
            wins_trans[i] = tmp
        i += 1
    print wins_trans
开发者ID:chronidev,项目名称:screen-session,代码行数:27,代码来源:tools.py

示例14: main

def main():
    logfile="___log-nest-layout"
    dumpfile="___scs-nest-layout-dump-%d"%os.getpid()
    if not os.path.exists(tmpdir):
        os.makedirs(tmpdir)
    logfile=os.path.join(tmpdir,logfile)
    dumpfile=os.path.join(tmpdir,dumpfile)
    sys.stdout=open(logfile,'w')
    sys.stderr=sys.stdout
    session=sys.argv[1]
    tlayout=sys.argv[2]

    scs=ScreenSaver(session)
    homelayout,homelayoutname=scs.get_layout_number()
    while True:
        regions=sc.get_regions(scs.pid)
        try:
            focusminsize="%s %s"%(regions[3][0], regions[3][1])
            regions_c=regions[0]
            foff=regions[1]
            rsize=tuple([int(regions[4+foff][1]),int(regions[4+foff][2])])
            hsize=int(regions[2][0]),int(regions[2][1])
            if regions[4][0]:
                break
        except Exception,x:
            print(x)
            sys.exit(2)
            pass
开发者ID:brendoncrawford,项目名称:screen-session,代码行数:28,代码来源:nest_layout.py

示例15: subwindows

def subwindows(session, datadir, groupids):
    ss = ScreenSaver(session)
    bAll = False
    try:
        if groupids[0] in ('cg', 'current', '..'):
            groupids[0] = ss.get_group()[0]
            if groupids[0] == "-1":
                bAll = True
        elif groupids[0] in ('cw', 'current-window', '.'):
            groupids[0] = ss.get_number_and_title()[0]
        elif groupids[0] == 'all':
            bAll = True
    except IndexError:
        bAll = True
    group_wins = {}
    group_groups = {}
    excluded_wins = []
    excluded_groups = []
    for (cwin, cgroupid, ctype, ctty, ctitle) in sc.gen_all_windows_fast(session,
            datadir):
        if ctype == 1:  # group
            if cwin in groupids or bAll or ctitle in groupids:
                excluded_groups.append(cwin)
            try:
                group_groups[cgroupid] += [cwin]
            except:
                group_groups[cgroupid] = [cwin]
        else:

              # anything other than group

            if cwin in groupids or bAll or ctitle in groupids:
                excluded_wins.append(cwin)
            else:
                try:
                    group_wins[cgroupid] += [cwin]
                except:
                    group_wins[cgroupid] = [cwin]
    excluded_groups_tmp = []
    while excluded_groups:
        egroup = excluded_groups.pop()
        if egroup not in excluded_groups_tmp:
            excluded_groups_tmp.append(egroup)
        try:
            ngroups = group_groups[egroup]
            if ngroups:
                for g in ngroups:
                    excluded_groups.append(g)
        except:
            pass
    excluded_groups = excluded_groups_tmp
    for egroup in excluded_groups:
        excluded_wins.append(egroup)
        try:
            for w in group_wins[egroup]:
                excluded_wins.append(w)
        except:
            pass
    return (excluded_groups, excluded_wins)
开发者ID:chronidev,项目名称:screen-session,代码行数:59,代码来源:tools.py


注:本文中的GNUScreen类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。