|
|
@@ -43,18 +43,8 @@ import shlex
|
|
|
import re
|
|
|
import signal
|
|
|
|
|
|
-__VERSION__ = '1.1.0'
|
|
|
-
|
|
|
-def pretty(d, indent=0, indenter=' ' * 4):
|
|
|
- info_str = ''
|
|
|
- for key, value in list(d.items()):
|
|
|
- info_str += indenter * indent + str(key)
|
|
|
- if isinstance(value, dict):
|
|
|
- info_str += '/\n'
|
|
|
- info_str += pretty(value, indent + 1, indenter)
|
|
|
- else:
|
|
|
- info_str += ': ' + str(value) + '\n'
|
|
|
- return info_str
|
|
|
+
|
|
|
+__VERSION__ = '1.1.5'
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
@@ -198,13 +188,19 @@ def get_arguments_from_options(options, **kwargs):
|
|
|
arguments['check'] = 1
|
|
|
arguments['unit'] = options.unit
|
|
|
|
|
|
+ args = list((k, v) for k, v in list(arguments.items()) if v is not None)
|
|
|
+
|
|
|
+ # Get the options (comma separated)
|
|
|
if options.queryargs:
|
|
|
- for argument in options.queryargs.split(','):
|
|
|
- key, value = argument.split('=')
|
|
|
- arguments[key] = value
|
|
|
+ # for each comma, perform lookahead, split iff we aren't inside quotes.
|
|
|
+ arguments_list = re.split(''',(?=(?:[^'"]|'[^']*'|"[^"]*")*$)''', options.queryargs)
|
|
|
+ for argument in arguments_list:
|
|
|
+ key, value = argument.split('=', 1)
|
|
|
+ if value is not None:
|
|
|
+ args.append((key, value))
|
|
|
|
|
|
#~ Encode the items in the dictionary that are not None
|
|
|
- return urlencode(dict((k, v) for k, v in list(arguments.items()) if v is not None))
|
|
|
+ return urlencode(args)
|
|
|
|
|
|
|
|
|
def get_json(options):
|
|
|
@@ -233,8 +229,15 @@ def get_json(options):
|
|
|
|
|
|
arr = json.loads(ret)
|
|
|
|
|
|
+ # Fix for NCPA < 2
|
|
|
if 'value' in arr:
|
|
|
- return arr['value']
|
|
|
+ arr = arr['value']
|
|
|
+
|
|
|
+ # We need to flip the returncode and stdout
|
|
|
+ if isinstance(arr['stdout'], int) and not isinstance(arr['returncode'], int):
|
|
|
+ tmp = arr['returncode']
|
|
|
+ arr['returncode'] = arr['stdout']
|
|
|
+ arr['stdout'] = tmp
|
|
|
|
|
|
return arr
|
|
|
|
|
|
@@ -250,13 +253,13 @@ def show_list(info_json):
|
|
|
"""Show the list of available options.
|
|
|
|
|
|
"""
|
|
|
- return pretty(info_json), 0
|
|
|
+ return json.dumps(info_json, indent=4), 0
|
|
|
|
|
|
|
|
|
def timeout_handler(threshold):
|
|
|
def wrapped(signum, frames):
|
|
|
stdout = "UNKNOWN: Execution exceeded timeout threshold of %ds" % threshold
|
|
|
- print stdout
|
|
|
+ print(stdout)
|
|
|
sys.exit(3)
|
|
|
return wrapped
|
|
|
|
|
|
@@ -285,7 +288,7 @@ def main():
|
|
|
return "{}{}".format(stdout, performance), returncode
|
|
|
else:
|
|
|
return stdout, returncode
|
|
|
- except Exception, e:
|
|
|
+ except Exception as e:
|
|
|
if options.debug:
|
|
|
return 'The stack trace:' + traceback.format_exc(), 3
|
|
|
elif options.verbose:
|