Decode datetime string when it's not utf-8

If the encoding is not utf-8, datatime_now() will yield

> 'now': '2019-05-17 \xbf\xc0\xc0\xfc 11:28:31'(with CP949),

and it fails to decode it with utf-8 afterward.

>  traces_readme, TRACES_README_FORMAT % git_push_metadata)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xbf in position 17: invalid start byte

For further information, please check out
https://bugs.chromium.org/p/chromium/issues/detail?id=955206#c16

Bug: 955206
Change-Id: I2733849735adc0361140b042ce617522c58fcc78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1621576
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
changes/76/1621576/10
sangwoo.ko 6 years ago committed by Commit Bot
parent c9e2283502
commit 7a6143385d

@ -2552,6 +2552,10 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
git_info_zip = trace_name + '-git-info'
git_push_metadata['now'] = datetime_now().strftime('%c')
if sys.stdin.encoding != 'utf-8':
git_push_metadata['now'] = git_push_metadata['now'].decode(
sys.stdin.encoding)
git_push_metadata['trace_name'] = trace_name
gclient_utils.FileWrite(
traces_readme, TRACES_README_FORMAT % git_push_metadata)

Loading…
Cancel
Save