@@ -150,7 +150,12 @@ class tmux_cmd(object):
150
150
"""
151
151
152
152
def __init__ (self , * args , ** kwargs ):
153
- cmd = [which ('tmux' )]
153
+
154
+ tmux_bin = which ('tmux' )
155
+ if not tmux_bin :
156
+ raise (exc .TmuxCommandNotFound )
157
+
158
+ cmd = [tmux_bin ]
154
159
cmd += args # add the command arguments to cmd
155
160
cmd = [str (c ) for c in cmd ]
156
161
@@ -187,8 +192,10 @@ def __init__(self, *args, **kwargs):
187
192
if not self .stdout :
188
193
self .stdout = self .stderr [0 ]
189
194
190
- logger .debug ('self.stdout for %s: \n %s' %
191
- (' ' .join (cmd ), self .stdout ))
195
+ logger .debug (
196
+ 'self.stdout for %s: \n %s' %
197
+ (' ' .join (cmd ), self .stdout )
198
+ )
192
199
193
200
194
201
class TmuxMappingObject (collections .MutableMapping ):
@@ -329,10 +336,9 @@ def get_by_id(self, id):
329
336
return None
330
337
331
338
332
- def which (exe = None ,
333
- default_paths = [
334
- '/bin' , '/sbin' , '/usr/bin' , '/usr/sbin' , '/usr/local/bin' ]
335
- ):
339
+ def which (exe = None , default_paths = [
340
+ '/bin' , '/sbin' , '/usr/bin' , '/usr/sbin' , '/usr/local/bin'
341
+ ], append_env_path = True ):
336
342
"""Return path of bin. Python clone of /usr/bin/which.
337
343
338
344
from salt.util - https://www.github.com/saltstack/salt - license apache
@@ -341,6 +347,8 @@ def which(exe=None,
341
347
:type exe: string
342
348
:param default_path: Application to search PATHs for.
343
349
:type default_path: list
350
+ :param append_env_path: Append PATHs in environmental variables.
351
+ :type append_env_path: bool
344
352
:rtype: string
345
353
346
354
"""
@@ -356,8 +364,12 @@ def _is_executable_file_or_link(exe):
356
364
# Enhance POSIX path for the reliability at some environments, when
357
365
# $PATH is changing. This also keeps order, where 'first came, first
358
366
# win' for cases to find optional alternatives
359
- search_path = os .environ .get ('PATH' ) and \
360
- os .environ ['PATH' ].split (os .pathsep ) or list ()
367
+ if append_env_path :
368
+ search_path = os .environ .get ('PATH' ) and \
369
+ os .environ ['PATH' ].split (os .pathsep ) or list ()
370
+ else :
371
+ search_path = []
372
+
361
373
for default_path in default_paths :
362
374
if default_path not in search_path :
363
375
search_path .append (default_path )
0 commit comments