From 842d7cca6f5afe5c4fb06665edfc7b21d956b0f5 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 14 Mar 2012 19:57:56 -0400 Subject: [PATCH] Fix async to use the new argfiles method (wrapping brain around rock, really must write module development guide) --- async_status | 10 +++++----- async_wrapper | 16 ++++++++-------- command | 22 ---------------------- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/async_status b/async_status index 8959ec97b19..74732b669bc 100755 --- a/async_status +++ b/async_status @@ -30,12 +30,12 @@ import datetime import traceback # =========================================== -# convert arguments of form a=b c=d -# to a dictionary -# FIXME: make more idiomatic -args = " ".join(sys.argv[1:]) -items = shlex.split(args) +# FIXME: better error handling + +argsfile = sys.argv[1] +items = shlex.split(file(argsfile).read()) + params = {} for x in items: (k, v) = x.split("=") diff --git a/async_wrapper b/async_wrapper index d6dbd8c6761..eea9396ab22 100755 --- a/async_wrapper +++ b/async_wrapper @@ -66,16 +66,15 @@ def daemonize_self(): if len(sys.argv) < 3: print json.dumps({ "failed" : True, - "msg" : "usage: async_wrapper . Humans, do not call directly!" + "msg" : "usage: async_wrapper . Humans, do not call directly!" }) sys.exit(1) jid = sys.argv[1] time_limit = sys.argv[2] wrapped_module = sys.argv[3] -args = sys.argv[4:] - -cmd = "%s %s" % (wrapped_module, " ".join(args)) +argsfile = sys.argv[4] +cmd = "%s %s" % (wrapped_module, argsfile) # setup logging directory logdir = os.path.expanduser("~/.ansible_async") @@ -92,20 +91,20 @@ if not os.path.exists(logdir): def _run_command(wrapped_cmd, jid, log_path): - print "RUNNING: %s" % wrapped_cmd logfile = open(log_path, "w") logfile.write(json.dumps({ "started" : 1, "ansible_job_id" : jid })) logfile.close() logfile = open(log_path, "w") result = {} - + + outdata = '' try: cmd = shlex.split(wrapped_cmd) script = subprocess.Popen(cmd, shell=False, stdin=None, stdout=logfile, stderr=logfile) script.communicate() - #result = json.loads(out) - result = json.loads(file(log_path).read()) + outdata = file(log_path).read() + result = json.loads(outdata) except (OSError, IOError), e: result = { @@ -119,6 +118,7 @@ def _run_command(wrapped_cmd, jid, log_path): result = { "failed" : 1, "cmd" : wrapped_cmd, + "data" : outdata, # temporary debug only "msg" : traceback.format_exc() } result['ansible_job_id'] = jid diff --git a/command b/command index 904a44c6bfa..06f5d656363 100755 --- a/command +++ b/command @@ -30,32 +30,10 @@ import traceback import shlex import os -if len(sys.argv) == 1: - print json.dumps({ - "failed" : True, - "msg" : "the command module requires arguments (-a)" - }) - sys.exit(1) - argfile = sys.argv[1] -if not os.path.exists(argfile): - print json.dumps({ - "failed" : True, - "msg" : "Argument file not found" - }) - sys.exit(1) - args = open(argfile, 'r').read() args = shlex.split(args) -if not len(args): - print json.dumps({ - "failed" : True, - "msg" : "the command module requires arguments (-a)" - }) - sys.exit(1) - - startd = datetime.datetime.now() try: