Look for file in a few standard locations, return absolute path if found.
(filename, *search_path)
| 3 | import sys |
| 4 | |
| 5 | def find_file(filename, *search_path): |
| 6 | """ |
| 7 | Look for file in a few standard locations, return absolute path if found. |
| 8 | """ |
| 9 | if os.path.isabs(filename): |
| 10 | if os.path.exists(filename): |
| 11 | return filename; |
| 12 | else: |
| 13 | raise IOError("{} does not exist".format(filename)); |
| 14 | |
| 15 | exe_dir = sys.path[0]; |
| 16 | root_dir = os.environ["MICROSTRUCTURES_PATH"]; |
| 17 | search_path = list(search_path); |
| 18 | search_path.append(exe_dir); |
| 19 | search_path.append(os.getcwd()); |
| 20 | search_path.append(root_dir); |
| 21 | |
| 22 | for path in search_path: |
| 23 | file_loc = os.path.join(path, filename); |
| 24 | if os.path.exists(file_loc): |
| 25 | return os.path.abspath(file_loc); |
| 26 | |
| 27 | raise IOError("{} does not exist".format(filename)); |
no test coverage detected