How to use the tmuxp.session.Session function in tmuxp

To help you get started, we’ve selected a few tmuxp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tmux-python / tmuxp / tmuxp / server.py View on Github external
'-F%s' % '\t'.join(tmux_formats),   # output
        ).stdout

        # combine format keys with values returned from ``tmux list-windows``
        sessions = [dict(zip(
            formats, session.split('\t'))) for session in sessions]

        # clear up empty dict
        new_sessions = [
            dict((k, v) for k, v in session.iteritems() if v) for session in sessions
        ]

        if not self._sessions:
            for session in new_sessions:
                logger.debug('adding session_id %s' % (session['session_id']))
                new_session = Session(server=self, **session)
                self._sessions.append(new_session)
            return self._sessions

        new = {session['session_id']: session for session in new_sessions}
        old = {session.get(
            'session_id'): session for session in self._sessions}

        created = set(new.keys()) - set(old.keys()) or ()
        deleted = set(old.keys()) - set(new.keys()) or ()
        intersect = set(new.keys()).intersection(set(old.keys()))

        diff = {id: dict(set(new[id].items()) - set(old[id].items()))
                for id in intersect}

        intersect = set(k for k, v in diff.iteritems() if v) or ()
        diff = dict((k, v) for k, v in diff.iteritems() if v) or ()
github tmux-python / tmuxp / tmuxp / server.py View on Github external
if proc.stderr:
            raise exc.TmuxpException(proc.stderr)

        session = proc.stdout[0]

        if env:
            os.environ['TMUX'] = env

        # combine format keys with values returned from ``tmux list-windows``
        session = dict(zip(sformats, session.split('\t')))

        # clear up empty dict
        session = dict((k, v) for k, v in session.items() if v)

        session = Session(server=self, **session)

        return session
github tmux-python / tmuxp / tmuxp / server.py View on Github external
'-s', session_name,
            '-P', '-F%s' % '\t'.join(tmux_formats),   # output
        )

        session_info = session_info.stdout[0]

        if env:
            os.environ['TMUX'] = env

        # combine format keys with values returned from ``tmux list-windows``
        session_info = dict(zip(formats, session_info.split('\t')))

        # clear up empty dict
        session_info = dict((k, v) for k, v in session_info.iteritems() if v)

        session = Session(server=self, **session_info)

        # need to be able to get first windows
        session._windows = session.list_windows()

        self._sessions.append(session)

        logger.info('hihi ho? 365')

        return session
github tmux-python / tmuxp / tmuxp / server.py View on Github external
def list_sessions(self):
        """Return list of :class:`Session` from the ``tmux(1)`` session.

        :rtype: :py:obj:`list` of :class:`Session`

        """
        return [
            Session(server=self, **s) for s in self._sessions
        ]
github tmux-python / tmuxp / tmuxp / server.py View on Github external
sessions = self._sessions
        attached_sessions = list()

        for session in sessions:
            if 'session_attached' in session:
                # for now session_active is a unicode
                if session.get('session_attached') == '1':
                    logger.debug('session %s attached', session.get(
                        'session_name'))
                    attached_sessions.append(session)
                else:
                    continue

        return [
                   Session(server=self, **s) for s in attached_sessions
               ] or None
github tmux-python / tmuxp / tmuxp / server.py View on Github external
for s in self._sessions:
            # remove session objects if deleted or out of session
            if s.get('session_id') in deleted:
                logger.debug("removing %s" % s)
                self._sessions.remove(s)

            if s.get('session_id') in intersect and s.get('session_id') in diff:
                logger.debug('updating session_id %s session_name %s' % (
                    s.get('session_id'), s.get('session_name')))
                s.update(diff[s.get('session_id')])

        # create session objects for non-existant session_id's
        for session in [new[session_id] for session_id in created]:
            logger.debug('new session %s' % session['session_id'])
            new_session = Session(server=self, **session)
            self._sessions.append(new_session)

        return self._sessions