From 0959c1d7b434ad515ec4a43b53deae9db7bfda40 Mon Sep 17 00:00:00 2001 From: Yonghee Han Date: Fri, 10 Mar 2017 15:53:17 +0900 Subject: [PATCH] Use the hardlink function to copy from snapshots to release Release-snapshot job is very slow. Change-Id: I75323893001a7e0d729d45f96961e6b832384d88 --- common/utils.py | 24 ++++++++++++++++++++++-- job_release_snapshot.py | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/common/utils.py b/common/utils.py index 23e2df8..43f09cb 100644 --- a/common/utils.py +++ b/common/utils.py @@ -108,7 +108,23 @@ def unicode_to_str(obj): 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. @@ -143,7 +159,11 @@ def sync(source, destination, remove=True): 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 diff --git a/job_release_snapshot.py b/job_release_snapshot.py index 7e76d1e..c1f2f61 100755 --- a/job_release_snapshot.py +++ b/job_release_snapshot.py @@ -77,7 +77,7 @@ def main(): 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, "../")) -- 2.7.4