else:
return obj
-def sync(source, destination, remove=True):
+def hardlink(src, dst):
+ print 'src = %s , dst = %s ' %(src, dst)
+ working_dir = os.getcwd()
+ if not os.path.exists(dst):
+ os.makedirs(dst)
+ os.chdir(src)
+ for root, dirs, files in os.walk('.'):
+ curdst = os.path.join(dst, root)
+ for d in dirs:
+ os.mkdir(os.path.join(curdst, d))
+ for f in files:
+ fromfile = os.path.join(root, f)
+ to = os.path.join(curdst, f)
+ os.link(fromfile, to)
+ os.chdir(working_dir)
+
+def sync(source, destination, remove=True, hardlinks=False):
""" sync srouce to destination, support local filesystem,
ssh and rsync protocol.
if remove:
shutil.move(source, destination)
else:
- shutil.copytree(source, destination)
+ if hardlinks:
+ # hardlink
+ hardlink(source, destination)
+ else:
+ shutil.copytree(source, destination)
# No exception so far, return code 0
ret_code = 0
shutil.rmtree(path_release_snapshot)
# sync snapshot to release
- sync(path_repo_snapshot, path_release_snapshot, remove=False)
+ sync(path_repo_snapshot, path_release_snapshot, remove=False, hardlinks=True)
# find the real latest repo by timestamp
repo_list = os.listdir(os.path.join(path_release_snapshot, "../"))