Commit f1ec6a94 authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

Write CL description into a temporary file

Also add open_text_tempfile() to FileSystem and its mock.

Bug: 780055
Change-Id: Ib6083639ab3774b468d6b6dc1cb41d818a1b0651
Reviewed-on: https://chromium-review.googlesource.com/747522Reviewed-by: default avatarQuinten Yearsley <qyearsley@chromium.org>
Commit-Queue: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512945}
parent a92fe336
...@@ -194,7 +194,7 @@ class FileSystem(object): ...@@ -194,7 +194,7 @@ class FileSystem(object):
def normpath(self, path): def normpath(self, path):
return os.path.normpath(path) return os.path.normpath(path)
def open_binary_tempfile(self, suffix): def open_binary_tempfile(self, suffix=''):
"""Create, open, and return a binary temp file. Returns a tuple of the file and the name.""" """Create, open, and return a binary temp file. Returns a tuple of the file and the name."""
temp_fd, temp_name = tempfile.mkstemp(suffix) temp_fd, temp_name = tempfile.mkstemp(suffix)
f = os.fdopen(temp_fd, 'wb') f = os.fdopen(temp_fd, 'wb')
...@@ -215,6 +215,12 @@ class FileSystem(object): ...@@ -215,6 +215,12 @@ class FileSystem(object):
with file(path, 'wb') as f: with file(path, 'wb') as f:
f.write(contents) f.write(contents)
def open_text_tempfile(self, suffix=''):
"""Create, open, and return a text temp file. Returns a tuple of the file and the name."""
_, temp_name = tempfile.mkstemp(suffix)
f = codecs.open(temp_name, 'w', 'utf8')
return f, temp_name
def open_text_file_for_reading(self, path): def open_text_file_for_reading(self, path):
# Note: There appears to be an issue with the returned file objects # Note: There appears to be an issue with the returned file objects
# not being seekable. See # not being seekable. See
......
...@@ -337,6 +337,10 @@ class MockFileSystem(object): ...@@ -337,6 +337,10 @@ class MockFileSystem(object):
self.files[path] = contents self.files[path] = contents
self.written_files[path] = contents self.written_files[path] = contents
def open_text_tempfile(self, suffix=''):
path = self.mktemp(suffix)
return (WritableTextFileObject(self, path), path)
def open_text_file_for_reading(self, path): def open_text_file_for_reading(self, path):
if self.files[path] is None: if self.files[path] is None:
self._raise_not_found(path) self._raise_not_found(path)
......
...@@ -433,17 +433,24 @@ class TestImporter(object): ...@@ -433,17 +433,24 @@ class TestImporter(object):
directory_owners = self.get_directory_owners() directory_owners = self.get_directory_owners()
description = self._cl_description(directory_owners) description = self._cl_description(directory_owners)
sheriff_email = self.tbr_reviewer() sheriff_email = self.tbr_reviewer()
temp_file, temp_path = self.fs.open_text_tempfile()
temp_file.write(description)
temp_file.close()
self.git_cl.run([ self.git_cl.run([
'upload', 'upload',
'-f', '-f',
'--gerrit', '--gerrit',
'-m', description, '--message-file', temp_path,
'--tbrs', sheriff_email, '--tbrs', sheriff_email,
# Note: we used to CC all the directory owners, but have stopped # Note: we used to CC all the directory owners, but have stopped
# in search of a better notification mechanism. (crbug.com/765334) # in search of a better notification mechanism. (crbug.com/765334)
'--cc', 'robertma@chromium.org', '--cc', 'robertma@chromium.org',
]) ])
self.fs.remove(temp_path)
def get_directory_owners(self): def get_directory_owners(self):
"""Returns a mapping of email addresses to owners of changed tests.""" """Returns a mapping of email addresses to owners of changed tests."""
_log.info('Gathering directory owners emails to CC.') _log.info('Gathering directory owners emails to CC.')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment