From: Ed Bartosh Date: Sun, 1 Dec 2013 21:17:07 +0000 (+0200) Subject: Cleanup prerelese repos from all snapshots X-Git-Tag: 0.15~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0e19924f5757f2bc5856c187b4e37a2b88487633;p=services%2Fjenkins-scripts.git Cleanup prerelese repos from all snapshots When cleaning up prerelease repos we should consider all snapshots, not just the latest one. Change-Id: I85b2d1dfedeb979eaf135ca5f4416ef54c3fbb93 Signed-off-by: Ed Bartosh --- diff --git a/job_pre_release_obs.py b/job_pre_release_obs.py index d9f5e6b..2ba181c 100755 --- a/job_pre_release_obs.py +++ b/job_pre_release_obs.py @@ -145,19 +145,21 @@ def make_repo(project, repo, backenddb, base_url, base_path, live_repo_base): os.path.join(prerelease.dir, prerelease.build_id), project, base_url) -def get_published_repo(repo_path_base, time_stamp): - """ Search publised repository +def get_published_repos(repo_path_base, time_stamp): + """ Search publised repository recursively Args: - repo_path_base (str): the repo location on file systems - time_stamp (str): the time stamp of sbumit tag + repo_path_base (str): path to base dir + time_stamp (str): time stamp of sbumit tag """ - ret_list = [] if os.path.isdir(repo_path_base): - for dir_name in os.listdir(repo_path_base): - if dir_name.endswith(time_stamp): - ret_list.append(os.path.join(repo_path_base, dir_name)) - - return ret_list + for name in os.listdir(repo_path_base): + path = os.path.join(repo_path_base, name) + if os.path.isdir(path): + if name.endswith(time_stamp): + yield path + else: + for npath in get_published_repos(path, time_stamp): + yield npath def project_cleanup(backenddb, build, base_path, base_url, event_dict): """ request(SR) end of life, this founction should be called to @@ -224,10 +226,13 @@ def project_cleanup(backenddb, build, base_path, base_url, event_dict): except SnapshotError, err: raise LocalError("Error getting prerelease data: %s" % str(err)) - published_repos = get_published_repo(prerelease.path, time_stamp) - for repo in published_repos: - print 'Removing the repo: %s' % repo - shutil.rmtree(repo) + # remove latest snapshot from prerelease_path as we need to clean up + # published repos from old snapshots too + root = prerelease.path.split(prerelease.snapshot)[0] + + for path in get_published_repos(root, time_stamp): + print 'Removing the repo: %s' % path + shutil.rmtree(path) def main(action): """Script entry point.