From 26816b72ecc28e85f6a51b9884fd6210388e8d23 Mon Sep 17 00:00:00 2001 From: "Nathan A. Feger" Date: Wed, 20 Jun 2012 14:17:15 -0500 Subject: [PATCH] attempt to make copy more idiomatic. --- library/copy | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/library/copy b/library/copy index f9c85ef2bb..495117fca5 100755 --- a/library/copy +++ b/library/copy @@ -28,11 +28,21 @@ import syslog # to a dictionary # FIXME: make more idiomatic +def dump_kv(vars): + return " ".join("%s='%s'" % (k,v) for (k,v) in vars.items()) + +def exit_kv(rc=0, **kwargs): + if 'path' in kwargs: + add_path_info(kwargs) + print dump_kv(kwargs) + sys.exit(rc) + if len(sys.argv) == 1: - sys.exit(1) + exit_kv(rc=1, failed=1, msg="incorrect number of arguments given") + argfile = sys.argv[1] if not os.path.exists(argfile): - sys.exit(1) + exit_kv(rc=1, failed=1, msg="file %s does not exist" % (argfile)) args = open(argfile, 'r').read() items = shlex.split(args) @@ -54,8 +64,7 @@ if dest: # raise an error if there is no src file if not os.path.exists(src): - print "failed=1 msg='Source %s failed to transfer'" % src - sys.exit(1) + exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src)) md5sum = None changed = False @@ -69,6 +78,7 @@ if md5sum != md5sum2: changed = True # mission accomplished -print "md5sum=%s changed=%s" % (md5sum2, changed) +#print "md5sum=%s changed=%s" % (md5sum2, changed) +exit_kv(dest=dest, src=src, changed="md5sum=%s changed=%s" % (md5sum2, changed))