From: Hasan Wan Date: Mon, 19 May 2014 09:28:58 +0000 (+0300) Subject: add new job script to create release repo from snapshot X-Git-Tag: 1.0~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49601009da415db1d510f942c4f341749234a8d9;p=services%2Fjenkins-scripts.git add new job script to create release repo from snapshot Change-Id: I5e773019ca1c278d40b1b204932d8e31f02cf8e8 Signed-off-by: Hasan Wan --- diff --git a/job_release_snapshot.py b/job_release_snapshot.py new file mode 100644 index 0000000..7c4847c --- /dev/null +++ b/job_release_snapshot.py @@ -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()) diff --git a/packaging/jenkins-scripts.spec b/packaging/jenkins-scripts.spec index 331c714..07133a7 100644 --- a/packaging/jenkins-scripts.spec +++ b/packaging/jenkins-scripts.spec @@ -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