Use the hardlink function to copy from snapshots to release 93/118393/1
authorYonghee Han <onstudy@samsung.com>
Fri, 10 Mar 2017 06:53:17 +0000 (15:53 +0900)
committerYonghee Han <onstudy@samsung.com>
Fri, 10 Mar 2017 06:53:17 +0000 (15:53 +0900)
Release-snapshot job is very slow.

Change-Id: I75323893001a7e0d729d45f96961e6b832384d88

common/utils.py
job_release_snapshot.py

index 23e2df8..43f09cb 100644 (file)
@@ -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
 
index 7e76d1e..c1f2f61 100755 (executable)
@@ -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, "../"))