Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'-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 ()
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
'-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
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
]
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
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