Merge pull request #495 from nafeger/devel

make copy module implemented closer to other newer modules when returning results
This commit is contained in:
Michael DeHaan 2012-06-20 13:12:24 -07:00
commit 46fddc3557

20
copy
View file

@ -28,11 +28,21 @@ import syslog
# to a dictionary # to a dictionary
# FIXME: make more idiomatic # 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: if len(sys.argv) == 1:
sys.exit(1) exit_kv(rc=1, failed=1, msg="incorrect number of arguments given")
argfile = sys.argv[1] argfile = sys.argv[1]
if not os.path.exists(argfile): 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() args = open(argfile, 'r').read()
items = shlex.split(args) items = shlex.split(args)
@ -54,8 +64,7 @@ if dest:
# raise an error if there is no src file # raise an error if there is no src file
if not os.path.exists(src): if not os.path.exists(src):
print "failed=1 msg='Source %s failed to transfer'" % src exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))
sys.exit(1)
md5sum = None md5sum = None
changed = False changed = False
@ -69,6 +78,7 @@ if md5sum != md5sum2:
changed = True changed = True
# mission accomplished # 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))