Skip to content

Commit 5fd998b

Browse files
committed
pep247. pep8, docs
1 parent 7ff4e31 commit 5fd998b

File tree

2 files changed

+63
-41
lines changed

2 files changed

+63
-41
lines changed

tmuxp/pane.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def tmux(self, cmd, *args, **kwargs):
6565
Specifying ``('-t', 'custom-target')`` or ``('-tcustom_target')`` in
6666
``args`` will override using the object's ``pane_id`` as target.
6767
68+
:rtype: :class:`util.tmux`
69+
6870
"""
6971
if not len([arg for arg in args if '-t' in arg]):
7072
args = ('-t', self.get('pane_id')) + args

tmuxp/server.py

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
import os
1616
from .util import tmux, TmuxRelationalObject
1717
from .session import Session
18-
from . import formats
18+
from . import formats, exc
1919
import logging
2020

2121
logger = logging.getLogger(__name__)
2222

2323

2424
class Server(TmuxRelationalObject):
2525

26-
'''
27-
The :term:`tmux(1)` server. Container for:
26+
"""The :term:`tmux(1)` server.
2827
2928
- :attr:`Server._sessions` [:class:`Session`, ...]
3029
@@ -36,7 +35,8 @@ class Server(TmuxRelationalObject):
3635
3736
When instantiated, provides the ``t`` global. stores information on live,
3837
running tmux server.
39-
'''
38+
39+
"""
4040

4141
#: socket name
4242
socket_name = None
@@ -69,6 +69,12 @@ def __init__(
6969
self.colors = colors
7070

7171
def tmux(self, *args, **kwargs):
72+
"""Send command to tmux with :attr:`pane_id` as ``target-pane``.
73+
74+
:rtype: :class:`util.tmux`
75+
76+
"""
77+
7278
args = list(args)
7379
if self.socket_name:
7480
args.insert(0, '-L{}'.format(self.socket_name))
@@ -87,11 +93,14 @@ def tmux(self, *args, **kwargs):
8793
return tmux(*args, **kwargs)
8894

8995
def __list_sessions(self):
90-
'''
91-
compatibility wrapping for ``$ tmux list-sessions``.
96+
"""Return list of ``$ tmux(1) list-sessions`` stdout.
9297
93-
:rtype: stdout or stderr of tmux proc
94-
'''
98+
The :py:obj:`list` is derived from ``stdout`` in :class:`util.tmux`
99+
which wraps :py:meth:`Subprocess.Popen`.
100+
101+
:rtype: list
102+
103+
"""
95104
sformats = formats.SESSION_FORMATS
96105
tmux_formats = ['#{%s}' % f for f in sformats]
97106

@@ -166,8 +175,8 @@ def sessions(self):
166175
def __list_windows(self):
167176
"""Return list of ``$ tmux(1) list-windows`` stdout.
168177
169-
The :py:obj:`list` is derived from :class:`util.tmux` which wraps
170-
:py:meth:`Subprocess.Popen`.
178+
The :py:obj:`list` is derived from ``stdout`` in :class:`util.tmux`
179+
which wraps :py:meth:`Subprocess.Popen`.
171180
172181
:rtype: list
173182
@@ -217,15 +226,20 @@ def _list_windows(self):
217226
return self._windows
218227

219228
def _update_windows(self):
220-
"""Update internal window data and return ``self`` for chainability."""
229+
"""Update internal window data and return ``self`` for chainability.
230+
231+
:rtype: :class:`Server`
232+
233+
"""
221234
self._list_windows()
222235
return self
223236

224237
def __list_panes(self):
225238
"""Return list of ``$ tmux(1) list-panes`` stdout.
226239
227-
The :py:obj:`list` is derived from :class:`util.tmux` which wraps
228-
:py:meth:`Subprocess.Popen`.
240+
The :py:obj:`list` is derived from ``stdout`` in :class:`util.tmux`
241+
which wraps :py:meth:`Subprocess.Popen`.
242+
229243
230244
:rtype: list
231245
@@ -272,15 +286,22 @@ def _list_panes(self):
272286
return self._panes
273287

