Detects if DepthMap was installed as a stable-diffusion-webui script, but run without current directory set to the stable-diffusion-webui root. Changes current directory if needed. This is to avoid re-downloading models and putting results into a wrong folder.
()
| 8 | |
| 9 | |
| 10 | def maybe_chdir(): |
| 11 | """Detects if DepthMap was installed as a stable-diffusion-webui script, but run without current directory set to |
| 12 | the stable-diffusion-webui root. Changes current directory if needed. |
| 13 | This is to avoid re-downloading models and putting results into a wrong folder.""" |
| 14 | try: |
| 15 | file_path = pathlib.Path(__file__) |
| 16 | path = file_path.parts |
| 17 | while len(path) > 0 and path[-1] != src.misc.REPOSITORY_NAME: |
| 18 | path = path[:-1] |
| 19 | if len(path) >= 2 and path[-1] == src.misc.REPOSITORY_NAME and path[-2] == "extensions": |
| 20 | path = path[:-2] |
| 21 | listdir = os.listdir(str(pathlib.Path(*path))) |
| 22 | if 'launch.py' in listdir and 'webui.py': |
| 23 | os.chdir(str(pathlib.Path(*path))) |
| 24 | except: |
| 25 | pass |
| 26 | |
| 27 | |
| 28 | if __name__ == '__main__': |