Skip to content

Commit 490662b

Browse files
committed
python 2.6: Create TmuxpException class since BaseException raises DeprecationWarning
1 parent a00a08d commit 490662b

File tree

11 files changed

+58
-47
lines changed

11 files changed

+58
-47
lines changed

doc/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Workspace Builder
113113
Exceptions
114114
----------
115115

116+
.. autoexception:: tmuxp.exc.TmuxpException
117+
116118
.. autoexception:: tmuxp.exc.TmuxSessionExists
117119

118120
.. autoexception:: tmuxp.exc.EmptyConfigException

tmuxp/cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def load_workspace(config_file, args):
273273
else:
274274
builder.session.attach_session()
275275
return
276-
except Exception as e:
276+
except exc.TmuxpException as e:
277277
import traceback
278278

279279
print(traceback.format_exc())
@@ -587,7 +587,7 @@ def command_convert(args):
587587

588588
try:
589589
configfile = args.config
590-
except Exception:
590+
except exc.TmuxpException:
591591
print('Please enter a config')
592592

593593
file_user = os.path.join(config_dir, configfile)
@@ -645,8 +645,8 @@ def command_attach_session(args):
645645
session = next((s for s in t.sessions if s.get(
646646
'session_name') == ctext), None)
647647
if not session:
648-
raise Exception('Session not found.')
649-
except Exception as e:
648+
raise exc.TmuxpException('Session not found.')
649+
except exc.TmuxpException as e:
650650
print(e.message)
651651
return
652652

@@ -673,15 +673,15 @@ def command_kill_session(args):
673673
session = next((s for s in t.sessions if s.get(
674674
'session_name') == ctext), None)
675675
if not session:
676-
raise Exception('Session not found.')
677-
except Exception as e:
678-
print(e.message)
676+
raise exc.TmuxpException('Session not found.')
677+
except exc.TmuxpException as e:
678+
print(e.getMessage())
679679
return
680680

681681
try:
682682
session.kill_session()
683683
print("Killed session %s." % ctext)
684-
except Exception as e:
684+
except exc.TmuxpException as e:
685685
logger.error(e)
686686

687687
def get_parser():
@@ -902,7 +902,7 @@ def main():
902902

903903
try:
904904
util.has_required_tmux_version()
905-
except Exception as e:
905+
except exc.TmuxpException as e:
906906
logger.error(e)
907907
sys.exit()
908908

tmuxp/exc.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@
99
"""
1010

1111

12-
class TmuxSessionExists(Exception):
12+
class TmuxpException(Exception):
13+
14+
"""Base Exception for Tmuxp Errors.
15+
16+
Also for Python 2.6 compat:
17+
http://stackoverflow.com/a/6029838
18+
19+
"""
20+
21+
22+
class TmuxSessionExists(TmuxpException):
1323

1424
"""Session does not exist in the server."""
1525

1626
pass
1727

1828

19-
class ConfigError(Exception):
29+
class ConfigError(TmuxpException):
2030

2131
"""Error parsing tmuxp configuration dict."""
2232

tmuxp/pane.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
"""
1313
from __future__ import absolute_import, division, print_function, with_statement
14-
from . import util, formats
14+
from . import util, formats, exc
1515
import logging
1616

1717
logger = logging.getLogger(__name__)
@@ -131,7 +131,7 @@ def resize_pane(self, *args, **kwargs):
131131
proc = self.tmux('resize-pane', args[0])
132132

133133
if proc.stderr:
134-
raise Exception(proc.stderr)
134+
raise exc.TmuxpException(proc.stderr)
135135

136136
self.server._update_panes()
137137
return self

tmuxp/server.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ def _list_sessions(self):
121121
)
122122

123123
if proc.stderr:
124-
raise Exception(proc.stderr)
124+
raise exc.TmuxpException(proc.stderr)
125125
else:
126126
session_info = proc.stdout[0]
127127

128128
if proc.stderr:
129-
raise Exception(proc.stderr)
129+
raise exc.TmuxpException(proc.stderr)
130130

131131
sformats = formats.SESSION_FORMATS
132132
tmux_formats = ['#{%s}' % format for format in sformats]
@@ -188,7 +188,7 @@ def _list_windows(self):
188188
)
189189

190190
if proc.stderr:
191-
raise Exception(proc.stderr)
191+
raise exc.TmuxpException(proc.stderr)
192192

193193
windows = proc.stdout
194194

@@ -248,7 +248,7 @@ def _list_panes(self):
248248
)
249249

250250
if proc.stderr:
251-
raise Exception(proc.stderr)
251+
raise exc.TmuxpException(proc.stderr)
252252

253253
panes = proc.stdout
254254

@@ -338,7 +338,7 @@ def kill_session(self, target_session=None):
338338
proc = self.tmux('kill-session', '-t%s' % target_session)
339339

340340
if proc.stderr:
341-
raise Exception(proc.stderr)
341+
raise exc.TmuxpException(proc.stderr)
342342

343343
return self
344344

@@ -353,7 +353,7 @@ def switch_client(self, target_session):
353353
proc = self.tmux('switch-client', '-t%s' % target_session)
354354

355355
if proc.stderr:
356-
raise Exception(proc.stderr)
356+
raise exc.TmuxpException(proc.stderr)
357357

358358
def attach_session(self, target_session=None):
359359
"""``$ tmux attach-session`` aka alias: ``$ tmux attach``.
@@ -368,7 +368,7 @@ def attach_session(self, target_session=None):
368368
proc = self.tmux('attach-session', *tmux_args)
369369

370370
if proc.stderr:
371-
raise Exception(proc.stderr)
371+
raise exc.TmuxpException(proc.stderr)
372372

373373
def new_session(self,
374374
session_name=None,
@@ -440,7 +440,7 @@ def new_session(self,
440440
)
441441

442442
if proc.stderr:
443-
raise Exception(proc.stderr)
443+
raise exc.TmuxpException(proc.stderr)
444444

445445
session = proc.stdout[0]
446446

tmuxp/session.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
import pipes
1616
from .window import Window
17-
from .exc import TmuxSessionExists
18-
from . import util, formats
17+
from . import util, formats, exc
1918
import logging
2019
logger = logging.getLogger(__name__)
2120

@@ -81,15 +80,15 @@ def attach_session(self, target_session=None):
8180
proc = self.tmux('attach-session', '-t%s' % self.get('session_id'))
8281

8382
if proc.stderr:
84-
raise Exception(proc.stderr)
83+
raise exc.TmuxpException(proc.stderr)
8584

8685
def kill_session(self):
8786
"""``$ tmux kill-session``."""
8887

8988
proc = self.tmux('kill-session', '-t%s' % self.get('session_id'))
9089

9190
if proc.stderr:
92-
raise Exception(proc.stderr)
91+
raise exc.TmuxpException(proc.stderr)
9392

9493
def switch_client(self, target_session=None):
9594
"""``$ tmux kill-session``.
@@ -101,7 +100,7 @@ def switch_client(self, target_session=None):
101100
proc = self.tmux('switch-client', '-t%s' % self.get('session_id'))
102101

103102
if proc.stderr:
104-
raise Exception(proc.stderr)
103+
raise exc.TmuxpException(proc.stderr)
105104

106105
def rename_session(self, new_name):
107106
"""Rename session and return new :class:`Session` object.
@@ -119,7 +118,7 @@ def rename_session(self, new_name):
119118
)
120119

121120
if proc.stderr:
122-
raise Exception(proc.stderr)
121+
raise exc.TmuxpException(proc.stderr)
123122

124123
return self
125124

@@ -182,7 +181,7 @@ def new_window(self,
182181
proc = self.tmux('new-window', *window_args)
183182

184183
if proc.stderr:
185-
raise Exception(proc.stderr)
184+
raise exc.TmuxpException(proc.stderr)
186185

187186
window = proc.stdout[0]
188187

@@ -218,7 +217,7 @@ def kill_window(self, target_window=None):
218217
proc = self.tmux('kill-window', target)
219218

220219
if proc.stderr:
221-
raise Exception(proc.stderr)
220+
raise exc.TmuxpException(proc.stderr)
222221

223222
self.server._update_windows()
224223

@@ -274,11 +273,11 @@ def attached_window(self):
274273
if len(active_windows) == int(1):
275274
return active_windows[0]
276275
else:
277-
raise Exception(
276+
raise exc.TmuxpException(
278277
'multiple active windows found. %s' % active_windows)
279278

280279
if len(self._windows) == int(0):
281-
raise Exception('No Windows')
280+
raise exc.TmuxpException('No Windows')
282281

283282
def select_window(self, target_window):
284283
"""Return :class:`Window` selected via ``$ tmux select-window``.
@@ -297,7 +296,7 @@ def select_window(self, target_window):
297296
proc = self.tmux('select-window', target)
298297

299298
if proc.stderr:
300-
raise Exception(proc.stderr)
299+
raise exc.TmuxpException(proc.stderr)
301300

302301
return self.attached_window()
303302

tmuxp/testsuite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
def suite():
3333
try:
3434
import unittest2 as unittest
35-
except ImportError: # Python 2.7
35+
except ImportError: # Python 2.7
3636
import unittest
3737

3838
return unittest.TestLoader().discover('.', pattern="test_*.py")

tmuxp/testsuite/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def setUpClassa(cls):
9999
logger.error(e)
100100

101101
logger.error(traceback.print_exc())
102-
# raise Exception(e)
102+
# raise exc.TmuxpException(e)
103103
return
104104

105105
@classmethod

tmuxp/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class tmux(object):
3636
proc = tmux('new-session', '-s%' % 'my session')
3737
3838
if proc.stderr:
39-
raise Exception('Command: %s returned error: %s' % (proc.cmd, proc.stderr))
39+
raise exc.TmuxpException('Command: %s returned error: %s' % (proc.cmd, proc.stderr))
4040
4141
print('tmux command returned %s' % proc.stdout)
4242
@@ -221,7 +221,7 @@ def which(exe=None):
221221
full_path = os.path.join(path, exe)
222222
if os.access(full_path, os.X_OK):
223223
return full_path
224-
raise Exception(
224+
raise exc.TmuxpException(
225225
'{0!r} could not be found in the following search '
226226
'path: {1!r}'.format(
227227
exe, search_path
@@ -242,7 +242,7 @@ def is_version(version):
242242
proc = tmux('-V')
243243

244244
if proc.stderr:
245-
raise Exception(proc.stderr)
245+
raise exc.TmuxpException(proc.stderr)
246246

247247
installed_version = proc.stdout[0].split('tmux ')[1]
248248

@@ -254,12 +254,12 @@ def has_required_tmux_version():
254254
proc = tmux('-V')
255255

256256
if proc.stderr:
257-
raise Exception(proc.stderr)
257+
raise exc.TmuxpException(proc.stderr)
258258

259259
version = proc.stdout[0].split('tmux ')[1]
260260

261261
if StrictVersion(version) <= StrictVersion("1.7"):
262-
raise Exception(
262+
raise exc.TmuxpException(
263263
'tmuxp only supports tmux 1.8 and greater. This system'
264264
' has %s installed. Upgrade your tmux to use tmuxp.' % version
265265
)

tmuxp/window.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import pipes
1616
from .pane import Pane
1717

18-
from . import util, formats
18+
from . import util, formats, exc
1919
import logging
2020

2121
logger = logging.getLogger(__name__)
@@ -116,7 +116,7 @@ def select_layout(self, layout=None):
116116
)
117117

118118
if proc.stderr:
119-
raise Exception(proc.stderr)
119+
raise exc.TmuxpException(proc.stderr)
120120

121121
def set_window_option(self, option, value):
122122
"""Wrapper for ``$ tmux set-window-option <option> <value>``.
@@ -246,7 +246,7 @@ def kill_window(self):
246246
)
247247

248248
if proc.stderr:
249-
raise Exception(proc.stderr)
249+
raise exc.TmuxpException(proc.stderr)
250250

251251
self.server._update_windows()
252252

@@ -266,7 +266,7 @@ def move_window(self, destination):
266266
)
267267

268268
if proc.stderr:
269-
raise Exception(proc.stderr)
269+
raise exc.TmuxpException(proc.stderr)
270270

271271
self.server._update_windows()
272272

@@ -286,7 +286,7 @@ def select_pane(self, target_pane):
286286
proc = self.tmux('select-pane', '-t%s' % target_pane)
287287

288288
if proc.stderr:
289-
raise Exception(proc.stderr)
289+
raise exc.TmuxpException(proc.stderr)
290290

291291
return self.attached_pane()
292292

@@ -337,11 +337,11 @@ def split_window(self, attach=True):
337337

338338
# tmux < 1.7. This is added in 1.7.
339339
if pane.stderr:
340-
raise Exception(pane.stderr)
340+
raise exc.TmuxpException(pane.stderr)
341341
if 'pane too small' in pane.stderr:
342342
pass
343343

344-
raise Exception(pane.stderr, self._TMUX, self.panes)
344+
raise exc.TmuxpException(pane.stderr, self._TMUX, self.panes)
345345
else:
346346
pane = pane.stdout[0]
347347

0 commit comments

Comments
 (0)