From 56238ddfefb4022bd96f9aabc1b89c8104f86bd0 Mon Sep 17 00:00:00 2001 From: Ramin Yaghoubzadeh <ryaghoubzadeh@uni-bielefeld.de> Date: Thu, 28 Apr 2016 18:29:58 +0200 Subject: [PATCH] New 'ipaaca-catlog' utility: pretty-print / minimal console log filter Arguments: --delimiter delim field delimiter, default '\t' --strip call strip() in each field first --fields name1 [name2 [...]] fields to print (in order) defaults to: 'time' 'text' --- ipaacatools/scripts/ipaaca-catlog | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 ipaacatools/scripts/ipaaca-catlog diff --git a/ipaacatools/scripts/ipaaca-catlog b/ipaacatools/scripts/ipaaca-catlog new file mode 100755 index 0000000..72da768 --- /dev/null +++ b/ipaacatools/scripts/ipaaca-catlog @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# This file is part of IPAACA, the +# "Incremental Processing Architecture +# for Artificial Conversational Agents". +# +# Copyright (c) 2009-2015 Social Cognitive Systems Group +# CITEC, Bielefeld University +# +# http://opensource.cit-ec.de/projects/ipaaca/ +# http://purl.org/net/ipaaca +# +# This file may be licensed under the terms of of the +# GNU Lesser General Public License Version 3 (the ``LGPL''), +# or (at your option) any later version. +# +# Software distributed under the License is distributed +# on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either +# express or implied. See the LGPL for the specific language +# governing rights and limitations. +# +# You should have received a copy of the LGPL along with this +# program. If not, go to http://www.gnu.org/licenses/lgpl.html +# or write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# The development of this software was supported by the +# Excellence Cluster EXC 277 Cognitive Interaction Technology. +# The Excellence Cluster EXC 277 is a grant of the Deutsche +# Forschungsgemeinschaft (DFG) in the context of the German +# Excellence Initiative. + + +from __future__ import division, print_function + +import sys +import ipaaca + +if __name__=='__main__': + iap = ipaaca.IpaacaArgumentParser( + 'ipaaca-logcat') + iap.add_argument( + '-s', '--strip-fields', + dest='strip', action='store_true', + default=False, + help='strip leading/trailing whitespace from all fields') + iap.add_argument( + '-d', '--delimiter', + dest='delimiter', nargs=1, + default=['\t'], + help='field delimiter, interpreted as python unicode string (default \'\\t\')') + iap.add_argument( + '-f', '--fields', + dest='fields', default=['time', 'text'], nargs='+', + help='fields to print (defaults: \'time\' \'text\')') + arguments = iap.parse_args() + delimiter = eval("u'"+arguments.delimiter[0]+"'", {"__builtins__":None}, {} ) + #print(arguments); sys.exit(1) + modify = (lambda s: s.strip()) if arguments.strip else (lambda s: s) + #modify = lambda s: type(s).__name__ + for line in sys.stdin: + record = eval(line.strip(), {"__builtins__":None}, {} ) + print(delimiter.join([modify(unicode(record[f])) for f in arguments.fields])) + -- GitLab