| OLD | NEW |
| 1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 # FIXME: Should we delete non-empty directories? | 167 # FIXME: Should we delete non-empty directories? |
| 168 if os.path.exists(self._directory_path): | 168 if os.path.exists(self._directory_path): |
| 169 os.rmdir(self._directory_path) | 169 os.rmdir(self._directory_path) |
| 170 | 170 |
| 171 return TemporaryDirectory(**kwargs) | 171 return TemporaryDirectory(**kwargs) |
| 172 | 172 |
| 173 def maybe_make_directory(self, *path): | 173 def maybe_make_directory(self, *path): |
| 174 """Create the specified directory if it doesn't already exist.""" | 174 """Create the specified directory if it doesn't already exist.""" |
| 175 try: | 175 try: |
| 176 os.makedirs(self.join(*path)) | 176 os.makedirs(self.join(*path)) |
| 177 except OSError as e: | 177 except OSError as error: |
| 178 if e.errno != errno.EEXIST: | 178 if error.errno != errno.EEXIST: |
| 179 raise | 179 raise |
| 180 | 180 |
| 181 def move(self, source, destination): | 181 def move(self, source, destination): |
| 182 shutil.move(source, destination) | 182 shutil.move(source, destination) |
| 183 | 183 |
| 184 def mtime(self, path): | 184 def mtime(self, path): |
| 185 return os.stat(path).st_mtime | 185 return os.stat(path).st_mtime |
| 186 | 186 |
| 187 def normpath(self, path): | 187 def normpath(self, path): |
| 188 return os.path.normpath(path) | 188 return os.path.normpath(path) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 exceptions.WindowsError | 251 exceptions.WindowsError |
| 252 except AttributeError: | 252 except AttributeError: |
| 253 exceptions.WindowsError = FileSystem._WindowsError | 253 exceptions.WindowsError = FileSystem._WindowsError |
| 254 | 254 |
| 255 retry_timeout_sec = 3.0 | 255 retry_timeout_sec = 3.0 |
| 256 sleep_interval = 0.1 | 256 sleep_interval = 0.1 |
| 257 while True: | 257 while True: |
| 258 try: | 258 try: |
| 259 osremove(path) | 259 osremove(path) |
| 260 return True | 260 return True |
| 261 except exceptions.WindowsError as e: | 261 except exceptions.WindowsError: |
| 262 time.sleep(sleep_interval) | 262 time.sleep(sleep_interval) |
| 263 retry_timeout_sec -= sleep_interval | 263 retry_timeout_sec -= sleep_interval |
| 264 if retry_timeout_sec < 0: | 264 if retry_timeout_sec < 0: |
| 265 raise e | 265 raise |
| 266 | 266 |
| 267 def rmtree(self, path): | 267 def rmtree(self, path): |
| 268 """Delete the directory rooted at path, whether empty or not.""" | 268 """Delete the directory rooted at path, whether empty or not.""" |
| 269 shutil.rmtree(path, ignore_errors=True) | 269 shutil.rmtree(path, ignore_errors=True) |
| 270 | 270 |
| 271 def copytree(self, source, destination): | 271 def copytree(self, source, destination): |
| 272 shutil.copytree(source, destination) | 272 shutil.copytree(source, destination) |
| 273 | 273 |
| 274 def split(self, path): | 274 def split(self, path): |
| 275 """Return (dirname, basename + '.' + ext)""" | 275 """Return (dirname, basename + '.' + ext)""" |
| 276 return os.path.split(path) | 276 return os.path.split(path) |
| 277 | 277 |
| 278 def splitext(self, path): | 278 def splitext(self, path): |
| 279 """Return (dirname + os.sep + basename, '.' + ext)""" | 279 """Return (dirname + os.sep + basename, '.' + ext)""" |
| 280 return os.path.splitext(path) | 280 return os.path.splitext(path) |
| 281 | 281 |
| 282 def make_executable(self, file_path): | 282 def make_executable(self, file_path): |
| 283 os.chmod(file_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_
IRGRP | stat.S_IXGRP) | 283 os.chmod(file_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_
IRGRP | stat.S_IXGRP) |
| OLD | NEW |