Add utility function to watch builds
External tools that interact with Koji need to wait for builds to appear in a repo. For example, Fedora cli tools 'bodhi' and 'fedpkg' can create buildroot overrides, which only become useful after the override's build appears in the correct repo. At the moment, 'bodhi' waits for a repo by invoking the 'koji wait-repo' cli tool while 'fedpkg' does not wait at all. In order to make it easier for such tools to wait for a repo, the wait implementation from 'koji wait-repo' is moved to koji_cli.lib namespace where it is available for use through Python import.
This commit is contained in:
parent
f48d6d2b71
commit
d2247940b6
2 changed files with 64 additions and 34 deletions
|
|
@ -831,6 +831,63 @@ def _list_tasks(options, session):
|
|||
return tasklist
|
||||
|
||||
|
||||
def watch_builds(session, tag_id, builds, quiet=False, poll_interval=5, timeout=120):
|
||||
"""Watch for given builds to appear in given tag. If no build are given,
|
||||
watch for new repo for given tag.
|
||||
|
||||
:param session: Koji session object
|
||||
:param tag_id: Tag id
|
||||
:param builds: List of builds as NVR dicts
|
||||
:param quiet: no/verbose
|
||||
:param poll_interval: Poll interval in seconds
|
||||
:param timeout: Watch timeout in minutes"""
|
||||
last_repo = None
|
||||
repo = session.getRepo(tag_id)
|
||||
|
||||
# String representations for logs and exceptions
|
||||
builds_str = koji.util.printList(
|
||||
[koji.buildLabel(build) for build in builds])
|
||||
tag_info = session.getTag(tag_id)
|
||||
if not tag_info:
|
||||
raise koji.GenericError("No tag with id: %s" % tag_id)
|
||||
tag_name = tag_info['name']
|
||||
|
||||
start = time.time()
|
||||
while True:
|
||||
if builds and repo and repo != last_repo:
|
||||
if koji.util.checkForBuilds(session, tag_id, builds,
|
||||
repo['create_event'], latest=True):
|
||||
if not quiet:
|
||||
print("Successfully waited %s for %s "
|
||||
"to appear in the %s repo" %
|
||||
(koji.util.duration(start), builds_str, tag_name))
|
||||
return
|
||||
|
||||
if (time.time() - start >= timeout * 60.0):
|
||||
if not quiet:
|
||||
if builds:
|
||||
raise koji.GenericError(
|
||||
"Unsuccessfully waited %s for %s "
|
||||
"to appear in the %s repo" %
|
||||
(koji.util.duration(start), builds_str, tag_name))
|
||||
else:
|
||||
raise koji.GenericError(
|
||||
"Unsuccessfully waited %s for a new %s repo" %
|
||||
(koji.util.duration(start), tag_name))
|
||||
raise koji.GenericError()
|
||||
|
||||
time.sleep(poll_interval)
|
||||
last_repo = repo
|
||||
repo = session.getRepo(tag_id)
|
||||
|
||||
if not builds:
|
||||
if repo != last_repo:
|
||||
if not quiet:
|
||||
print("Successfully waited %s for a new %s repo" %
|
||||
(koji.util.duration(start), tag_name))
|
||||
return
|
||||
|
||||
|
||||
def format_inheritance_flags(parent):
|
||||
"""Return a human readable string of inheritance flags"""
|
||||
flags = ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue