From: Hasan Wan Date: Thu, 16 May 2013 09:25:40 +0000 (+0800) Subject: implement the sync api X-Git-Tag: 0.14~178 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6c1ad180d74fee08f3259cedd2090fa45dcb1a2e;p=services%2Fjenkins-scripts.git implement the sync api Change-Id: I237184d6ffd48ab0a07279eb372500e580f4bf1d Signed-off-by: Hasan Wan --- diff --git a/common/utils.py b/common/utils.py index 3a720f7..2ee51aa 100644 --- a/common/utils.py +++ b/common/utils.py @@ -20,6 +20,7 @@ import os import glob +import subprocess from common import runner @@ -88,3 +89,30 @@ def unicode_to_str(obj): return obj.encode('utf-8') else: return obj + +def sync(source, destination): + """ sync srouce to destination, support local filesystem, + ssh and rsync protocol. + + Note: access to destination server must be use key authentication + or anonymous + """ + + # Through rsync protocol + if destination.startswith('rsync:'): + cmd = "rsync -av %s/ %s" %(source, destination) + + # Through ssh protocol + elif destination.startswith('ssh:'): + destination = destination.replace("ssh://", "") + cmd = "scp -r %s/* %s" %(source, destination) + + # Try to take the destination as local path + else: + cmd = "mv -v %s/* %s/" %(source, destination) + try: + ret_code = subprocess.call(cmd, shell = True) + except OSError as err: + raise RuntimeException("Execution of %s failed: %s" % (cmd, str(err))) + + return ret_code