OLD | NEW |
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import contextlib | 5 import contextlib |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import shutil | 10 import shutil |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 @contextlib.contextmanager | 82 @contextlib.contextmanager |
83 def TemporaryDirectory(): | 83 def TemporaryDirectory(): |
84 """Returns a freshly-created directory that gets automatically deleted after | 84 """Returns a freshly-created directory that gets automatically deleted after |
85 usage. | 85 usage. |
86 """ | 86 """ |
87 name = tempfile.mkdtemp() | 87 name = tempfile.mkdtemp() |
88 try: | 88 try: |
89 yield name | 89 yield name |
90 finally: | 90 finally: |
91 shutil.rmtree(name) | 91 shutil.rmtree(name) |
| 92 |
| 93 |
| 94 def EnsureParentDirectoryExists(path): |
| 95 """Verifies that the parent directory exists or creates it if missing.""" |
| 96 parent_directory_path = os.path.abspath(os.path.dirname(path)) |
| 97 if not os.path.isdir(parent_directory_path): |
| 98 os.makedirs(parent_directory_path) |
OLD | NEW |