| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 # FIXME: Should we delete non-empty directories? | 165 # FIXME: Should we delete non-empty directories? |
| 166 if os.path.exists(self._directory_path): | 166 if os.path.exists(self._directory_path): |
| 167 os.rmdir(self._directory_path) | 167 os.rmdir(self._directory_path) |
| 168 | 168 |
| 169 return TemporaryDirectory(**kwargs) | 169 return TemporaryDirectory(**kwargs) |
| 170 | 170 |
| 171 def maybe_make_directory(self, *path): | 171 def maybe_make_directory(self, *path): |
| 172 """Create the specified directory if it doesn't already exist.""" | 172 """Create the specified directory if it doesn't already exist.""" |
| 173 try: | 173 try: |
| 174 os.makedirs(self.join(*path)) | 174 os.makedirs(self.join(*path)) |
| 175 except OSError, e: | 175 except OSError as e: |
| 176 if e.errno != errno.EEXIST: | 176 if e.errno != errno.EEXIST: |
| 177 raise | 177 raise |
| 178 | 178 |
| 179 def move(self, source, destination): | 179 def move(self, source, destination): |
| 180 shutil.move(source, destination) | 180 shutil.move(source, destination) |
| 181 | 181 |
| 182 def mtime(self, path): | 182 def mtime(self, path): |
| 183 return os.stat(path).st_mtime | 183 return os.stat(path).st_mtime |
| 184 | 184 |
| 185 def normpath(self, path): | 185 def normpath(self, path): |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 exceptions.WindowsError | 247 exceptions.WindowsError |
| 248 except AttributeError: | 248 except AttributeError: |
| 249 exceptions.WindowsError = FileSystem._WindowsError | 249 exceptions.WindowsError = FileSystem._WindowsError |
| 250 | 250 |
| 251 retry_timeout_sec = 3.0 | 251 retry_timeout_sec = 3.0 |
| 252 sleep_interval = 0.1 | 252 sleep_interval = 0.1 |
| 253 while True: | 253 while True: |
| 254 try: | 254 try: |
| 255 osremove(path) | 255 osremove(path) |
| 256 return True | 256 return True |
| 257 except exceptions.WindowsError, e: | 257 except exceptions.WindowsError as e: |
| 258 time.sleep(sleep_interval) | 258 time.sleep(sleep_interval) |
| 259 retry_timeout_sec -= sleep_interval | 259 retry_timeout_sec -= sleep_interval |
| 260 if retry_timeout_sec < 0: | 260 if retry_timeout_sec < 0: |
| 261 raise e | 261 raise e |
| 262 | 262 |
| 263 def rmtree(self, path): | 263 def rmtree(self, path): |
| 264 """Delete the directory rooted at path, whether empty or not.""" | 264 """Delete the directory rooted at path, whether empty or not.""" |
| 265 shutil.rmtree(path, ignore_errors=True) | 265 shutil.rmtree(path, ignore_errors=True) |
| 266 | 266 |
| 267 def copytree(self, source, destination): | 267 def copytree(self, source, destination): |
| 268 shutil.copytree(source, destination) | 268 shutil.copytree(source, destination) |
| 269 | 269 |
| 270 def split(self, path): | 270 def split(self, path): |
| 271 """Return (dirname, basename + '.' + ext)""" | 271 """Return (dirname, basename + '.' + ext)""" |
| 272 return os.path.split(path) | 272 return os.path.split(path) |
| 273 | 273 |
| 274 def splitext(self, path): | 274 def splitext(self, path): |
| 275 """Return (dirname + os.sep + basename, '.' + ext)""" | 275 """Return (dirname + os.sep + basename, '.' + ext)""" |
| 276 return os.path.splitext(path) | 276 return os.path.splitext(path) |
| OLD | NEW |