Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: tools/utils.py

Issue 19523003: Use a utils.TempDir() decorator for temporary files, to make sure we clean up even in case of excep… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/bots/editor.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/utils.py
diff --git a/tools/utils.py b/tools/utils.py
index 8346d09546c8f561856e91f463d2ede50a4fec1d..0abb0ed15d32240c5f8613e7612315830209f549 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -9,8 +9,10 @@ import commands
import os
import platform
import re
+import shutil
import subprocess
import sys
+import tempfile
# Try to guess the host operating system.
@@ -406,6 +408,18 @@ def DartSdkBinary():
dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin')
return os.path.join(dart_binary_prefix, 'dart')
+class TempDir(object):
+ def __init__(self, prefix=''):
+ self._temp_dir = None
+ self._prefix = prefix
+
+ def __enter__(self):
+ self._temp_dir = tempfile.mkdtemp(self._prefix)
+ return self._temp_dir
+
+ def __exit__(self, *_):
+ shutil.rmtree(self._temp_dir, ignore_errors=True)
+
if __name__ == "__main__":
import sys
« no previous file with comments | « tools/bots/editor.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698