Skip to content

Commit

Permalink
Code analysis & reformat
Browse files Browse the repository at this point in the history
- Reformat code
- Drop unnecessary imports
- Spell check

Closes #10
  • Loading branch information
lowell80 committed Nov 9, 2018
1 parent 0d699eb commit 92149b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Local dev env
venv
.python-version
.idea

# Build/dist stuff
.latest_release
Expand Down
24 changes: 14 additions & 10 deletions bin/jpath.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Version 1.0
import splunk.Intersplunk as si
import json, os, sys, itertools
import json
import os
import sys
from itertools import chain

import splunk.Intersplunk as si

ERROR_FIELD = "_jmespath_error"

Expand All @@ -12,20 +13,22 @@
import jmespath
from jmespath.exceptions import ParseError, JMESPathError, UnknownFunctionError


def flatten(container):
if isinstance(container, (list,tuple)):
if isinstance(container, (list, tuple)):
for i in container:
if isinstance(i, (list,tuple)):
if isinstance(i, (list, tuple)):
for j in flatten(i):
yield str(j)
else:
yield str(i)
else:
yield str(container)


if __name__ == '__main__':
try:
keywords,options = si.getKeywordsAndOptions()
keywords, options = si.getKeywordsAndOptions()
defaultval = options.get('default', None)
field = options.get('field', '_raw')
outfield = options.get('outfield', 'jpath')
Expand All @@ -38,11 +41,11 @@ def flatten(container):
jp = jmespath.compile(path)
except ParseError as e:
# Todo: Consider stripping off the last line " ^" pointing to the issue.
# Not helpful since Splunk wrapps the error message in a really ugly way.
si.generateErrorResults("Invalid JMESPath expression '{}'. {}".format(path,e))
# Not helpful since Splunk wraps the error message in a really ugly way.
si.generateErrorResults("Invalid JMESPath expression '{}'. {}".format(path, e))
sys.exit(0)

results,dummyresults,settings = si.getOrganizedResults()
results, dummyresults, settings = si.getOrganizedResults()
# for each results
for result in results:
# get field value
Expand Down Expand Up @@ -75,5 +78,6 @@ def flatten(container):
si.outputResults(results)
except Exception as e:
import traceback
stack = traceback.format_exc()

stack = traceback.format_exc()
si.generateErrorResults("Error '%s'. %s" % (e, stack))

0 comments on commit 92149b1

Please sign in to comment.