Chromium Code Reviews| Index: build/android/devil/utils/tempdir.py |
| diff --git a/build/android/devil/utils/tempdir.py b/build/android/devil/utils/tempdir.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2566c00c274c5f1203e4e155cac5758aebd9ccde |
| --- /dev/null |
| +++ b/build/android/devil/utils/tempdir.py |
| @@ -0,0 +1,15 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
|
rnephew (Wrong account)
2015/11/04 22:22:02
I like this. They have it as a context manager in
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import contextlib |
| +import tempfile |
| +import shutil |
| + |
| +@contextlib.contextmanager |
| +def TempDir(suffix='', prefix=''): |
| + dirname = tempfile.mkdtemp(suffix=suffix, prefix=prefix) |
| + try: |
| + yield dirname |
| + finally: |
| + shutil.rmtree(dirname) |