274288
def _update_panes(self):
289+
"""Update internal pane data and return ``self`` for chainability.
290+
291+
:rtype: :class:`Server`
292+
293+
"""
275294
self._list_panes()
276295
return self
277296

278297
def attached_sessions(self):
279-
'''
280-
Returns active :class:`Session` object
298+
"""Return active :class:`Session` object.
281299
282-
This will not work where multiple tmux sessions are attached.
283-
'''
300+
This will not work where multiple tmux sessions are attached.
301+
302+
:rtype: :class:`Server`
303+
304+
"""
284305

285306
sessions = self._sessions
286307
attached_sessions = list()
@@ -298,13 +319,12 @@ def attached_sessions(self):
298319
return attached_sessions or None
299320

300321
def has_session(self, target_session):
301-
'''
302-
``$ tmux has-session``
322+
"""Return True if session exists. ``$ tmux has-session``.
303323
304324
:param: target_session: str of session name.
325+
:rtype: bool
305326
306-
returns True if session exists.
307-
'''
327+
"""
308328

309329
proc = self.tmux('has-session', '-t%s' % target_session)
310330

@@ -316,18 +336,18 @@ def has_session(self, target_session):
316336
return True
317337

318338
def kill_server(self):
319-
'''
320-
``$ tmux kill-server``
321-
'''
339+
"""``$ tmux kill-server``."""
322340
self.tmux('kill-server')
323341

324342
def kill_session(self, target_session=None):
325-
'''
326-
``$ tmux kill-session``
343+
"""Kill the tmux session with ``$ tmux kill-session``.
327344
328-
:param: target_session: str. note this accepts fnmatch(3). 'asdf' will
329-
kill asdfasd
330-
'''
345+
:param: target_session: str. note this accepts ``fnmatch(3)``. 'asdf'
346+
will kill 'asdfasd'.
347+
348+
:rtype: :class:`Server`
349+
350+
"""
331351
proc = self.tmux('kill-session', '-t%s' % target_session)
332352

333353
if proc.stderr:
@@ -336,23 +356,24 @@ def kill_session(self, target_session=None):
336356
return self
337357

338358
def switch_client(self, target_session):
339-
'''
340-
``$ tmux switch-client``
359+
"""``$ tmux switch-client``.
341360
342361
:param: target_session: str. name of the session. fnmatch(3) works.
343-
'''
362+
363+
"""
364+
344365
# tmux('switch-client', '-t', target_session)
345366
proc = self.tmux('switch-client', '-t%s' % target_session)
346367

347368
if proc.stderr:
348369
raise Exception(proc.stderr)
349370

350371
def attach_session(self, target_session=None):
351-
'''
352-
``$ tmux attach-session`` aka alias: ``$ tmux attach``
372+
"""``$ tmux attach-session`` aka alias: ``$ tmux attach``.
353373
354374
:param: target_session: str. name of the session. fnmatch(3) works.
355-
'''
375+
376+
"""
356377
# tmux('switch-client', '-t', target_session)
357378
tmux_args = tuple()
358379
if target_session:
@@ -369,10 +390,7 @@ def new_session(self,
369390
attach=False,
370391
*args,
371392
**kwargs):
372-
'''
373-
``$ tmux new-session``
374-
375-
Returns :class:`Session`
393+
"""Return :class:`Session` from ``$ tmux new-session``.
376394
377395
Uses ``-P`` flag to print session info, ``-F`` for return formatting
378396
returns new Session object.
@@ -399,14 +417,16 @@ def new_session(self,
399417
:param kill_session: Kill current session if ``$ tmux has-session``
400418
Useful for testing workspaces.
401419
:type kill_session: bool
402-
'''
420+
:rtype: :class:`Session`
421+
422+
"""
403423

404424
if self.has_session(session_name):
405425
if kill_session:
406426
self.tmux('kill-session', '-t%s' % session_name)
407427
logger.info('session %s exists. killed it.' % session_name)
408428
else:
409-
raise TmuxSessionExists(
429+
raise exc.TmuxSessionExists(
410430
'Session named %s exists' % session_name
411431
)
412432

0 commit comments

Comments
 (0)