MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / maybe_chdir

Function maybe_chdir

main.py:10–25  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

8
9
10def 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
28if __name__ == '__main__':

Callers 1

main.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected