Skip to content
Snippets Groups Projects
Commit 42cfb3ce authored by Jonathan Maw's avatar Jonathan Maw
Browse files

utils.py: Add a helper for searching upwards for files

i.e. with a given directory and filename, check parent directories until
either a directory with the filename is found, or you reach the root of
the filesystem.
parent d850101b
No related branches found
No related tags found
No related merge requests found
......@@ -1198,3 +1198,17 @@ def _deduplicate(iterable, key=None):
def _get_link_mtime(path):
path_stat = os.lstat(path)
return path_stat.st_mtime
# Returns the first directory to contain filename, or an empty string if
# none found
#
def _search_upward_for_file(directory, filename):
directory = os.path.abspath(directory)
while not os.path.isfile(os.path.join(directory, filename)):
parent_dir = os.path.dirname(directory)
if directory == parent_dir:
return ""
directory = parent_dir
return directory
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment