diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-07-31 15:53:32 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-07-31 15:53:32 +0300 |
commit | 7d799b85d6644fc1676b21277ce758b5bd313a5b (patch) | |
tree | 48afc3f9221a1d20e4133937903f9ec4948159cc /slog-pretty | |
parent | df26f3c4af7d4ca34a3ffd85a91a600590623d3b (diff) | |
download | slog-7d799b85d6644fc1676b21277ce758b5bd313a5b.tar.gz |
Add: scripts to handle slog files
Diffstat (limited to 'slog-pretty')
-rwxr-xr-x | slog-pretty | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/slog-pretty b/slog-pretty new file mode 100755 index 0000000..80f07fb --- /dev/null +++ b/slog-pretty @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import json +import sys + +import yaml + + +def text_representer(dumper, data): + if '\n' in data: + return dumper.represent_scalar( + u'tag:yaml.org,2002:str', data, style='|') + return dumper.represent_scalar( + u'tag:yaml.org,2002:str', data, style='') + +yaml.add_representer(str, text_representer) +yaml.add_representer(unicode, text_representer) + + +def dump(f): + for line in f: + obj = json.loads(line.strip()) + yaml.dump( + obj, stream=sys.stdout, indent=4, default_flow_style=False, + explicit_start=True, explicit_end=True) + + +if len(sys.argv) == 1: + dump(sys.stdin) +else: + for filename in sys.argv[1:]: + with open(filename) as f: + dump(f) |