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)
| 86 | |
| 87 | |
| 88 | def 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 | |
| 115 | class PathProvider: |