--- /dev/null
+#!/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())