MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / find_file

Function find_file

scripts/find_file.py:5–27  ·  view source on GitHub ↗

Look for file in a few standard locations, return absolute path if found.

(filename, *search_path)

Source from the content-addressed store, hash-verified

3import sys
4
5def 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));

Callers 2

convert_to_abs_pathFunction · 0.90
load_wiresFunction · 0.90

Calls 1

IOErrorClass · 0.85

Tested by

no test coverage detected