309 |
tries = 0 |
tries = 0 |
310 |
while tries < SLEEP_TIMES: |
while tries < SLEEP_TIMES: |
311 |
tries += 1 |
tries += 1 |
312 |
|
if tries > 1: time.sleep(SLEEP_REPEAT) |
313 |
try: |
try: |
314 |
# Download new tarball |
# Download new tarball |
315 |
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
316 |
|
# success, so exit loop |
317 |
break |
break |
318 |
except subprocess.CalledProcessError, e: |
except subprocess.CalledProcessError, e: |
319 |
# mgarepo sync returns 1 if the tarball cannot be downloaded |
# mgarepo sync returns 1 if the tarball cannot be downloaded |
320 |
if e.returncode != 1: |
if e.returncode != 1: |
321 |
return False |
return False |
322 |
|
else: |
323 |
|
return False |
324 |
|
|
|
if tries == SLEEP_TIMES: |
|
|
return False |
|
|
|
|
|
time.sleep(SLEEP_REPEAT) |
|
325 |
|
|
326 |
try: |
try: |
327 |
# Check patches still apply |
# Check patches still apply |
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() |
531 |
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream].keys()))) |
|
532 |
|
# 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 |
return downstream[upstream].keys() |
# 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: |