Skip to content

Commit 1b9c715

Browse files
authored
scripts/koji: add more informative error messages for koji_build (#738)
Also fixes fix ruff errors in the directory
2 parents e4f4619 + 319ad7f commit 1b9c715

File tree

5 files changed

+42
-28
lines changed

5 files changed

+42
-28
lines changed

scripts/koji/create_user_target.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python3
22
import argparse
3-
import subprocess
43
import logging
4+
import subprocess
55
import sys
66

7+
78
def setup_logger():
89
logging.basicConfig(
910
format="%(asctime)s - %(levelname)s - %(message)s",

scripts/koji/koji_build.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ def is_remote_branch_commit(git_repo, sha, branch):
155155
)
156156
return sha == remote_sha
157157

158+
def build_id_of(name, candidate):
159+
if candidate is None:
160+
return None
161+
162+
length = len(candidate)
163+
if length > 16:
164+
logging.error(f"The {name} build id must be at most 16 characters long, it's {length} characters long")
165+
exit(1)
166+
167+
invalid_chars = any(re.match(r'[a-zA-Z0-9]', char) is None for char in candidate)
168+
169+
if invalid_chars:
170+
pp_invalid = ''.join("^" if re.match(r'[a-zA-Z0-9]', char) is None else " " for char in candidate)
171+
logging.error(f"The {name} build id must only contain letters and digits:")
172+
logging.error(f" {candidate}")
173+
logging.error(f" {pp_invalid}")
174+
exit(1)
175+
176+
return candidate
177+
158178
def main():
159179
parser = argparse.ArgumentParser(
160180
description='Build a package or chain-build several from local git repos for RPM sources'
@@ -182,17 +202,13 @@ def main():
182202
git_repos = [os.path.abspath(check_dir(d)) for d in args.git_repos]
183203
is_scratch = args.scratch
184204
is_nowait = args.nowait
185-
test_build = args.test_build
186-
pre_build = args.pre_build
205+
206+
test_build = build_id_of("test", args.test_build)
207+
pre_build = build_id_of("pre", args.pre_build)
208+
187209
if test_build and pre_build:
188210
logging.error("--pre-build and --test-build can't be used together")
189211
exit(1)
190-
if test_build is not None and re.match('^[a-zA-Z0-9]{1,16}$', test_build) is None:
191-
logging.error("The test build id must be 16 characters long maximum and only contain letters and digits")
192-
exit(1)
193-
if pre_build is not None and re.match('^[a-zA-Z0-9]{1,16}$', pre_build) is None:
194-
logging.error("The pre build id must be 16 characters long maximum and only contain letters and digits")
195-
exit(1)
196212

197213
if len(git_repos) > 1 and is_scratch:
198214
parser.error("--scratch is not compatible with chained builds.")

scripts/koji/koji_import_rpms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env python3
2+
23
import argparse
4+
import glob
35
import os
46
import subprocess
5-
import glob
7+
68

79
def get_srpm_info(srpmpath):
810
return subprocess.check_output(['rpm', '-qp', srpmpath, '--qf', '%{name};;%{nvr}']).split(';;')
@@ -22,8 +24,6 @@ def main():
2224
parser.add_argument('--create-build', help='create the build even if there\'s no SRPM', action='store_true', default=False)
2325
args = parser.parse_args()
2426

25-
DEVNULL = open(os.devnull, 'w')
26-
2727
srpm_directory = os.path.abspath(check_dir(args.srpm_directory))
2828
rpm_directory = os.path.abspath(check_dir(args.rpm_directory))
2929

scripts/koji/sync_repo_from_koji.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env python3
2+
23
import argparse
3-
import re
4-
import os
5-
import sys
6-
import subprocess
4+
import atexit
75
import glob
6+
import os
7+
import re
88
import shutil
9+
import subprocess
10+
import sys
911
import tempfile
10-
import atexit
11-
1212
from datetime import datetime
1313

1414
USER_REPO_HTTPS = "https://koji.xcp-ng.org/repos/user/"
@@ -85,8 +85,6 @@
8585

8686
KEY_ID = "3fd3ac9e"
8787

88-
DEVNULL = open(os.devnull, 'w')
89-
9088
def version_from_tag(tag):
9189
matches = re.match(r'v(\d+\.\d+)', tag)
9290
return matches.group(1)
@@ -118,7 +116,7 @@ def sign_rpm(rpm):
118116
subprocess.check_call(['koji', 'download-build', '--debuginfo', '--noprogress', '--rpm', rpm])
119117

120118
# sign: requires a sign-rpm executable or alias in the PATH
121-
subprocess.check_call(['sign-rpm', rpm], stdout=DEVNULL)
119+
subprocess.check_call(['sign-rpm', rpm], stdout=subprocess.DEVNULL)
122120

123121
# import signature
124122
subprocess.check_call(['koji', 'import-sig', rpm])
@@ -184,8 +182,8 @@ def write_repo(tag, dest_dir, tmp_root_dir, offline=False):
184182
paths.append(os.path.join(path_to_tmp_repo, 'Source'))
185183
for path in paths:
186184
print("\n-- Generate repodata for %s" % path)
187-
subprocess.check_call(['createrepo_c', path], stdout=DEVNULL)
188-
subprocess.check_call(['sign-file', os.path.join(path, 'repodata', 'repomd.xml')], stdout=DEVNULL)
185+
subprocess.check_call(['createrepo_c', path], stdout=subprocess.DEVNULL)
186+
subprocess.check_call(['sign-file', os.path.join(path, 'repodata', 'repomd.xml')], stdout=subprocess.DEVNULL)
189187

190188
# Synchronize to our final repository:
191189
# - add new RPMs
@@ -379,7 +377,7 @@ def offline_repo_dir():
379377
subprocess.check_call(
380378
['sign-file', 'SHA256SUMS'],
381379
cwd=offline_repo_path_parent,
382-
stdout=DEVNULL
380+
stdout=subprocess.DEVNULL
383381
)
384382

385383
# update data

scripts/koji/update_vendor_tags.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env python3
2+
23
import argparse
3-
import subprocess
44
import json
55
import os
66
import re
7-
8-
DEVNULL = open(os.devnull, 'w')
7+
import subprocess
98

109
XS_buildhosts = [
1110
'1b68968c4e4e',
@@ -59,7 +58,7 @@ def update_vendor_tag_for_build(build, is_bootstrap=False):
5958

6059
# get vendor information
6160
output = subprocess.check_output(
62-
['rpm', '-qp', rpm_path, '--qf', '%{vendor};;%{buildhost}'], stderr=DEVNULL
61+
['rpm', '-qp', rpm_path, '--qf', '%{vendor};;%{buildhost}'], stderr=devprocess.DEVNULL
6362
).decode()
6463
vendor, buildhost = output.split(';;')
6564
package = re.search('/packages/([^/]+)/', rpm_path).group(1)

0 commit comments

Comments
 (0)