@@ -53,13 +53,6 @@ def __init__(self, value):
53
53
def __str__ (self ):
54
54
return repr (self .value )
55
55
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
63
56
64
57
def _unlock_display (ndisplay ):
65
58
lockf = os .path .join ('/tmp' , '.X%d-lock' % ndisplay )
@@ -70,19 +63,24 @@ def _unlock_display(ndisplay):
70
63
71
64
return True
72
65
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
+ '''
73
71
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" )
80
74
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
86
84
87
85
def load_template (name ):
88
86
"""Load a template from the script_templates directory
@@ -1131,25 +1129,6 @@ def version(self):
1131
1129
self .__class__ .__name__ )
1132
1130
return self ._version
1133
1131
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
-
1153
1132
1154
1133
class Stream (object ):
1155
1134
"""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):
1211
1190
1212
1191
cmdline = runtime .cmdline
1213
1192
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 :
1216
1195
raise RuntimeError ('Xvfb was not found, X redirection aborted' )
1217
1196
cmdline = 'xvfb-run -a ' + cmdline
1218
1197
@@ -1452,7 +1431,7 @@ def _get_environ(self):
1452
1431
1453
1432
def version_from_command (self , flag = '-v' ):
1454
1433
cmdname = self .cmd .split ()[0 ]
1455
- if self . _exists_in_path (cmdname ):
1434
+ if _exists_in_path (cmdname ):
1456
1435
env = deepcopy (os .environ .data )
1457
1436
out_environ = self ._get_environ ()
1458
1437
env .update (out_environ )
@@ -1488,8 +1467,8 @@ def _run_interface(self, runtime, correct_return_codes=[0]):
1488
1467
out_environ = self ._get_environ ()
1489
1468
runtime .environ .update (out_environ )
1490
1469
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 )
1493
1472
if not exist_val :
1494
1473
raise IOError ("%s could not be found on host %s" %
1495
1474
(self .cmd .split ()[0 ], runtime .hostname ))
0 commit comments