gerrit: handle unicode messages
Using str() on unicode strings fails. Tweak how we do things to work
with both ascii and utf-8 and integers.
BUG=None
TEST=`USER=marcheu gerrit todo` works (handles message in CL:60715)
Change-Id: I20bd116c31e5383fa95b26f6a33d51c1052ea3af
Reviewed-on: https://chromium-review.googlesource.com/173812
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Tested-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/scripts/gerrit.py b/scripts/gerrit.py
index 0ab4183..c3eeb93 100644
--- a/scripts/gerrit.py
+++ b/scripts/gerrit.py
@@ -58,7 +58,9 @@
lims = {}
for cl in cls:
for k in cl.keys():
- lims[k] = max(lims.get(k, 0), len(str(cl[k])))
+ # Use %s rather than str() to avoid codec issues.
+ # We also do this so we can format integers.
+ lims[k] = max(lims.get(k, 0), len('%s' % cl[k]))
return lims