@@ -150,7 +150,12 @@ class tmux_cmd(object):
150150 """
151151
152152 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 ]
154159 cmd += args # add the command arguments to cmd
155160 cmd = [str (c ) for c in cmd ]
156161
@@ -187,8 +192,10 @@ def __init__(self, *args, **kwargs):
187192 if not self .stdout :
188193 self .stdout = self .stderr [0 ]
189194
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+ )
192199
193200
194201class TmuxMappingObject (collections .MutableMapping ):
@@ -329,10 +336,9 @@ def get_by_id(self, id):
329336 return None
330337
331338
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 ):
336342 """Return path of bin. Python clone of /usr/bin/which.
337343
338344 from salt.util - https://www.github.com/saltstack/salt - license apache
@@ -341,6 +347,8 @@ def which(exe=None,
341347 :type exe: string
342348 :param default_path: Application to search PATHs for.
343349 :type default_path: list
350+ :param append_env_path: Append PATHs in environmental variables.
351+ :type append_env_path: bool
344352 :rtype: string
345353
346354 """
@@ -356,8 +364,12 @@ def _is_executable_file_or_link(exe):
356364 # Enhance POSIX path for the reliability at some environments, when
357365 # $PATH is changing. This also keeps order, where 'first came, first
358366 # 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+
361373 for default_path in default_paths :
362374 if default_path not in search_path :
363375 search_path .append (default_path )
0 commit comments