OLD | NEW |
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 # This file contains a set of utilities functions used by other Python-based | 5 # This file contains a set of utilities functions used by other Python-based |
6 # scripts. | 6 # scripts. |
7 | 7 |
8 import commands | 8 import commands |
9 import os | 9 import os |
10 import platform | 10 import platform |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 self._temp_dir = None | 455 self._temp_dir = None |
456 self._prefix = prefix | 456 self._prefix = prefix |
457 | 457 |
458 def __enter__(self): | 458 def __enter__(self): |
459 self._temp_dir = tempfile.mkdtemp(self._prefix) | 459 self._temp_dir = tempfile.mkdtemp(self._prefix) |
460 return self._temp_dir | 460 return self._temp_dir |
461 | 461 |
462 def __exit__(self, *_): | 462 def __exit__(self, *_): |
463 shutil.rmtree(self._temp_dir, ignore_errors=True) | 463 shutil.rmtree(self._temp_dir, ignore_errors=True) |
464 | 464 |
| 465 class ChangedWorkingDirectory(object): |
| 466 def __init__(self, working_directory): |
| 467 self._working_directory = working_directory |
| 468 |
| 469 def __enter__(self): |
| 470 self._old_cwd = os.getcwd() |
| 471 print "Enter directory = ", self._working_directory |
| 472 os.chdir(self._working_directory) |
| 473 |
| 474 def __exit__(self, *_): |
| 475 print "Enter directory = ", self._old_cwd |
| 476 os.chdir(self._old_cwd) |
| 477 |
465 | 478 |
466 if __name__ == "__main__": | 479 if __name__ == "__main__": |
467 import sys | 480 import sys |
468 Main(sys.argv) | 481 Main(sys.argv) |
OLD | NEW |