Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __enter__(self):
self.tmux_config = self.tempfile(self.tmux_config_contents())
self.bash_config = self.tempfile(self.bash_config_contents())
self.server = tmuxp.Server()
if self.use_existing_session:
try:
session_dict = self.server.attached_sessions() # until tmuxp bug is fixed
if session_dict is None:
raise tmuxp.exc.TmuxpException
self.session = tmuxp.Session(self.server, **session_dict[0])
except tmuxp.exc.TmuxpException:
self.session = self.server.new_session(session_name='rlundotesting')
else:
self.session = self.server.new_session(session_name='rlundotesting', kill_session=True)
self.window = self.session.new_window(attach=False)
try:
output = self.window.panes[0].cmd('respawn-pane', '-k', 'bash --rcfile %s --noprofile' % (self.bash_config.name, ))
if output.stderr:
raise ValueError(repr(output.stderr) + " " + repr(self.window.panes))
session = tmux.list_sessions()[0]
session.attach_session()
exit(1)
else:
session = tmux.new_session(session_name="iscap")
top_pane = session.attached_pane()
tmux.cmd('split-window')
new_pane = session.attached_pane()
new_pane.clear()
top_pane.select_pane()
top_pane.clear()
top_pane.send_keys('iscap')
session.attach_session()
exit(0)
tmux = tmuxp.Server();
return tmux
def setup_tmux():
if not 'TMUX' in os.environ:
tmux = tmuxp.Server();
if tmux.has_session('iscap'):
print ('error: iscap session already running. Try reattaching with `tmux attach`')
session = tmux.list_sessions()[0]
session.attach_session()
exit(1)
else:
session = tmux.new_session(session_name="iscap")
top_pane = session.attached_pane()
tmux.cmd('split-window')
new_pane = session.attached_pane()
new_pane.clear()
top_pane.select_pane()
top_pane.clear()
top_pane.send_keys('iscap')
session.attach_session()
exit(0)
import tmuxp
import pprint
server = tmuxp.Server()
def format_session(session):
pane_count = [w.panes for w in session.windows]
pane_count = [pane for window in pane_count for pane in window]
pane_count = len(pane_count)
return "({0}) {1} | {2} Windows, {3} Panes".format(
session.get("session_id"),
session.get("session_name"),
session.get("session_windows"),
pane_count)
def list_sessions():
sessions = server.list_sessions()
sessions = [format_session(s) for s in sessions]
return sessions
:todo: initialize :class:`Session` from here, in ``self.session``.
:param sconf: session config, includes a :py:obj:`list` of ``windows``.
:type sconf: :py:obj:`dict`
:param server:
:type server: :class:`Server`
"""
if not sconf:
raise exc.EmptyConfigException('session configuration is empty.')
# config.validate_schema(sconf)
if isinstance(server, Server):
self.server = server
else:
self.server = None
self.sconf = sconf