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

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

Issue 1839193004: Run auto-formatter (autopep8) on webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 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 21 matching lines...) Expand all
32 import errno 32 import errno
33 import exceptions 33 import exceptions
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 class FileSystem(object): 43 class FileSystem(object):
43 """FileSystem interface for webkitpy. 44 """FileSystem interface for webkitpy.
44 45
45 Unless otherwise noted, all paths are allowed to be either absolute 46 Unless otherwise noted, all paths are allowed to be either absolute
46 or relative.""" 47 or relative."""
47 sep = os.sep 48 sep = os.sep
48 pardir = os.pardir 49 pardir = os.pardir
49 50
50 def abspath(self, path): 51 def abspath(self, path):
51 return os.path.abspath(path) 52 return os.path.abspath(path)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 This is like tempfile.mkdtemp, but if used in a with statement 141 This is like tempfile.mkdtemp, but if used in a with statement
141 the directory will self-delete at the end of the block (if the 142 the directory will self-delete at the end of the block (if the
142 directory is empty; non-empty directories raise errors). The 143 directory is empty; non-empty directories raise errors). The
143 directory can be safely deleted inside the block as well, if so 144 directory can be safely deleted inside the block as well, if so
144 desired. 145 desired.
145 146
146 Note that the object returned is not a string and does not support all o f the string 147 Note that the object returned is not a string and does not support all o f the string
147 methods. If you need a string, coerce the object to a string and go from there. 148 methods. If you need a string, coerce the object to a string and go from there.
148 """ 149 """
149 class TemporaryDirectory(object): 150 class TemporaryDirectory(object):
151
150 def __init__(self, **kwargs): 152 def __init__(self, **kwargs):
151 self._kwargs = kwargs 153 self._kwargs = kwargs
152 self._directory_path = tempfile.mkdtemp(**self._kwargs) 154 self._directory_path = tempfile.mkdtemp(**self._kwargs)
153 155
154 def __str__(self): 156 def __str__(self):
155 return self._directory_path 157 return self._directory_path
156 158
157 def __enter__(self): 159 def __enter__(self):
158 return self._directory_path 160 return self._directory_path
159 161
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 """Return the contents of the file at the given path as a byte string."" " 198 """Return the contents of the file at the given path as a byte string."" "
197 with file(path, 'rb') as f: 199 with file(path, 'rb') as f:
198 return f.read() 200 return f.read()
199 201
200 def write_binary_file(self, path, contents): 202 def write_binary_file(self, path, contents):
201 with file(path, 'wb') as f: 203 with file(path, 'wb') as f:
202 f.write(contents) 204 f.write(contents)
203 205
204 def open_text_file_for_reading(self, path): 206 def open_text_file_for_reading(self, path):
205 # Note: There appears to be an issue with the returned file objects 207 # Note: There appears to be an issue with the returned file objects
206 # not being seekable. See http://stackoverflow.com/questions/1510188/can -seek-and-tell-work-with-utf-8-encoded-documents-in-python . 208 # not being seekable. See
209 # http://stackoverflow.com/questions/1510188/can-seek-and-tell-work-with -utf-8-encoded-documents-in-python
210 # .
207 return codecs.open(path, 'r', 'utf8') 211 return codecs.open(path, 'r', 'utf8')
208 212
209 def open_text_file_for_writing(self, path): 213 def open_text_file_for_writing(self, path):
210 return codecs.open(path, 'w', 'utf8') 214 return codecs.open(path, 'w', 'utf8')
211 215
212 def read_text_file(self, path): 216 def read_text_file(self, path):
213 """Return the contents of the file at the given path as a Unicode string . 217 """Return the contents of the file at the given path as a Unicode string .
214 218
215 The file is read assuming it is a UTF-8 encoded file with no BOM.""" 219 The file is read assuming it is a UTF-8 encoded file with no BOM."""
216 with codecs.open(path, 'r', 'utf8') as f: 220 with codecs.open(path, 'r', 'utf8') as f:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 def copytree(self, source, destination): 267 def copytree(self, source, destination):
264 shutil.copytree(source, destination) 268 shutil.copytree(source, destination)
265 269
266 def split(self, path): 270 def split(self, path):
267 """Return (dirname, basename + '.' + ext)""" 271 """Return (dirname, basename + '.' + ext)"""
268 return os.path.split(path) 272 return os.path.split(path)
269 273
270 def splitext(self, path): 274 def splitext(self, path):
271 """Return (dirname + os.sep + basename, '.' + ext)""" 275 """Return (dirname + os.sep + basename, '.' + ext)"""
272 return os.path.splitext(path) 276 return os.path.splitext(path)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698