Skip to content
Snippets Groups Projects
Unverified Commit bc35aee2 authored by Petr Hodina's avatar Petr Hodina Committed by Oliver Smith
Browse files

mrtest: allow to toggle multiple packages and use ranges (MR 23)

parent 976b3319
No related branches found
Tags 1.3.0
1 merge request!23mrtest: allow to select multiple packages and use ranges
Pipeline #184960 passed
......@@ -88,6 +88,46 @@ def show_commands():
print(" l: list selection")
print(" y: confirm selection")
print(" q: quit")
print("")
print("Toggling multiple packages in one command is possible (e.g. 2 3 4 10-15 20)")
def toggle_package(selection, apks, ret):
""" Toggle the package based on the user action.
:param selection: user input, single integer
:param apks: list of packages available for install
:param ret: list containing packages that are marked for install"""
pkg = int(selection)
if pkg >= 1 and pkg <= len(apks):
apk = apks[pkg - 1]
if apk in ret:
ret = [x for x in ret if x != apk]
else:
ret += [apk]
else:
print(f"Number {pkg} is out of range (1-{len(apks)})! Ignoring...")
return ret
def toggle_packages(action, apks, ret):
""" Toggle multiple packages based on the user action.
:param action: user input, multiple integers or range
:param apks: list of packages available for install
:param ret: list containing packages that are marked for install"""
selection = action.split()
for i in selection:
multiple = i.split("-")
size = len(multiple)
if size == 1 and i.isnumeric():
ret = toggle_package(i, apks, ret)
elif size == 2 and multiple[0].isnumeric() and multiple[1].isnumeric():
start = int(multiple[0])
stop = int(multiple[1])+1
for j in range(start, stop):
ret = toggle_package(j, apks, ret)
else:
print(f"Don't know ({i})! Ignoring...")
return ret
def ask(zip_path):
......@@ -128,12 +168,10 @@ def ask(zip_path):
exit(1)
elif action == "u":
ret = toggle_installed(apks, ret)
elif action.isnumeric() and int(action) >= 1 and int(action) <= len(apks):
apk = apks[int(action) - 1]
if apk in ret:
ret = [x for x in ret if x != apk]
else:
ret += [apk]
elif " " in action or "-" in action:
ret = toggle_packages(action, apks, ret)
elif action.isnumeric():
ret = toggle_package(action, apks, ret)
elif len(action) > 0:
print(f"Don't know ({action}), try 'h' for help")
show_selection_short(apks, ret)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment