Index: master/skia_master_scripts/utils.py |
=================================================================== |
--- master/skia_master_scripts/utils.py (revision 8776) |
+++ master/skia_master_scripts/utils.py (working copy) |
@@ -46,6 +46,57 @@ |
return builder_name.endswith(TRYBOT_NAME_SUFFIX) |
borenet
2013/04/25 15:50:28
Helpers for dumping out the dictionary. We need t
|
+def IndentStr(indent): |
rmistry
2013/04/25 17:31:50
private function?
The only one that looks useful h
borenet
2013/04/25 18:28:09
Done.
|
+ string = '' |
+ for _ in range(indent + 1): |
+ string += ' ' |
+ return string |
+ |
+ |
+def ToString(o, indent=0): |
rmistry
2013/04/25 17:31:50
If this is going to be the only public function le
borenet
2013/04/25 18:28:09
Done.
|
+ if isinstance(o, list): |
+ return ListToString(o, indent) |
+ elif isinstance(o, dict): |
+ return DictToString(o, indent) |
+ elif isinstance(o, tuple): |
+ return ListToString(o, indent) |
+ elif isinstance(o, str): |
+ return '\'%s\'' % o |
+ elif o is None: |
+ return 'None' |
+ else: |
+ return '<Object>' |
+ |
+ |
+def ListToString(l, indent): |
rmistry
2013/04/25 17:31:50
private function?
borenet
2013/04/25 18:28:09
Done.
|
+ if not l: |
+ return '[]' |
+ indent_str = IndentStr(indent) |
+ val = '[\n' |
+ indent += 1 |
+ val += ''.join(['%s%s,\n' % (indent_str, ToString(elem, indent)) \ |
+ for elem in l]) |
+ indent -= 1 |
+ indent_str = IndentStr(indent - 1) |
+ val += indent_str + ']' |
+ return val |
+ |
+ |
+def DictToString(d, indent): |
rmistry
2013/04/25 17:31:50
private function?
borenet
2013/04/25 18:28:09
Done.
|
+ if not d: |
+ return '{}' |
+ indent_str = IndentStr(indent) |
+ val = '{\n' |
+ indent += 1 |
+ val += ''.join(['%s%s: %s,\n' % (indent_str, ToString(k, indent), |
+ ToString(d[k], indent)) \ |
+ for k in sorted(d.keys())]) |
+ indent -= 1 |
+ indent_str = IndentStr(indent - 1) |
+ val += indent_str + '}' |
+ return val |
+ |
+ |
class SkiaChangeFilter(ChangeFilter): |
"""Skia specific subclass of ChangeFilter.""" |