Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _list_sessions(self):
"""
Return list of sessions in :py:obj:`dict` form.
Retrieved from ``$ tmux(1) list-sessions`` stdout.
The :py:obj:`list` is derived from ``stdout`` in
:class:`common.tmux_cmd` which wraps :py:class:`subprocess.Popen`.
Returns
-------
list of dict
"""
sformats = formats.SESSION_FORMATS
tmux_formats = ['#{%s}' % f for f in sformats]
tmux_args = ('-F%s' % '\t'.join(tmux_formats),) # output
proc = self.cmd('list-sessions', *tmux_args)
if proc.stderr:
raise exc.LibTmuxException(proc.stderr)
sformats = formats.SESSION_FORMATS
tmux_formats = ['#{%s}' % format for format in sformats]
sessions = proc.stdout
# combine format keys with values returned from ``tmux list-sessions``
sessions = [dict(zip(sformats, session.split('\t'))) for session in sessions]
Returns
-------
list of dict
"""
sformats = formats.SESSION_FORMATS
tmux_formats = ['#{%s}' % f for f in sformats]
tmux_args = ('-F%s' % '\t'.join(tmux_formats),) # output
proc = self.cmd('list-sessions', *tmux_args)
if proc.stderr:
raise exc.LibTmuxException(proc.stderr)
sformats = formats.SESSION_FORMATS
tmux_formats = ['#{%s}' % format for format in sformats]
sessions = proc.stdout
# combine format keys with values returned from ``tmux list-sessions``
sessions = [dict(zip(sformats, session.split('\t'))) for session in sessions]
# clear up empty dict
sessions = [
dict((k, v) for k, v in session.items() if v) for session in sessions
]
return sessions
wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS
tmux_formats = ['#{%s}' % format for format in wformats]
proc = self.cmd(
'list-windows', # ``tmux list-windows``
'-a',
'-F%s' % '\t'.join(tmux_formats), # output
)
if proc.stderr:
raise exc.LibTmuxException(proc.stderr)
windows = proc.stdout
wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS
# combine format keys with values returned from ``tmux list-windows``
windows = [dict(zip(wformats, window.split('\t'))) for window in windows]
# clear up empty dict
windows = [dict((k, v) for k, v in window.items() if v) for window in windows]
# tmux < 1.8 doesn't have window_id, use window_name
for w in windows:
if 'window_id' not in w:
w['window_id'] = w['window_name']
if self._windows:
self._windows[:] = []
self._windows.extend(windows)
:term:`tmux(1)` will move window to the new pane if the
``split-window`` target is off screen. tmux handles the ``-d`` the
same way as ``new-window`` and ``attach`` in
:class:`Session.new_window`.
By default, this will make the window the pane is created in
active. To remain on the same window and split the pane in another
target window, pass in ``attach=False``.
"""
pformats = [
'session_name',
'session_id',
'window_index',
'window_id',
] + formats.PANE_FORMATS
tmux_formats = ['#{%s}\t' % f for f in pformats]
# '-t%s' % self.attached_pane.get('pane_id'),
# 2013-10-18 LOOK AT THIS, rm'd it..
tmux_args = tuple()
if target:
tmux_args += ('-t%s' % target,)
else:
tmux_args += ('-t%s' % self.panes[0].get('pane_id'),)
if vertical:
tmux_args += ('-v',)
else:
tmux_args += ('-h',)
The :py:obj:`list` is derived from ``stdout`` in
:class:`util.tmux_cmd` which wraps :py:class:`subprocess.Popen`.
Returns
-------
list
"""
pformats = [
'session_name',
'session_id',
'window_index',
'window_id',
'window_name',
] + formats.PANE_FORMATS
tmux_formats = ['#{%s}\t' % f for f in pformats]
proc = self.cmd('list-panes', '-a', '-F%s' % ''.join(tmux_formats)) # output
if proc.stderr:
raise exc.LibTmuxException(proc.stderr)
panes = proc.stdout
pformats = [
'session_name',
'session_id',
'window_index',
'window_id',
'window_name',
] + formats.PANE_FORMATS
:param attach: make new window the current window after creating it,
default True.
:type attach: bool
:param start_directory: specifies the working directory in which the
new created.
:type start_directory: string
:param target: ``target_pane`` to split.
:type target: bool
:rtype: :class:`Pane`
"""
pformats = ['session_name', 'session_id',
'window_index', 'window_id'] + formats.PANE_FORMATS
tmux_formats = ['#{%s}\t' % f for f in pformats]
# '-t%s' % self.attached_pane().get('pane_id'),
# 2013-10-18 LOOK AT THIS, rm'd it..
tmux_args = tuple()
if target:
tmux_args += ('-t%s' % target,)
else:
tmux_args += ('-t%s' % self.panes[0].get('pane_id'),)
tmux_args += (
'-P', '-F%s' % ''.join(tmux_formats) # output
)
if start_directory:
create the new window at the given index position. Default is empty
string which will create the window in the next available position.
window_shell : str
execute a command on starting the window. The window will close
when the command exits.
.. note::
When this command exits the window will close. This feature is
useful for long-running processes where the closing of the
window upon completion is desired.
Returns
-------
:class:`Window`
"""
wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS
tmux_formats = ['#{%s}' % f for f in wformats]
window_args = tuple()
if not attach:
window_args += ('-d',)
window_args += ('-P',)
if start_directory:
# as of 2014-02-08 tmux 1.9-dev doesn't expand ~ in new-window -c.
start_directory = os.path.expanduser(start_directory)
window_args += ('-c%s' % start_directory,)
window_args += ('-F"%s"' % '\t'.join(tmux_formats),) # output
if window_name: