find a program in folders path_lst, and sets env[var] @param filenames: a list of possible names of the program to search for @return: the full path of the filename if found, or '' if filename could not be found
(*filenames)
| 24 | os.chdir(prevdir) |
| 25 | |
| 26 | def find_program(*filenames): |
| 27 | """find a program in folders path_lst, and sets env[var] |
| 28 | @param filenames: a list of possible names of the program to search for |
| 29 | @return: the full path of the filename if found, or '' if filename could not be found |
| 30 | """ |
| 31 | paths = os.environ.get('PATH', '').split(os.pathsep) |
| 32 | suffixes = ('win32' in sys.platform) and '.exe .com .bat .cmd' or '' |
| 33 | for filename in filenames: |
| 34 | for name in [filename+ext for ext in suffixes.split(' ')]: |
| 35 | for directory in paths: |
| 36 | full_path = os.path.join(directory, name) |
| 37 | if os.path.isfile(full_path): |
| 38 | return full_path |
| 39 | return '' |
| 40 | |
| 41 | def do_subst_in_file(targetfile, sourcefile, dict): |
| 42 | """Replace all instances of the keys of dict with their values. |