1271 return True |
1271 return True |
1272 |
1272 |
1273 def find_exe(command): |
1273 def find_exe(command): |
1274 '''Find executable for command searching like cmd.exe does. |
1274 '''Find executable for command searching like cmd.exe does. |
1275 If command is a basename then PATH is searched for command. |
1275 If command is a basename then PATH is searched for command. |
1276 PATH isn't searched if command is an absolute or relative path. |
1276 PATH isn't searched if command is an absolute or relative path. |
1277 An extension from PATHEXT is found and added if not present. |
1277 An extension from PATHEXT is found and added if not present. |
1278 If command isn't found None is returned.''' |
1278 If command isn't found None is returned.''' |
1279 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') |
1279 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') |
1280 pathexts = [ext for ext in pathext.lower().split(os.pathsep)] |
1280 pathexts = [ext for ext in pathext.lower().split(os.pathsep)] |
1281 if os.path.splitext(command)[1].lower() in pathexts: |
1281 if os.path.splitext(command)[1].lower() in pathexts: |
1282 pathexts = [''] |
1282 pathexts = [''] |
1283 |
1283 |
1284 def findexisting(pathcommand): |
1284 def findexisting(pathcommand): |
1285 'Will append extension (if needed) and return existing file' |
1285 'Will append extension (if needed) and return existing file' |
1286 for ext in pathexts: |
1286 for ext in pathexts: |
1287 executable = pathcommand + ext |
1287 executable = pathcommand + ext |
1288 if os.path.exists(executable): |
1288 if os.path.exists(executable): |
1289 return executable |
1289 return executable |
1290 return None |
1290 return None |
1291 |
1291 |
1292 if os.sep in command: |
1292 if os.sep in command: |
1293 return findexisting(command) |
1293 return findexisting(command) |
1294 |
1294 |
1295 for path in os.environ.get('PATH', '').split(os.pathsep): |
1295 for path in os.environ.get('PATH', '').split(os.pathsep): |
1296 executable = findexisting(os.path.join(path, command)) |
1296 executable = findexisting(os.path.join(path, command)) |
1297 if executable is not None: |
1297 if executable is not None: |
1298 return executable |
1298 return executable |
1299 return None |
1299 return None |
1463 return st.st_uid == os.getuid() |
1463 return st.st_uid == os.getuid() |
1464 |
1464 |
1465 def find_exe(command): |
1465 def find_exe(command): |
1466 '''Find executable for command searching like which does. |
1466 '''Find executable for command searching like which does. |
1467 If command is a basename then PATH is searched for command. |
1467 If command is a basename then PATH is searched for command. |
1468 PATH isn't searched if command is an absolute or relative path. |
1468 PATH isn't searched if command is an absolute or relative path. |
1469 If command isn't found None is returned.''' |
1469 If command isn't found None is returned.''' |
1470 if sys.platform == 'OpenVMS': |
1470 if sys.platform == 'OpenVMS': |
1471 return command |
1471 return command |
1472 |
1472 |
1473 def findexisting(executable): |
1473 def findexisting(executable): |
1474 'Will return executable if existing file' |
1474 'Will return executable if existing file' |
1475 if os.path.exists(executable): |
1475 if os.path.exists(executable): |
1476 return executable |
1476 return executable |
1477 return None |
1477 return None |
1478 |
1478 |
1479 if os.sep in command: |
1479 if os.sep in command: |
1480 return findexisting(command) |
1480 return findexisting(command) |
1481 |
1481 |
1482 for path in os.environ.get('PATH', '').split(os.pathsep): |
1482 for path in os.environ.get('PATH', '').split(os.pathsep): |
1483 executable = findexisting(os.path.join(path, command)) |
1483 executable = findexisting(os.path.join(path, command)) |
1484 if executable is not None: |
1484 if executable is not None: |
1485 return executable |
1485 return executable |
1486 return None |
1486 return None |