import os
import glob
+import subprocess
from common import runner
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