Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an interactive option to display build log in 'request list -i' command #1367

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 65 additions & 25 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import fnmatch
import glob
import hashlib
import io

Check notice

Code scanning / CodeQL

Module is imported with 'import' and 'import from' Note

Module 'io' is imported with both 'import' and 'import from'.
import locale
import os
import platform
Expand Down Expand Up @@ -6936,13 +6937,16 @@
strip_time=False,
last=False,
lastsucceeded=False,
output_buffer=None,
):
"""prints out the buildlog on stdout"""

output_buffer = output_buffer or sys.stdout.buffer

Check warning on line 6944 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L6944

Added line #L6944 was not covered by tests

def print_data(data, strip_time=False):
if strip_time:
data = buildlog_strip_time(data)
sys.stdout.buffer.write(data)
output_buffer.write(data)

Check warning on line 6949 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L6949

Added line #L6949 was not covered by tests

query = {'nostream': '1', 'start': '%s' % offset}
if last:
Expand Down Expand Up @@ -8263,39 +8267,73 @@
print('Try -f to force the state change', file=sys.stderr)
return False

def safe_get_rpmlint_log(src_actions):
lintlogs = []
def get_repos(src_actions):

Check warning on line 8270 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8270

Added line #L8270 was not covered by tests
"""
Translate src_actions to [{"proj": ..., "pkg": ..., "repo": ..., "arch": ...}]
"""
result = []

Check warning on line 8274 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8274

Added line #L8274 was not covered by tests
for action in src_actions:
print('Type %s:' % action.type)
disabled = show_package_disabled_repos(apiurl, action.src_project, action.src_package)
for repo in get_repos_of_project(apiurl, action.src_project):
if (disabled is None) or (repo.name not in [d['repo'] for d in disabled]):
lintlog_entry = {
'proj': action.src_project,
'pkg': action.src_package,
'repo': repo.name,
'arch': repo.arch
if (disabled is None) or (repo.name not in [d["repo"] for d in disabled]):
entry = {

Check warning on line 8279 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8278-L8279

Added lines #L8278 - L8279 were not covered by tests
"proj": action.src_project,
"pkg": action.src_package,
"repo": repo.name,
"arch": repo.arch
}
lintlogs.append(lintlog_entry)
print('(%i) %s/%s/%s/%s' % ((len(lintlogs) - 1), action.src_project, action.src_package, repo.name, repo.arch))
if not lintlogs:
print('No possible rpmlintlogs found')
return False
result.append(entry)
return result

Check warning on line 8286 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8285-L8286

Added lines #L8285 - L8286 were not covered by tests

def select_repo(src_actions):

Check warning on line 8288 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8288

Added line #L8288 was not covered by tests
"""
Prompt user to select a repo from a list.
"""
repos = get_repos(src_actions)

Check warning on line 8292 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8292

Added line #L8292 was not covered by tests

for num, entry in enumerate(repos):
print(f"({num}) {entry['proj']}/{entry['pkg']}/{entry['repo']}/{entry['arch']}")

Check warning on line 8295 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8294-L8295

Added lines #L8294 - L8295 were not covered by tests

if not repos:
print('No repos')
return None

Check warning on line 8299 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8297-L8299

Added lines #L8297 - L8299 were not covered by tests

while True:
try:
lint_n = int(raw_input('Number of rpmlint log to examine (0 - %i): ' % (len(lintlogs) - 1)))
lintlogs[lint_n]
break
reply = raw_input(f"Number of repo to examine (0 - {len(repos)-1}): ").strip()
if not reply:
return None
reply_num = int(reply)
return repos[reply_num]

Check warning on line 8307 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8303-L8307

Added lines #L8303 - L8307 were not covered by tests
except (ValueError, IndexError):
print('Invalid rpmlintlog index. Please choose between 0 and %i' % (len(lintlogs) - 1))
print(f"Invalid index. Please choose between 0 and {len(repos)-1}")

Check warning on line 8309 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8309

Added line #L8309 was not covered by tests

def safe_get_rpmlint_log(src_actions):
repo = select_repo(src_actions)
if not repo:
return

Check warning on line 8314 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8311-L8314

Added lines #L8311 - L8314 were not covered by tests
try:
print(decode_it(get_rpmlint_log(apiurl, **lintlogs[lint_n])))
run_pager(get_rpmlint_log(apiurl, **repo))

Check warning on line 8316 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8316

Added line #L8316 was not covered by tests
except HTTPError as e:
if e.code == 404:
print('No rpmlintlog for %s %s' % (lintlogs[lint_n]['repo'],
lintlogs[lint_n]['arch']))
print(f"No rpmlint log for {repo['repo']}/{repo['arch']}")

Check warning on line 8319 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8319

Added line #L8319 was not covered by tests
else:
raise e
raise

Check warning on line 8321 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8321

Added line #L8321 was not covered by tests

def get_build_log(src_actions):
repo = select_repo(src_actions)
if not repo:
return
try:
buffer = io.BytesIO()
print_buildlog(apiurl, repo["proj"], repo["pkg"], repo["repo"], repo["arch"], output_buffer=buffer)
buffer.seek(0)
run_pager(buffer.read())
except HTTPError as e:
if e.code == 404:
print(f"No build log for {repo['repo']}/{repo['arch']}")

Check warning on line 8334 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8323-L8334

Added lines #L8323 - L8334 were not covered by tests
else:
raise

Check warning on line 8336 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8336

Added line #L8336 was not covered by tests

def print_request(request):
print(request)
Expand Down Expand Up @@ -8344,10 +8382,10 @@
# actions which have sources + buildresults
src_actions = editable_actions + request.get_actions('maintenance_release')
if editable_actions:
prompt = 'd(i)ff/(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/rpm(li)ntlog/c(l)one/(e)dit/co(m)ment/(s)kip/(c)ancel > '
prompt = 'd(i)ff/(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/(bl)buildlog/rpm(li)ntlog/c(l)one/(e)dit/co(m)ment/(s)kip/(c)ancel > '

Check warning on line 8385 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8385

Added line #L8385 was not covered by tests
elif src_actions:
# no edit for maintenance release requests
prompt = 'd(i)ff/(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/rpm(li)ntlog/c(l)one/co(m)ment/(s)kip/(c)ancel > '
prompt = 'd(i)ff/(a)ccept/(d)ecline/(r)evoke/(b)uildstatus/(bl)buildlog/rpm(li)ntlog/c(l)one/co(m)ment/(s)kip/(c)ancel > '

Check warning on line 8388 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8388

Added line #L8388 was not covered by tests
editprj = ''
orequest = None
if source_buildstatus and src_actions:
Expand Down Expand Up @@ -8406,6 +8444,8 @@
print_source_buildstatus(src_actions)
elif repl == 'li' and src_actions:
safe_get_rpmlint_log(src_actions)
elif repl == 'bl' and src_actions:
get_build_log(src_actions)

Check warning on line 8448 in osc/core.py

View check run for this annotation

Codecov / codecov/patch

osc/core.py#L8447-L8448

Added lines #L8447 - L8448 were not covered by tests
elif repl == 'e' and editable_actions:
# this is only for editable actions
if not editprj:
Expand Down
Loading