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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/filesystem.py

Issue 2014063002: Run format-webkit on webkitpy code (without string conversion). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 import glob 34 import glob
35 import hashlib 35 import hashlib
36 import os 36 import os
37 import shutil 37 import shutil
38 import sys 38 import sys
39 import tempfile 39 import tempfile
40 import time 40 import time
41 41
42 42
43 class FileSystem(object): 43 class FileSystem(object):
44
44 """FileSystem interface for webkitpy. 45 """FileSystem interface for webkitpy.
45 46
46 Unless otherwise noted, all paths are allowed to be either absolute 47 Unless otherwise noted, all paths are allowed to be either absolute
47 or relative.""" 48 or relative."""
48 sep = os.sep 49 sep = os.sep
49 pardir = os.pardir 50 pardir = os.pardir
50 51
51 def abspath(self, path): 52 def abspath(self, path):
52 return os.path.abspath(path) 53 return os.path.abspath(path)
53 54
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 # FIXME: Should we delete non-empty directories? 166 # FIXME: Should we delete non-empty directories?
166 if os.path.exists(self._directory_path): 167 if os.path.exists(self._directory_path):
167 os.rmdir(self._directory_path) 168 os.rmdir(self._directory_path)
168 169
169 return TemporaryDirectory(**kwargs) 170 return TemporaryDirectory(**kwargs)
170 171
171 def maybe_make_directory(self, *path): 172 def maybe_make_directory(self, *path):
172 """Create the specified directory if it doesn't already exist.""" 173 """Create the specified directory if it doesn't already exist."""
173 try: 174 try:
174 os.makedirs(self.join(*path)) 175 os.makedirs(self.join(*path))
175 except OSError, e: 176 except OSError as e:
176 if e.errno != errno.EEXIST: 177 if e.errno != errno.EEXIST:
177 raise 178 raise
178 179
179 def move(self, source, destination): 180 def move(self, source, destination):
180 shutil.move(source, destination) 181 shutil.move(source, destination)
181 182
182 def mtime(self, path): 183 def mtime(self, path):
183 return os.stat(path).st_mtime 184 return os.stat(path).st_mtime
184 185
185 def normpath(self, path): 186 def normpath(self, path):
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 f.write(contents) 229 f.write(contents)
229 230
230 def sha1(self, path): 231 def sha1(self, path):
231 contents = self.read_binary_file(path) 232 contents = self.read_binary_file(path)
232 return hashlib.sha1(contents).hexdigest() 233 return hashlib.sha1(contents).hexdigest()
233 234
234 def relpath(self, path, start='.'): 235 def relpath(self, path, start='.'):
235 return os.path.relpath(path, start) 236 return os.path.relpath(path, start)
236 237
237 class _WindowsError(exceptions.OSError): 238 class _WindowsError(exceptions.OSError):
239
238 """Fake exception for Linux and Mac.""" 240 """Fake exception for Linux and Mac."""
239 pass 241 pass
240 242
241 def remove(self, path, osremove=os.remove): 243 def remove(self, path, osremove=os.remove):
242 """On Windows, if a process was recently killed and it held on to a 244 """On Windows, if a process was recently killed and it held on to a
243 file, the OS will hold on to the file for a short while. This makes 245 file, the OS will hold on to the file for a short while. This makes
244 attempts to delete the file fail. To work around that, this method 246 attempts to delete the file fail. To work around that, this method
245 will retry for a few seconds until Windows is done with the file.""" 247 will retry for a few seconds until Windows is done with the file."""
246 try: 248 try:
247 exceptions.WindowsError 249 exceptions.WindowsError
248 except AttributeError: 250 except AttributeError:
249 exceptions.WindowsError = FileSystem._WindowsError 251 exceptions.WindowsError = FileSystem._WindowsError
250 252
251 retry_timeout_sec = 3.0 253 retry_timeout_sec = 3.0
252 sleep_interval = 0.1 254 sleep_interval = 0.1
253 while True: 255 while True:
254 try: 256 try:
255 osremove(path) 257 osremove(path)
256 return True 258 return True
257 except exceptions.WindowsError, e: 259 except exceptions.WindowsError as e:
258 time.sleep(sleep_interval) 260 time.sleep(sleep_interval)
259 retry_timeout_sec -= sleep_interval 261 retry_timeout_sec -= sleep_interval
260 if retry_timeout_sec < 0: 262 if retry_timeout_sec < 0:
261 raise e 263 raise e
262 264
263 def rmtree(self, path): 265 def rmtree(self, path):
264 """Delete the directory rooted at path, whether empty or not.""" 266 """Delete the directory rooted at path, whether empty or not."""
265 shutil.rmtree(path, ignore_errors=True) 267 shutil.rmtree(path, ignore_errors=True)
266 268
267 def copytree(self, source, destination): 269 def copytree(self, source, destination):
268 shutil.copytree(source, destination) 270 shutil.copytree(source, destination)
269 271
270 def split(self, path): 272 def split(self, path):
271 """Return (dirname, basename + '.' + ext)""" 273 """Return (dirname, basename + '.' + ext)"""
272 return os.path.split(path) 274 return os.path.split(path)
273 275
274 def splitext(self, path): 276 def splitext(self, path):
275 """Return (dirname + os.sep + basename, '.' + ext)""" 277 """Return (dirname + os.sep + basename, '.' + ext)"""
276 return os.path.splitext(path) 278 return os.path.splitext(path)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698