Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
def kill_zombie(session,groupids=[]):
    ss=ScreenSaver(session,'/dev/null','/dev/null')
    if groupids:
        windows=subwindows(session,groupids)[1]
    for cwin,cgroupid,ctype,ctty,ctitle in sc.gen_all_windows_fast(session):
        if ctype==-1:
            if groupids:
                if cwin in windows:
                    ss.kill(cwin)
            else:
                ss.kill(cwin)
Esempio n. 8
0
def kill_zombie(session, datadir, groupids=[]):
    ss = ScreenSaver(session, '/dev/null', '/dev/null')
    if groupids:
        windows = subwindows(session, datadir, groupids)[1]
    for (cwin, cgroupid, ctype, ctty,
         ctitle) in sc.gen_all_windows_fast(session, datadir):
        if ctype == -1:
            if groupids:
                if cwin in windows:
                    ss.kill(cwin)
            else:
                ss.kill(cwin)
Esempio n. 9
0
def subwindows(session,groupids,datafile=None):
    ss=ScreenSaver(session)
    bAll=False
    if groupids[0] in ('cg','current'):
        groupids[0]=ss.get_group()[0]
    elif groupids[0] in ('cw','current-window'):
        groupids[0]=ss.get_number_and_title()[0]
    elif groupids[0]=='all':
        bAll=True
    group_wins={}
    group_groups={}
    excluded_wins=[]
    excluded_groups=[]
    #for cwin,cgroupid,cgroup,ctty,ctype,ctypestr,ctitle,cfilter,cscroll,ctime in sc.gen_all_windows_full(session):
    for cwin,cgroupid,ctype,ctty,ctitle in sc.gen_all_windows_fast(session,datafile):
        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 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
Esempio n. 10
0
def sort(session, datadir, key=None):
    ss = ScreenSaver(session, '/dev/null', '/dev/null')
    wins = []
    wins_trans = {}
    groups = {}
    cgroup = None
    for (cwin, cgroupid, ctype, ctty, ctitle) in sc.gen_all_windows_fast(session,
            datadir):
        iwin = int(cwin)
        lastval = (groupid, iwin, ctype, ss.title('', iwin))
        try:
            groups[groupid].append(lastval)
        except:
            groups[groupid] = [lastval]
        wins_trans[iwin] = iwin

    i = 0
    for (group, props) in groups.items():
        try:
            props.sort(key=lambda wins: wins[3].lower())
        except:
            print 'FAIL'
            print str(len(props)) + ' : ' + group + ' : ' + str(props)
            pass

        #print( str(len(props))+' : '+group + ' : ' + str(props))

        for (groupid, win, ctype, 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]
                try:
                    wins_trans[win] = wins_trans[i]
                except:
                    wins_trans[win] = -1
                wins_trans[i] = tmp
            i += 1
    return
Esempio n. 11
0
def sort(session, datadir, key=None):
    ss = ScreenSaver(session, '/dev/null', '/dev/null')
    wins = []
    wins_trans = {}
    groups = {}
    cgroup = None
    for (cwin, cgroupid, ctype, ctty,
         ctitle) in sc.gen_all_windows_fast(session, datadir):
        iwin = int(cwin)
        lastval = (groupid, iwin, ctype, ss.title('', iwin))
        try:
            groups[groupid].append(lastval)
        except:
            groups[groupid] = [lastval]
        wins_trans[iwin] = iwin

    i = 0
    for (group, props) in groups.items():
        try:
            props.sort(key=lambda wins: wins[3].lower())
        except:
            print 'FAIL'
            print str(len(props)) + ' : ' + group + ' : ' + str(props)
            pass

        #print( str(len(props))+' : '+group + ' : ' + str(props))

        for (groupid, win, ctype, 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]
                try:
                    wins_trans[win] = wins_trans[i]
                except:
                    wins_trans[win] = -1
                wins_trans[i] = tmp
            i += 1
    return
Esempio n. 12
0
def make_group_tabs(session,groupids,bAll=False):
    group_wins={}
    group_groups={}
    excluded_wins=[]
    excluded_groups=[]
    for cwin,cgroupid,ctype,ctty,ctitle in sc.gen_all_windows_fast(session):
        if(ctype==1): # group
            if cwin in groupids or bAll:
                excluded_groups.append(cwin)
            try:
                group_groups[cgroupid]+=[cwin]
            except:
                group_groups[cgroupid]=[cwin]
        else: # anything other than group
            if cwin in groupids:
                excluded_wins.append(cwin)
            else:
                try:
                    group_wins[cgroupid]+=[cwin]
                except:
                    group_wins[cgroupid]=[cwin]
    return group_groups,group_wins,excluded_groups,excluded_wins