-
Notifications
You must be signed in to change notification settings - Fork 13
/
koji-tools.py
executable file
·60 lines (50 loc) · 1.84 KB
/
koji-tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
import os
import click
import koji
from six.moves.urllib_parse import urljoin
KOJIPKGS = "https://kojipkgs.fedoraproject.org/"
KOJIHUB = "https://koji.fedoraproject.org/kojihub"
@click.group()
def kojicli():
pass
@kojicli.command("get-latest-repo")
@click.argument("tag")
def get_latest_repo(tag):
"""Find latest repo ID and its URL for tag name.
\b
Example of output:
756330 https://kojipkgs.fedoraproject.org/repos/f27-build/756330
"""
ks = koji.ClientSession(KOJIHUB)
pathinfo = koji.PathInfo(topdir="")
repo = ks.getRepo(tag, state=koji.REPO_READY)
repo_id = repo["id"]
path = pathinfo.repo(repo_id, tag)
click.echo("{} {}".format(repo_id, urljoin(KOJIPKGS, path)))
@kojicli.command("get-source-packages")
@click.argument("tag")
@click.argument("repo_id", type=int)
def get_source_packages(tag, repo_id):
"""Find URLs to SRPMs used in repo ID for tag name."""
ks = koji.ClientSession(KOJIHUB)
pathinfo = koji.PathInfo(topdir="")
tinfo = ks.getTag(tag, strict=True)
tag_id = tinfo["id"]
repos = ks.getActiveRepos()
# let's filter all active repos by tag
repos = (repo for repo in repos if repo["tag_id"] == tag_id)
try:
repo = next(repo for repo in repos if repo["id"] == repo_id)
except StopIteration:
raise koji.GenericError("No active repo for specified tag and id: {!r}, {!r}".format(tag, repo_id))
event_id = repo["create_event"]
rpms, builds = ks.listTaggedRPMS(tag_id, event=event_id, inherit=True, latest=True, arch="src")
build_idx = {b["id"]: b for b in builds}
for rpm in rpms:
build = build_idx[rpm["build_id"]]
builddir = pathinfo.build(build)
path = os.path.join(pathinfo.build(build), pathinfo.rpm(rpm))
click.echo(urljoin(KOJIPKGS, path))
if __name__ == "__main__":
kojicli()