Skip to content
Snippets Groups Projects
Unverified Commit 8fcac5b3 authored by Newbyte's avatar Newbyte :snowflake:
Browse files

mrtest: Format with Ruff (MR 35)

parent d8a107bf
No related branches found
No related tags found
No related merge requests found
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Various small functions used in other files in mrtest. """
"""Various small functions used in other files in mrtest."""
import os
def get_sudo():
""" :returns: either "doas" or "sudo" """
""":returns: either "doas" or "sudo" """
if os.path.exists("/usr/bin/doas"):
return "doas"
return "sudo"
def get_virtual_group(origin, mr_id):
""" Generate a virtual group id to be passed to apk when installing
packages from a merge request.
:param origin: gitlab origin information, see gitlab.parse_git_origin()
:param mr_id: merge request ID """
"""Generate a virtual group id to be passed to apk when installing
packages from a merge request.
:param origin: gitlab origin information, see gitlab.parse_git_origin()
:param mr_id: merge request ID"""
return f".mrtest-{mr_id}-{origin['project']}"
......
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" High level action of adding packages from MR's artifacts """
"""High level action of adding packages from MR's artifacts"""
import logging
import os
......@@ -52,10 +52,14 @@ def run_apk_add(origin, mr_id, apk_paths):
:param mr_id: merge request ID
:param apk_paths: list of apk file paths to be installed
"""
cmd = ["apk", "add",
"-u",
"--virtual", mrtest.get_virtual_group(origin, mr_id),
"--allow-untrusted"] + apk_paths
cmd = [
"apk",
"add",
"-u",
"--virtual",
mrtest.get_virtual_group(origin, mr_id),
"--allow-untrusted",
] + apk_paths
if not mrtest.is_root_user():
cmd = [mrtest.get_sudo()] + cmd
......@@ -83,8 +87,8 @@ def confirm_mr_id(origin, mr_id):
print()
print("You are about to select and then install packages from:")
print(link)
print("\t\033[1m"+status.title+"\033[m”")
print("\t(\033[3m" + status.source + ":" + status.source_branch+"\033[m)")
print("\t\033[1m" + status.title + "\033[m”")
print("\t(\033[3m" + status.source + ":" + status.source_branch + "\033[m)")
print()
print("* Did you read and understand the diff?")
print("* If not, do you at least trust the person who submitted it?")
......@@ -112,10 +116,12 @@ def add_packages(origin, mr_id, no_cache):
try:
zip_path = mrhlpr.mr.get_artifacts_zip(mr_id, no_cache, origin)
except HTTPError:
print('''
print(
"""
Remote server does not have any packages to download.
Please trigger again the MR {} to generate the packages.
'''.format(mr_id))
""".format(mr_id)
)
exit(0)
selection = mrtest.select_package.ask(zip_path)
......
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Code interacting with apk (Alpine's package manager) """
"""Code interacting with apk (Alpine's package manager)"""
import logging
import os
......@@ -24,8 +24,10 @@ def get_installed_all():
try:
output = subprocess.run(cmd, capture_output=True).stdout
except FileNotFoundError:
print("ERROR: The command 'apk' was not found!\n"
"Please run the 'mrtest' on pmOS/alpine installation.")
print(
"ERROR: The command 'apk' was not found!\n"
"Please run the 'mrtest' on pmOS/alpine installation."
)
exit(1)
output = output.decode("utf-8")
......
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Parse command-line arguments. """
"""Parse command-line arguments."""
import argparse
import logging
......@@ -17,25 +17,30 @@ except ImportError:
def parse_args_parser_add(sub):
""" :param sub: argparser's subparser """
""":param sub: argparser's subparser"""
parser = sub.add_parser("add", help="install/upgrade to packages from a MR")
parser.add_argument("-a", "--alpine", action="store_true",
help="use alpine's aports instead of pmOS' pmaports")
parser.add_argument(
"-a", "--alpine", action="store_true", help="use alpine's aports instead of pmOS' pmaports"
)
parser.add_argument("mr_id", type=int, help="merge request ID")
def parse_args_parser_zap(sub):
""" :param sub: argparser's subparser """
""":param sub: argparser's subparser"""
sub.add_parser("zap", help="uninstall previously added packages")
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--no-cache", action="store_true",
help="do not use local cache for MR information")
parser.add_argument("-v", "--verbose", action="store_true",
help="display debug log: all commands and locations of"
" http cache files")
parser.add_argument(
"-n", "--no-cache", action="store_true", help="do not use local cache for MR information"
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="display debug log: all commands and locations of" " http cache files",
)
sub = parser.add_subparsers(title="action", dest="action")
sub.required = True
......
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Origin information about gitlab instances relevant to mrtest, in the format
needed for mrhlpr.gitlab.parse_git_origin(). """
"""Origin information about gitlab instances relevant to mrtest, in the format
needed for mrhlpr.gitlab.parse_git_origin()."""
pmaports = {"api": "https://gitlab.com/api/v4",
"api_project_id": "postmarketOS%2Fpmaports",
"full": "git@gitlab.com:postmarketOS/pmaports.git",
"project": "postmarketOS",
"project_id": "postmarketOS/pmaports",
"host": "gitlab.com"}
pmaports = {
"api": "https://gitlab.com/api/v4",
"api_project_id": "postmarketOS%2Fpmaports",
"full": "git@gitlab.com:postmarketOS/pmaports.git",
"project": "postmarketOS",
"project_id": "postmarketOS/pmaports",
"host": "gitlab.com",
}
aports = {"api": "https://gitlab.alpinelinux.org/api/v4",
"api_project_id": "alpine%2Faports",
"full": "git@gitlab.alpinelinux.org:alpine/aports.git",
"project": "alpine",
"project_id": "alpine/aports",
"host": "gitlab.alpinelinux.org"}
aports = {
"api": "https://gitlab.alpinelinux.org/api/v4",
"api_project_id": "alpine%2Faports",
"full": "git@gitlab.alpinelinux.org:alpine/aports.git",
"project": "alpine",
"project_id": "alpine/aports",
"host": "gitlab.alpinelinux.org",
}
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Interactive package selection dialog """
"""Interactive package selection dialog"""
import os
import zipfile
......@@ -93,10 +93,10 @@ def show_commands():
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"""
"""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]
......@@ -110,10 +110,10 @@ def toggle_package(selection, apks, 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"""
"""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("-")
......@@ -122,7 +122,7 @@ def toggle_packages(action, apks, ret):
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
stop = int(multiple[1]) + 1
for j in range(start, stop):
ret = toggle_package(j, apks, ret)
else:
......@@ -131,10 +131,10 @@ def toggle_packages(action, apks, ret):
def ask(zip_path):
""" Ask the user which packages shall be installed or upgraded.
:param zip_path: downloaded artifacts zip containing the apks
:returns: paths inside the zip file of the packages that the user wants
to install, e.g. ["packages/edge/aarch64/postmarketos-ui-phosh-18-r0.apk"] """
"""Ask the user which packages shall be installed or upgraded.
:param zip_path: downloaded artifacts zip containing the apks
:returns: paths inside the zip file of the packages that the user wants
to install, e.g. ["packages/edge/aarch64/postmarketos-ui-phosh-18-r0.apk"]"""
ret = []
apks = get_apks_in_zip(zip_path)
......
# Copyright 2022 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
""" Remove packages previously added with 'mrtest add' """
"""Remove packages previously added with 'mrtest add'"""
import logging
import subprocess
......
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