|
|
@ -24,13 +24,6 @@ import shlex
|
|
|
|
import shutil
|
|
|
|
import shutil
|
|
|
|
import syslog
|
|
|
|
import syslog
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
HAVE_HASHLIB=True
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
import md5
|
|
|
|
|
|
|
|
HAVE_HASHLIB=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
# ===========================================
|
|
|
|
# convert arguments of form a=b c=d
|
|
|
|
# convert arguments of form a=b c=d
|
|
|
|
# to a dictionary
|
|
|
|
# to a dictionary
|
|
|
@ -45,20 +38,9 @@ def exit_kv(rc=0, **kwargs):
|
|
|
|
print dump_kv(kwargs)
|
|
|
|
print dump_kv(kwargs)
|
|
|
|
sys.exit(rc)
|
|
|
|
sys.exit(rc)
|
|
|
|
|
|
|
|
|
|
|
|
def local_md5(filename):
|
|
|
|
def md5_sum(f):
|
|
|
|
''' compute local md5sum, return None if file is not present '''
|
|
|
|
md5sum = os.popen("/usr/bin/md5sum %(file)s 2>/dev/null || /sbin/md5 -q %(file)s 2>/dev/null || /usr/bin/digest -a md5 -v %(file)s 2>/dev/null" % {"file": f}).read().split()[0]
|
|
|
|
if os.path.exists(filename):
|
|
|
|
return md5sum
|
|
|
|
md5val=None
|
|
|
|
|
|
|
|
if os.path.exists(filename):
|
|
|
|
|
|
|
|
if HAVE_HASHLIB:
|
|
|
|
|
|
|
|
md5val=hashlib.md5(file(filename).read()).hexdigest()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
md5val=md5.new(file(filename).read()).hexdigest()
|
|
|
|
|
|
|
|
return md5val
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
exit_kv(rc=1, failed=1, msg="incorrect number of arguments given")
|
|
|
|
exit_kv(rc=1, failed=1, msg="incorrect number of arguments given")
|
|
|
@ -91,7 +73,7 @@ if not os.path.exists(src):
|
|
|
|
exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))
|
|
|
|
exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))
|
|
|
|
if not os.access(src, os.R_OK):
|
|
|
|
if not os.access(src, os.R_OK):
|
|
|
|
exit_kv(rc=1, failed=1, msg="Source %s not readable" % (src))
|
|
|
|
exit_kv(rc=1, failed=1, msg="Source %s not readable" % (src))
|
|
|
|
md5sum_src = local_md5(src)
|
|
|
|
md5sum_src = md5_sum(src)
|
|
|
|
|
|
|
|
|
|
|
|
md5sum_dest = None
|
|
|
|
md5sum_dest = None
|
|
|
|
# check if there is no dest file
|
|
|
|
# check if there is no dest file
|
|
|
@ -101,7 +83,7 @@ if os.path.exists(dest):
|
|
|
|
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
|
|
|
|
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
|
|
|
|
if not os.access(dest, os.R_OK):
|
|
|
|
if not os.access(dest, os.R_OK):
|
|
|
|
exit_kv(rc=1, failed=1, msg="Destination %s not readable" % (dest))
|
|
|
|
exit_kv(rc=1, failed=1, msg="Destination %s not readable" % (dest))
|
|
|
|
md5sum_dest = local_md5(dest)
|
|
|
|
md5sum_dest = md5_sum(dest)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if not os.access(os.path.dirname(dest), os.W_OK):
|
|
|
|
if not os.access(os.path.dirname(dest), os.W_OK):
|
|
|
|
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (os.path.dirname(dest)))
|
|
|
|
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (os.path.dirname(dest)))
|
|
|
|