MCPcopy Create free account
hub / github.com/comaps/comaps / find_last_build_dir

Function find_last_build_dir

tools/python/maps_generator/generator/env.py:88–112  ·  view source on GitHub ↗

It tries to find a last generation directory. If it's found function returns path of last generation directory. Otherwise returns None.

(hint: Optional[AnyStr] = None)

Source from the content-addressed store, hash-verified

86
87
88def find_last_build_dir(hint: Optional[AnyStr] = None) -> Optional[AnyStr]:
89 """
90 It tries to find a last generation directory. If it's found function
91 returns path of last generation directory. Otherwise returns None.
92 """
93 if hint is not None:
94 p = os.path.join(settings.MAIN_OUT_PATH, hint)
95 return hint if os.path.exists(p) else None
96 try:
97 paths = [
98 os.path.join(settings.MAIN_OUT_PATH, f)
99 for f in os.listdir(settings.MAIN_OUT_PATH)
100 ]
101 except FileNotFoundError:
102 logger.exception(f"{settings.MAIN_OUT_PATH} not found.")
103 return None
104 versions = []
105 for path in paths:
106 version_path = os.path.join(path, settings.VERSION_FILE_NAME)
107 if not os.path.isfile(version_path):
108 versions.append(0)
109 else:
110 versions.append(Version.read(version_path))
111 pairs = sorted(zip(paths, versions), key=lambda p: p[1], reverse=True)
112 return None if not pairs or pairs[0][1] == 0 else pairs[0][0].split(os.sep)[-1]
113
114
115class PathProvider:

Callers 1

mainFunction · 0.90

Calls 3

joinMethod · 0.45
appendMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected