Get rid of gcl.ReadFile.

Review URL: http://codereview.chromium.org/501106

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@34950 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent fc83c11b37
commit 0fca4f3746

@ -141,7 +141,7 @@ def GetCachedFile(filename, max_age=60*60*24*3, use_root=False):
# fetch it each time.
gclient_utils.FileWrite(cached_file, content)
else:
content = ReadFile(cached_file)
content = gclient_utils.FileRead(cached_file, 'r')
# Keep the content cached in memory.
FILES_CACHE[filename] = content
return FILES_CACHE[filename]
@ -205,14 +205,6 @@ def RunShell(command, print_output=False):
return RunShellWithReturnCode(command, print_output)[0]
def ReadFile(filename, flags='r'):
"""Returns the contents of a file."""
f = open(filename, flags)
result = f.read()
f.close()
return result
def FilterFlag(args, flag):
"""Returns True if the flag is present in args list.
@ -416,7 +408,8 @@ class ChangeInfo(object):
ErrorExit("Changelist " + changename + " not found.")
return ChangeInfo(changename, 0, 0, '', None, local_root,
needs_upload=False)
split_data = ReadFile(info_file).split(ChangeInfo._SEPARATOR, 2)
split_data = gclient_utils.FileRead(info_file, 'r').split(
ChangeInfo._SEPARATOR, 2)
if len(split_data) != 3:
ErrorExit("Changelist file %s is corrupt" % info_file)
items = split_data[0].split(', ')
@ -1012,7 +1005,7 @@ def Change(change_info, args):
if not silent:
os.system(GetEditor() + " " + filename)
result = ReadFile(filename)
result = gclient_utils.FileRead(filename, 'r')
os.remove(filename)
if not result:

@ -416,11 +416,7 @@ class SVN(object):
# We know the diff will be incorrectly formatted. Fix it.
if SVN.IsMoved(filename):
# The file is "new" in the patch sense. Generate a homebrew diff.
# We can't use ReadFile() since it's not using binary mode.
file_handle = open(filename, 'rb')
file_content = file_handle.read()
file_handle.close()
file_content = gclient_utils.FileRead(filename, 'rb')
# Prepend '+' to every lines.
file_content = ['+' + i for i in file_content.splitlines(True)]
nb_lines = len(file_content)

@ -19,7 +19,7 @@ class GclTestsBase(SuperMoxTestBase):
self.mox.StubOutWithMock(gcl.SVN, 'CaptureInfo')
self.mox.StubOutWithMock(gcl, 'tempfile')
self.mox.StubOutWithMock(gcl.upload, 'RealMain')
self.mox.StubOutWithMock(gcl, 'ReadFile')
self.mox.StubOutWithMock(gcl.gclient_utils, 'FileRead')
self.mox.StubOutWithMock(gcl.gclient_utils, 'FileWrite')
@ -38,7 +38,7 @@ class GclUnittest(GclTestsBase):
'GetModifiedFiles', 'GetRepositoryRoot', 'Help', 'Lint',
'LoadChangelistInfoForMultiple', 'MISSING_TEST_MSG', 'Opened',
'OptionallyDoPresubmitChecks', 'PresubmitCL', 'REPOSITORY_ROOT',
'ReadFile', 'RunShell', 'RunShellWithReturnCode', 'SVN',
'RunShell', 'RunShellWithReturnCode', 'SVN',
'SendToRietveld', 'TryChange', 'UnknownFiles', 'UploadCL', 'Warn',
'breakpad', 'gclient_utils', 'getpass', 'main', 'os', 'random', 're',
'shutil', 'string', 'subprocess', 'sys', 'tempfile', 'upload',
@ -185,7 +185,7 @@ class ChangeInfoUnittest(GclTestsBase):
description = ["This is some description.", "force an extra separator."]
gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.ReadFile('bleeeh').AndReturn(
gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["42, 53", "G b.cc"] + description))
self.mox.ReplayAll()
@ -200,7 +200,7 @@ class ChangeInfoUnittest(GclTestsBase):
def testLoadEmpty(self):
gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh')
gcl.os.path.exists('bleeeh').AndReturn(True)
gcl.ReadFile('bleeeh').AndReturn(
gcl.gclient_utils.FileRead('bleeeh', 'r').AndReturn(
gcl.ChangeInfo._SEPARATOR.join(["", "", ""]))
self.mox.ReplayAll()

@ -49,9 +49,8 @@ def GetPreferredTrySlaves():
presubmit.os.chdir = MockChdir
self.mox.StubOutWithMock(presubmit.scm.SVN, 'CaptureInfo')
self.mox.StubOutWithMock(presubmit.scm.SVN, 'GetFileProperty')
# TODO(maruel): Err, small duplication of code here.
self.mox.StubOutWithMock(presubmit.gcl, 'ReadFile')
self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileRead')
self.mox.StubOutWithMock(presubmit.gclient_utils, 'FileWrite')
class PresubmitUnittest(PresubmitTestsBase):

@ -520,7 +520,7 @@ def TryChange(argv,
if options.url:
options.diff = urllib.urlopen(options.url).read()
elif options.diff:
options.diff = gcl.ReadFile(options.diff)
options.diff = gcl.gclient_utils.FileRead(options.diff, 'rb')
# Process the VCS in any case at least to retrieve the email address.
try:
options.scm = GuessVCS(options)

Loading…
Cancel
Save