From df0f93dc66ace14da626ead05852b59e43de3eb0 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Mon, 21 Apr 2014 15:05:37 +0800 Subject: [PATCH] Support multiply repos in snapshot module Change-Id: I0fb3df6e41fab0545a5e7d8ee1e360fb68f9062f Signed-off-by: Lin Yang --- common/snapshot.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/common/snapshot.py b/common/snapshot.py index 5b13fac..cb478d6 100644 --- a/common/snapshot.py +++ b/common/snapshot.py @@ -41,14 +41,13 @@ class Prerelease(object): """Prerelease path.""" return os.path.join(self.snapshot.base_path, self.dir) - @property - def pkg_urls(self): + def pkg_urls(self, repo): """List of package(repository) urls for prerelease.""" pkg_urls = {} - for arch in self.snapshot.archs: + for arch in self.snapshot.archs(repo): pkg_urls[arch] = os.path.join(self.base_url, self.dir, self.build_id, 'repos', - self.snapshot.repo['Target'], + repo, 'packages') return pkg_urls @@ -57,16 +56,15 @@ class Snapshot(object): """Snapshot maintenance class.""" def __init__(self, backenddb, base_path, repo_name=None, - obs_project=None, obs_repo=None): + obs_project=None): """Get snapshot properties from backend db. Init snapshot attributes.""" self.backenddb = backenddb self.base_path = base_path try: - key = "%s:%s" % (obs_project, obs_repo) - self.repo_name = repo_name or backenddb.get_obs_repo_map()[key] + self.repo_name = repo_name or backenddb.get_obs_repo_map()[obs_project] except (BackendDBError, EntityError), err: - raise SnapshotError("Can't get repo name for '%s:%s' : %s" % \ - (obs_project, obs_repo, str(err))) + raise SnapshotError("Can't get repo name for '%s' : %s" % \ + (obs_project, str(err))) try: self.repo = backenddb.get_repos()[self.repo_name] except BackendDBError, err: @@ -74,8 +72,7 @@ class Snapshot(object): % (repo_name, str(err))) # Sanity check - for key in ('Release', 'SnapshotDir', 'PrereleaseDir', 'PartOf', - 'Architectures'): + for key in ('Release', 'SnapshotDir', 'PrereleaseDir', 'Targets'): if key not in self.repo: raise SnapshotError("Key '%s' doesn't exist for repo '%s' "\ "in Redis" % (key, self.repo_name)) @@ -117,9 +114,17 @@ class Snapshot(object): self.build_id) @property - def archs(self): - """List of architectures used in snapshot.""" - return self.repo['Architectures'] + def targets(self): + """List of targets enabled in snapshot.""" + return self.repo['Targets'] + + def archs(self, repo): + """List of architectures used in snapshot + """ + for target in self.targets: + if str(target['Name']) != repo: + continue + return target['Architectures'] def inc(self): """Increment stapshot.""" -- 2.7.4