| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """This module contains utilities related to file/directory manipulations.""" | |
| 7 | |
| 8 import os | |
| 9 import stat | |
| 10 | |
| 11 from common import chromium_utils | |
| 12 | |
| 13 | |
| 14 def clear_directory(directory): | |
| 15 """Attempt to clear the contents of a directory. This should only be used | |
| 16 when the directory itself cannot be removed for some reason. Otherwise, | |
| 17 chromium_utils.RemoveDirectory or create_clean_local_dir should be preferred. | |
| 18 """ | |
| 19 for path in os.listdir(directory): | |
| 20 abs_path = os.path.join(directory, path) | |
| 21 if os.path.isdir(abs_path): | |
| 22 chromium_utils.RemoveDirectory(abs_path) | |
| 23 else: | |
| 24 if not os.access(abs_path, os.W_OK): | |
| 25 # Change the path to be writeable | |
| 26 os.chmod(abs_path, stat.S_IWUSR) | |
| 27 os.remove(abs_path) | |
| 28 | |
| 29 | |
| 30 def create_clean_local_dir(directory): | |
| 31 """If directory already exists, it is deleted and recreated.""" | |
| 32 if os.path.exists(directory): | |
| 33 chromium_utils.RemoveDirectory(directory) | |
| 34 print 'Creating directory: %s' % directory | |
| 35 os.makedirs(directory) | |
| OLD | NEW |