import subprocess
import re
import xml.sax.handler
+import shutil
from common import runner
else:
return obj
-def sync(source, destination):
+def sync(source, destination, remove=True):
""" sync srouce to destination, support local filesystem,
ssh and rsync protocol.
Note: access to destination server must be use key authentication
or anonymous
"""
+ ret_code = -1
# Through rsync protocol
if destination.startswith('rsync:'):
cmd = "rsync -av %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)))
+
# Through ssh protocol
elif destination.startswith('ssh:'):
destination = destination.replace("ssh://", "")
cmd = "scp -r %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)))
+
# 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)))
+ if remove:
+ shutil.move(source, destination)
+ else:
+ shutil.copytree(source, destination)
+ # No exception so far, return code 0
+ ret_code = 0
return ret_code
xml.sax.parse(src, builder)
return builder.root._attrs.values()[0]
+def make_latest_link(snapshot_path):
+ """ make the latest repo link to the new repo
+ snapshot_path (str): the local path to snapshot
+ """
+ latest = os.path.join(snapshot_path, "../latest")
+ if os.path.lexists(latest):
+ os.unlink(latest)
+ os.symlink(snapshot_path, latest)
from common.repomaker import RepoMaker, RepoMakerError
from common.backenddb import BackendDB
from common.snapshot import Snapshot, SnapshotError
-
+from common.utils import make_latest_link
class LocalError(Exception):
"""Local error exception."""
'imagedata': imagedatas
}
-def make_latest_link(snapshot_path):
- """ make the latest repo link to the new repo
- snapshot_path (str): the local path to snapshot
- """
- latest = os.path.join(snapshot_path, "../latest")
- if os.path.lexists(latest):
- os.unlink(latest)
- os.symlink(snapshot_path, latest)
-
def main():
"""Script entry point."""