Commit 7b9c2c8220f13abe2e8c3797c1bdfcd4be7893ff
1 parent
5f04230e
Add docstring and improve log_object_data a little
Showing
1 changed file
with
19 additions
and
2 deletions
| @@ -58,10 +58,27 @@ def compare_date(data1, data2): | @@ -58,10 +58,27 @@ def compare_date(data1, data2): | ||
| 58 | return False | 58 | return False |
| 59 | return True | 59 | return True |
| 60 | 60 | ||
| 61 | -def log_object_data(data, file_name="", format="yaml"): | 61 | +def log_object_data(data, file_name=None, format="yaml"): |
| 62 | + """Log object data in pretty format (JSON or YAML) | ||
| 63 | + | ||
| 64 | + Two output formats are supported: "yaml" and "json". | ||
| 65 | + | ||
| 66 | + If a file name is specified, the output is written into that file. | ||
| 67 | + | ||
| 68 | + If you would like to get similar output everywhere, | ||
| 69 | + use the following snippet somewhere in your code | ||
| 70 | + before actually using Munch. For instance, | ||
| 71 | + put it into your __init__.py, or, if you use zc.buildout, | ||
| 72 | + specify it in "initialization" setting of zc.recipe.egg. | ||
| 73 | + | ||
| 74 | + from munch import Munch | ||
| 75 | + Munch.__str__ = lambda self: Munch.toYAML(self, allow_unicode=True, | ||
| 76 | + default_flow_style=False) | ||
| 77 | + Munch.__repr__ = Munch.__str__ | ||
| 78 | + """ | ||
| 62 | if not isinstance(data, Munch): | 79 | if not isinstance(data, Munch): |
| 63 | data = munchify(data) | 80 | data = munchify(data) |
| 64 | - if format == 'json': | 81 | + if format.lower() == 'json': |
| 65 | data = data.toJSON(indent=2) | 82 | data = data.toJSON(indent=2) |
| 66 | else: | 83 | else: |
| 67 | data = data.toYAML(allow_unicode=True, default_flow_style=False) | 84 | data = data.toYAML(allow_unicode=True, default_flow_style=False) |
Please
register
or
login
to post a comment