[asterisk-commits] mjordan: testsuite/asterisk/trunk r3627 - /asterisk/trunk/contrib/scripts/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 29 16:04:40 CST 2013


Author: mjordan
Date: Tue Jan 29 16:04:36 2013
New Revision: 3627

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3627
Log:
Add a script that converts a CEL log into a YAML blob

You'll still probably want to format it a bit, and it may need
some TLC, but it is better than doing it all by hand.

Added:
    asterisk/trunk/contrib/scripts/
    asterisk/trunk/contrib/scripts/cel-to-yaml.py   (with props)

Added: asterisk/trunk/contrib/scripts/cel-to-yaml.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/contrib/scripts/cel-to-yaml.py?view=auto&rev=3627
==============================================================================
--- asterisk/trunk/contrib/scripts/cel-to-yaml.py (added)
+++ asterisk/trunk/contrib/scripts/cel-to-yaml.py Tue Jan 29 16:04:36 2013
@@ -1,0 +1,57 @@
+#!/usr/bin/env python
+"""Script that turns a CEL CSV file into a blob of YAML suitable
+for parsing by the CELModule
+
+Copyright (C) 2013, Digium, Inc.
+Matt Jordan <mjordan at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import sys
+import os
+import optparse
+import yaml
+
+def main(argv=None):
+    if argv is None:
+        args = sys.argv
+
+    parser = optparse.OptionParser()
+    parser.add_option("-i", "--input",
+            dest="input_file",
+            help="Specify the input CEL file to process")
+    parser.add_option("-c", "--column", action="append",
+            dest="columns",
+            help="Add a column to the output. Can be used multiple times.")
+    (options, args) = parser.parse_args(argv)
+
+    columns = ["eventtype", "cidname", "cidnum", "dnid", "exten", "context",
+               "channel", "app"]
+    if options.columns:
+        for c in options.columns:
+            columns.append(c)
+    fields = ['eventtype', 'eventtime', 'cidname', 'cidnum', 'ani', 'rdnis',
+    'dnid', 'exten', 'context', 'channel', 'app', 'appdata', 'amaflags',
+    'accountcode', 'uniqueid', 'linkedid', 'bridgepeer', 'userfield',
+    'userdeftype', 'eventextra']
+
+    input_file = open(options.input_file)
+    result = []
+    for line in input_file.readlines():
+        tokens = line.split(',')
+        blob = {}
+        for column in columns:
+            index = fields.index(column)
+            blob[column] = str(tokens[index].replace('"','').strip())
+        result.append(blob)
+    raw_yaml = yaml.dump(result)
+    raw_yaml = raw_yaml.replace(',', '\n').replace('}', '').replace('{', '')
+    print raw_yaml
+
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)

Propchange: asterisk/trunk/contrib/scripts/cel-to-yaml.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/contrib/scripts/cel-to-yaml.py
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/contrib/scripts/cel-to-yaml.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/contrib/scripts/cel-to-yaml.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list