Return the path to a new existing unique temporary directory, created under the `base_dir` base directory using the `prefix` prefix. If `base_dir` is not provided, use the 'SCANCODE_TMP' env var or the system temp directory. WARNING: do not change this code without changing sca
(base_dir=_base_temp_dir, prefix="")
| 98 | |
| 99 | |
| 100 | def get_temp_dir(base_dir=_base_temp_dir, prefix=""): |
| 101 | """ |
| 102 | Return the path to a new existing unique temporary directory, created under |
| 103 | the `base_dir` base directory using the `prefix` prefix. |
| 104 | If `base_dir` is not provided, use the 'SCANCODE_TMP' env var or the system |
| 105 | temp directory. |
| 106 | |
| 107 | WARNING: do not change this code without changing scancode_config.py too |
| 108 | """ |
| 109 | |
| 110 | has_base = bool(base_dir) |
| 111 | if not has_base: |
| 112 | base_dir = os.getenv("SCANCODE_TMP") |
| 113 | if not base_dir: |
| 114 | base_dir = tempfile.gettempdir() |
| 115 | |
| 116 | if not os.path.exists(base_dir): |
| 117 | create_dir(base_dir) |
| 118 | |
| 119 | if not has_base: |
| 120 | prefix = "scancode-tk-" |
| 121 | |
| 122 | return tempfile.mkdtemp(prefix=prefix, dir=base_dir) |
| 123 | |
| 124 | |
| 125 | # |
no test coverage detected