+def findname(names, files):
+ matches = list(names.keys())
+ for f in files:
+ matches = [pfx for pfx in matches if f.startswith(pfx)]
+ if len(matches) < 1: return None
+ matches.sort(key=len, reverse=True)
+ return names[matches[0]]
+
+def prefixes(path):
+ nmpath = path/"names"
+ if not nmpath.exists():
+ return {}
+ ret = {}
+ with nmpath.open("r") as fp:
+ for line in fp:
+ line = line.strip()
+ p = line.find(' ')
+ if p < 0: continue
+ ret[line[:p]] = line[p + 1:]
+ return ret
+