def _findToolFile(name, containerFile, typ): PathLog.track(name) if os.path.exists(name): # absolute reference return name if containerFile: rootPath = os.path.dirname(os.path.dirname(containerFile)) paths = [os.path.join(rootPath, typ)] else: paths = [] paths.extend(PathPreferences.searchPathsTool(typ)) def _findFile(path, name): PathLog.track(path, name) fullPath = os.path.join(path, name) if os.path.exists(fullPath): return (True, fullPath) for root, ds, fs in os.walk(path): for d in ds: found, fullPath = _findFile(d, name) if found: return (True, fullPath) return (False, None) for p in paths: found, path = _findFile(p, name) if found: return path return None
def _findRelativePath(path, typ): relative = path for p in PathPreferences.searchPathsTool(typ): if path.startswith(p): p = path[len(p):] if os.path.sep == p[0]: p = p[1:] if len(p) < len(relative): relative = p return relative
def searchFor(pname, fname): if dbg: PathLog.debug("Looking for {}".format(pname)) if fname: for p in PathPreferences.searchPathsTool(typ): f = os.path.join(p, fname) if dbg: PathLog.debug(" Checking {}".format(f)) if os.path.exists(f): if dbg: PathLog.debug(" Found {} at {}".format(typ, f)) return f if pname and os.path.sep != pname: ppname, pfname = os.path.split(pname) ffname = os.path.join(pfname, fname) if fname else pfname return searchFor(ppname, ffname) return None