add new job script to create release repo from snapshot
authorHasan Wan <hasan.wan@intel.com>
Mon, 19 May 2014 09:28:58 +0000 (12:28 +0300)
committerHasan Wan <hasan.wan@intel.com>
Sun, 8 Jun 2014 14:40:23 +0000 (17:40 +0300)
Change-Id: I5e773019ca1c278d40b1b204932d8e31f02cf8e8
Signed-off-by: Hasan Wan <hasan.wan@intel.com>
job_release_snapshot.py [new file with mode: 0644]
packaging/jenkins-scripts.spec

diff --git a/job_release_snapshot.py b/job_release_snapshot.py
new file mode 100644 (file)
index 0000000..7c4847c
--- /dev/null
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+"""
+job_release_snapshot.py
+This job is created to RE to release snapshot through jenkins UI, by trigger
+it manually. The release target can be weekly or daily
+"""
+
+import os
+import sys
+import shutil
+
+from common.utils import sync
+from common.utils import make_latest_link
+from common.backenddb import BackendDB
+
+
+def main():
+    """The main body"""
+
+    path_repo_base = os.getenv('PATH_REPO_BASE')
+
+    release_type = os.getenv('release_type');
+    release_profile = os.getenv('profile');
+    release_id = os.getenv('release_id');
+
+    # only supports the snapshot repo created by Jenkins
+    backend = BackendDB(os.getenv('REDIS_HOST'),
+                        int(os.getenv("REDIS_PORT")))
+
+    repos = backend.get_repos()
+    if release_profile not in repos:
+        print("Internal error, the profile %s doesn't exists" %release_profile)
+        return -1
+
+    profile_info = repos[release_profile]
+
+    # figure out the snapshot dir
+    path_repo_snapshot = os.path.join(path_repo_base,
+                                      profile_info['SnapshotDir'],
+                                      release_id)
+
+    # make sure the source dir is exists
+
+    if not os.path.exists(path_repo_snapshot):
+        print("The snapshot %s of %s doesn't exists on download server"
+              %(release_id, release_profile))
+        return -1
+
+    # figure out the release destination dir
+    release_dir = "releases/%s" %release_type
+
+    path_release_snapshot = os.path.join(path_repo_base,
+                                         profile_info['SnapshotDir'],
+                                         release_id)\
+                                         .replace('snapshots', release_dir)
+    # exists, it will be replaced
+    if os.path.exists(path_release_snapshot):
+        printf("The repo %s already exists, deleted and sync again" %release_id)
+        shutil.rmtree(path_release_snapshot)
+
+    # sync snapshot to release
+    sync(path_repo_snapshot, path_release_snapshot, remove = False)
+
+    # find the real latest repo by timestamp
+    repo_list = os.listdir(os.path.join(path_release_snapshot, "../"))
+    repo_list.sort()
+
+    path_latest_release_snapshot = os.path.join(path_release_snapshot, "../",
+                                           repo_list[-1])
+
+    # update the latest link
+    make_latest_link(path_latest_release_snapshot)
+
+if __name__ == '__main__':
+
+    sys.exit(main())
index 331c714..07133a7 100644 (file)
@@ -119,6 +119,7 @@ fi
 %{destdir}/common/manifest.py
 %{destdir}/common/upload_service.py
 %{destdir}/job_create_snapshot.py
+%{destdir}/job_release_snapshot.py
 %{destdir}/job_buildlogs.py
 %{destdir}/job_jobs_dispatcher.py
 %{destdir}/job_imager.py