From 1f53c89b14856fa2dab67e615809097f2c24d09b Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Wed, 14 Mar 2012 00:39:18 -0400 Subject: [PATCH] convert so they handle argsfiles rather than arguments --- library/command | 22 +++++++++++++++++++++- library/git | 25 ++++++++++++++++++++++++- library/service | 29 +++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/library/command b/library/command index 7413db7b94e..904a44c6bfa 100755 --- a/library/command +++ b/library/command @@ -27,6 +27,8 @@ import subprocess import sys import datetime import traceback +import shlex +import os if len(sys.argv) == 1: print json.dumps({ @@ -35,7 +37,25 @@ if len(sys.argv) == 1: }) sys.exit(1) -args = sys.argv[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: diff --git a/library/git b/library/git index 9fe4ba7437f..5a25915a3fb 100755 --- a/library/git +++ b/library/git @@ -37,8 +37,31 @@ import subprocess # to a dictionary # FIXME: make more idiomatic -args = " ".join(sys.argv[1:]) +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() items = shlex.split(args) + +if not len(items): + print json.dumps({ + "failed" : True, + "msg" : "the command module requires arguments (-a)" + }) + sys.exit(1) + params = {} for x in items: (k, v) = x.split("=") diff --git a/library/service b/library/service index 5572df0ea43..bb609a868de 100755 --- a/library/service +++ b/library/service @@ -31,8 +31,33 @@ import subprocess # to a dictionary # FIXME: make more idiomatic -args = " ".join(sys.argv[1:]) -items = shlex.split(args) + +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() +itmes = shlex.split(args) + +if not len(items): + print json.dumps({ + "failed" : True, + "msg" : "the command module requires arguments (-a)" + }) + sys.exit(1) + + params = {} for x in items: (k, v) = x.split("=")