forked from Mirror/pmbootstrap
commands: add pmbootstrap test (MR 2252)
This is to serve as a place to dump useful internal tests, starting with one that simply parses all available APKINDEX files. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
efce73df2f
commit
62d700c3d8
4 changed files with 46 additions and 0 deletions
|
@ -13,6 +13,7 @@ from .log import Log
|
|||
from .index import Index
|
||||
from .repo_bootstrap import RepoBootstrap
|
||||
from .shutdown import Shutdown
|
||||
from .test import Test
|
||||
|
||||
"""New way to model pmbootstrap subcommands that can be invoked without PmbArgs."""
|
||||
|
||||
|
@ -68,6 +69,8 @@ def run_command(args: PmbArgs):
|
|||
command = RepoBootstrap(args.arch, args.repository)
|
||||
elif args.action == "shutdown":
|
||||
command = Shutdown()
|
||||
elif args.action == "test":
|
||||
command = Test(args.action_test)
|
||||
else:
|
||||
raise NotImplementedError(f"Command '{args.action}' is not implemented.")
|
||||
|
||||
|
|
35
pmb/commands/test.py
Normal file
35
pmb/commands/test.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Copyright 2024 Caleb Connolly
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Any, Dict, List
|
||||
from pmb import commands, logging
|
||||
import pmb.helpers.repo
|
||||
import pmb.parse.apkindex
|
||||
from pmb.core.arch import Arch
|
||||
import time
|
||||
|
||||
|
||||
"""Various internal test commands for performance testing and debugging."""
|
||||
|
||||
def apkindex_parse_all():
|
||||
indexes = pmb.helpers.repo.apkindex_files(Arch.native())
|
||||
|
||||
pkgs = 0
|
||||
indxs = len(indexes)
|
||||
start = time.time()
|
||||
for index in indexes:
|
||||
ret = pmb.parse.apkindex.parse(index)
|
||||
pkgs += len(ret)
|
||||
end = time.time()
|
||||
logging.info(f"Parsed {pkgs} packages from {indxs} APKINDEX files in {end - start:.3f} seconds")
|
||||
|
||||
|
||||
class Test(commands.Command):
|
||||
def __init__(self, action: str):
|
||||
self.action = action
|
||||
|
||||
def run(self):
|
||||
if self.action == "apkindex_parse_all":
|
||||
apkindex_parse_all()
|
||||
|
|
@ -564,6 +564,12 @@ def arguments_lint(subparser):
|
|||
add_packages_arg(lint, nargs="*")
|
||||
|
||||
|
||||
def arguments_test(subparser):
|
||||
test = subparser.add_parser("test", help="Internal pmbootstrap test tools")
|
||||
sub = test.add_subparsers(dest="action_test", required=True)
|
||||
sub.add_parser("apkindex_parse_all", help="parse all APKINDEX files")
|
||||
|
||||
|
||||
def arguments_status(subparser):
|
||||
ret = subparser.add_parser("status",
|
||||
help="show a config and pmaports overview")
|
||||
|
@ -730,6 +736,7 @@ def get_parser():
|
|||
arguments_aportupgrade(sub)
|
||||
arguments_newapkbuild(sub)
|
||||
arguments_lint(sub)
|
||||
arguments_test(sub)
|
||||
arguments_status(sub)
|
||||
arguments_ci(sub)
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class PmbArgs(Namespace):
|
|||
action_initfs: str
|
||||
action_kconfig: str
|
||||
action_netboot: str
|
||||
action_test: str
|
||||
add: str
|
||||
all: bool
|
||||
all_git: str
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue