Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_show_option_unknown(session):
"""Session.show_option raises UnknownOption for invalid option."""
with pytest.raises(exc.UnknownOption):
session.show_option('moooz')
def test_show_window_option_ambiguous(session):
"""show_window_option raises AmbiguousOption for ambiguous option."""
window = session.new_window(window_name='test_window')
with pytest.raises(exc.AmbiguousOption):
window.show_window_option('clock-mode')
version appended with -master, e.g. ``2.4-master``.
If using OpenBSD's base system tmux, the version will have ``-openbsd``
appended to the latest version, e.g. ``2.4-openbsd``.
Returns
-------
:class:`distutils.version.LooseVersion`
tmux version according to :func:`libtmux.common.which`'s tmux
"""
proc = tmux_cmd('-V')
if proc.stderr:
if proc.stderr[0] == 'tmux: unknown option -- V':
if sys.platform.startswith("openbsd"): # openbsd has no tmux -V
return LooseVersion('%s-openbsd' % TMUX_MAX_VERSION)
raise exc.LibTmuxException(
'libtmux supports tmux %s and greater. This system'
' is running tmux 1.3 or earlier.' % TMUX_MIN_VERSION
)
raise exc.VersionTooLow(proc.stderr)
version = proc.stdout[0].split('tmux ')[1]
# Allow latest tmux HEAD
if version == 'master':
return LooseVersion('%s-master' % TMUX_MAX_VERSION)
version = re.sub(r'[a-z-]', '', version)
return LooseVersion(version)
: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]
# clear up empty dict
sessions = [
dict((k, v) for k, v in session.items() if v) for session in sessions
]
return sessions
def get_session(server, session_name):
# Get session
try:
session = server.new_session(session_name=session_name)
except libtmux.exc.TmuxSessionExists as e:
with Colorblock(Fore.RED):
print("\nDon't support append window in existing session! Please change your session name.")
sys.exit(1)
return session
:type exe: string
:rtype: string
"""
if exe:
if os.access(exe, os.X_OK):
return exe
# default path based on busybox's default
search_path = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
for path in search_path.split(os.pathsep):
full_path = os.path.join(path, exe)
if os.access(full_path, os.X_OK):
return full_path
raise exc.LibTmuxException(
'{0!r} could not be found in the following search '
'path: {1!r}'.format(
exe, search_path
)
)
logger.error('No executable was passed to be searched by which')
return None
def kill_session(self):
"""``$ tmux kill-session``."""
proc = self.cmd('kill-session', '-t%s' % self.id)
if proc.stderr:
raise exc.LibTmuxException(proc.stderr)
All errors raised will have the base error of :exc:`exc.OptionError`. So to
catch any option error, use ``except exc.OptionError``.
Parameters
----------
error : str
Error response from subprocess call.
Raises
------
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`, :exc:`exc.InvalidOption`,
:exc:`exc.AmbiguousOption`
"""
if 'unknown option' in error:
raise exc.UnknownOption(error)
elif 'invalid option' in error:
raise exc.InvalidOption(error)
elif 'ambiguous option' in error:
raise exc.AmbiguousOption(error)
else:
raise exc.OptionError(error) # Raise generic option error
def get_slash_tmux_session(session_name):
try:
tmux_server = libtmux.Server()
return tmux_server.find_where({"session_name":session_name})
except libtmux.exc.LibTmuxException:
_logger.debug('No tmux server is running')
return