returns the topmost already-existing directory in the given path erasing work-dirs should never progress above this file. Also returns the name of first non-existing dir for use as filename.
(workdir)
| 227 | |
| 228 | |
| 229 | def get_closest_dir(workdir): |
| 230 | """ |
| 231 | returns the topmost already-existing directory in the given path |
| 232 | erasing work-dirs should never progress above this file. |
| 233 | Also returns the name of first non-existing dir for use as filename. |
| 234 | """ |
| 235 | closest_dir = "" |
| 236 | for wdi in path_split_all(workdir): |
| 237 | if os.path.isdir(os.path.join(closest_dir, wdi)): |
| 238 | closest_dir = os.path.join(closest_dir, wdi) |
| 239 | else: |
| 240 | break |
| 241 | assert closest_dir != workdir |
| 242 | return closest_dir, wdi |
| 243 | |
| 244 | |
| 245 | @contextmanager |