526 |
if upstream not in downstream: |
if upstream not in downstream: |
527 |
raise ValueError("No packages for upstream name: %s" % upstream) |
raise ValueError("No packages for upstream name: %s" % upstream) |
528 |
|
|
529 |
if len(downstream[upstream]) != 1: |
if len(downstream[upstream]) == 1: |
530 |
# XXX - Make it more intelligent |
return downstream[upstream].keys() |
|
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream].keys()))) |
|
531 |
|
|
532 |
return downstream[upstream].keys() |
# Directories packages are located in |
533 |
|
root = os.path.expanduser(PKGROOT) |
534 |
|
|
535 |
|
packages = {} |
536 |
|
for package in downstream[upstream].keys(): |
537 |
|
cwd = os.path.join(root, package) |
538 |
|
|
539 |
|
# Checkout package to ensure the checkout reflects the latest changes |
540 |
|
try: |
541 |
|
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
542 |
|
except subprocess.CalledProcessError: |
543 |
|
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
544 |
|
|
545 |
|
# Determine version from spec file |
546 |
|
try: |
547 |
|
packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
548 |
|
except subprocess.CalledProcessError: |
549 |
|
raise ValueError("Multiple packages found and cannot determine version of %s" % package) |
550 |
|
|
551 |
|
# Return all packages reflecting the current version |
552 |
|
matches = [package for package in packages if packages[package] == version] |
553 |
|
if len(matches): |
554 |
|
return matches |
555 |
|
|
556 |
|
# Return all packages reflecting the version before the current version |
557 |
|
latest_version = get_latest_version(packages.values(), max_version=version) |
558 |
|
matches = [package for package in packages if packages[package] == latest_version] |
559 |
|
if len(matches): |
560 |
|
return matches |
561 |
|
|
562 |
|
# Give up |
563 |
|
raise ValueError("Multiple packages found and cannot determine package for version %s" % version) |
564 |
|
|
565 |
def write_file(path, data): |
def write_file(path, data): |
566 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |