@@ -53,13 +53,6 @@ def __init__(self, value):
5353 def __str__ (self ):
5454 return repr (self .value )
5555
56- def _lock_files ():
57- tmpdir = '/tmp'
58- pattern = '.X*-lock'
59- names = fnmatch .filter (os .listdir (tmpdir ), pattern )
60- ls = [os .path .join (tmpdir , child ) for child in names ]
61- ls = [p for p in ls if os .path .isfile (p )]
62- return ls
6356
6457def _unlock_display (ndisplay ):
6558 lockf = os .path .join ('/tmp' , '.X%d-lock' % ndisplay )
@@ -70,19 +63,24 @@ def _unlock_display(ndisplay):
7063
7164 return True
7265
66+ def _exists_in_path (cmd , environ ):
67+ '''
68+ Based on a code snippet from
69+ http://orip.org/2009/08/python-checking-if-executable-exists-in.html
70+ '''
7371
74-
75- def _search_for_free_display ():
76- ls = [int (x .split ('X' )[1 ].split ('-' )[0 ]) for x in _lock_files ()]
77- min_display_num = 1000
78- if len (ls ):
79- display_num = max (min_display_num , max (ls ) + 1 )
72+ if 'PATH' in environ :
73+ input_environ = environ .get ("PATH" )
8074 else :
81- display_num = min_display_num
82- random .seed ()
83- display_num += random .randint (0 , 100 )
84- return display_num
85-
75+ input_environ = os .environ .get ("PATH" , "" )
76+ extensions = os .environ .get ("PATHEXT" , "" ).split (os .pathsep )
77+ for directory in input_environ .split (os .pathsep ):
78+ base = os .path .join (directory , cmd )
79+ options = [base ] + [(base + ext ) for ext in extensions ]
80+ for filename in options :
81+ if os .path .exists (filename ):
82+ return True , filename
83+ return False , None
8684
8785def load_template (name ):
8886 """Load a template from the script_templates directory
@@ -1131,25 +1129,6 @@ def version(self):
11311129 self .__class__ .__name__ )
11321130 return self ._version
11331131
1134- def _exists_in_path (self , cmd , environ ):
1135- '''
1136- Based on a code snippet from
1137- http://orip.org/2009/08/python-checking-if-executable-exists-in.html
1138- '''
1139-
1140- if 'PATH' in environ :
1141- input_environ = environ .get ("PATH" )
1142- else :
1143- input_environ = os .environ .get ("PATH" , "" )
1144- extensions = os .environ .get ("PATHEXT" , "" ).split (os .pathsep )
1145- for directory in input_environ .split (os .pathsep ):
1146- base = os .path .join (directory , cmd )
1147- options = [base ] + [(base + ext ) for ext in extensions ]
1148- for filename in options :
1149- if os .path .exists (filename ):
1150- return True , filename
1151- return False , None
1152-
11531132
11541133class Stream (object ):
11551134 """Function to capture stdout and stderr streams with timestamps
@@ -1211,8 +1190,8 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
12111190
12121191 cmdline = runtime .cmdline
12131192 if redirect_x :
1214- exist_xvfb , _ = self . _exists_in_path ('xvfb-run' , runtime .environ )
1215- if not exist_val :
1193+ exist_xvfb , _ = _exists_in_path ('xvfb-run' , runtime .environ )
1194+ if not exist_xvfb :
12161195 raise RuntimeError ('Xvfb was not found, X redirection aborted' )
12171196 cmdline = 'xvfb-run -a ' + cmdline
12181197
@@ -1452,7 +1431,7 @@ def _get_environ(self):
14521431
14531432 def version_from_command (self , flag = '-v' ):
14541433 cmdname = self .cmd .split ()[0 ]
1455- if self . _exists_in_path (cmdname ):
1434+ if _exists_in_path (cmdname ):
14561435 env = deepcopy (os .environ .data )
14571436 out_environ = self ._get_environ ()
14581437 env .update (out_environ )
@@ -1488,8 +1467,8 @@ def _run_interface(self, runtime, correct_return_codes=[0]):
14881467 out_environ = self ._get_environ ()
14891468 runtime .environ .update (out_environ )
14901469 executable_name = self .cmd .split ()[0 ]
1491- exist_val , cmd_path = self . _exists_in_path (executable_name ,
1492- runtime .environ )
1470+ exist_val , cmd_path = _exists_in_path (executable_name ,
1471+ runtime .environ )
14931472 if not exist_val :
14941473 raise IOError ("%s could not be found on host %s" %
14951474 (self .cmd .split ()[0 ], runtime .hostname ))
0 commit comments