28 lines
635 B
Python
28 lines
635 B
Python
import os
|
|
|
|
def find_nearest(path, test):
|
|
path = os.path.abspath(path)
|
|
|
|
while True:
|
|
parent_path = os.path.dirname(path)
|
|
for entry in os.listdir(path):
|
|
if test(entry):
|
|
return path
|
|
|
|
if parent_path == path:
|
|
return None
|
|
|
|
path = parent_path
|
|
|
|
def merge_dicts (dicts):
|
|
fusion = {}
|
|
for source in dicts:
|
|
if not source:
|
|
continue
|
|
|
|
for key, value in source.items():
|
|
if isinstance(value, dict):
|
|
value = merge_dicts([fusion.get(key, None), value])
|
|
fusion[key] = value
|
|
return fusion
|