diff options
-rwxr-xr-x | mgagnome | 38 |
1 files changed, 34 insertions, 4 deletions
@@ -526,11 +526,41 @@ def get_downstream_from_upstream(upstream, version): if upstream not in downstream: raise ValueError("No packages for upstream name: %s" % upstream) - if len(downstream[upstream]) != 1: - # XXX - Make it more intelligent - raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream].keys()))) + if len(downstream[upstream]) == 1: + return downstream[upstream].keys() - return downstream[upstream].keys() + # Directories packages are located in + root = os.path.expanduser(PKGROOT) + + packages = {} + for package in downstream[upstream].keys(): + cwd = os.path.join(root, package) + + # Checkout package to ensure the checkout reflects the latest changes + try: + subprocess.check_call(['mgarepo', 'co', package], cwd=root) + except subprocess.CalledProcessError: + raise ValueError("Multiple packages found and cannot checkout %s" % package) + + # Determine version from spec file + try: + packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version + except subprocess.CalledProcessError: + raise ValueError("Multiple packages found and cannot determine version of %s" % package) + + # Return all packages reflecting the current version + matches = [package for package in packages if packages[package] == version] + if len(matches): + return matches + + # Return all packages reflecting the version before the current version + latest_version = get_latest_version(packages.values(), max_version=version) + matches = [package for package in packages if packages[package] == latest_version] + if len(matches): + return matches + + # Give up + raise ValueError("Multiple packages found and cannot determine package for version %s" % version) def write_file(path, data): with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |