mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-22 09:39:30 +00:00
Compare commits
29
Commits
2.23.0
..
0bd22a049c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bd22a049c | ||
|
|
71c5d58264 | ||
|
|
22c763ed52 | ||
|
|
36b7972b26 | ||
|
|
4f839a7e6a | ||
|
|
a10b1a9364 | ||
|
|
f0d523492d | ||
|
|
dc4f2be65b | ||
|
|
9ba74413e3 | ||
|
|
d3b569bfa2 | ||
|
|
64a7e9b288 | ||
|
|
5ad8a2a7d0 | ||
|
|
c56a319267 | ||
|
|
96558886bd | ||
|
|
4a745321ec | ||
|
|
4446c950ec | ||
|
|
8d569e6075 | ||
|
|
c375236327 | ||
|
|
ddbb4b06ff | ||
|
|
2d66b67123 | ||
|
|
27cfcd07eb | ||
|
|
2080f1e06f | ||
|
|
2544d44051 | ||
|
|
b07ad8cc0c | ||
|
|
c38cb5f680 | ||
|
|
f776b33310 | ||
|
|
eafa1b417a | ||
|
|
d0aff05be5 | ||
|
|
8a6b71a425 |
No files matched your search
@@ -16,7 +16,7 @@ pacman -S --noconfirm --asdeps base-devel npm python-build python-hatchling pyth
|
||||
# optional dependencies
|
||||
if [[ -z $MINIMAL_INSTALL ]]; then
|
||||
# web server
|
||||
pacman -S --noconfirm --asdeps python-aioauth-client python-aiohttp python-aiohttp-apispec-git python-aiohttp-cors python-aiohttp-jinja2 python-aiohttp-security python-aiohttp-session python-aiohttp-sse-git python-cryptography python-jinja
|
||||
pacman -S --noconfirm --asdeps python-aioauth-client python-aiohttp python-aiohttp-apispec-git python-aiohttp-cors python-aiohttp-jinja2 python-aiohttp-security python-aiohttp-session python-aiohttp-sse python-cryptography python-jinja
|
||||
# additional features
|
||||
pacman -S --noconfirm --asdeps gnupg ipython python-boto3 python-cerberus python-matplotlib python-systemd rsync
|
||||
fi
|
||||
@@ -41,6 +41,7 @@ systemd-machine-id-setup
|
||||
|
||||
# remove unused dependencies
|
||||
pacman -Qdtq | pacman -Rscn --noconfirm -
|
||||
find "/var/cache/pacman/pkg" -type f -delete
|
||||
|
||||
# initial setup command as root
|
||||
[[ -z $MINIMAL_INSTALL ]] && WEB_ARGS=("--web-port" "8080")
|
||||
@@ -60,6 +61,6 @@ sudo -u ahriman -- ahriman --log-handler console package-add --now ahriman
|
||||
# check if package was actually installed
|
||||
test -n "$(find "/var/lib/ahriman/repository/github/x86_64" -name "ahriman*pkg*")"
|
||||
# run package check
|
||||
sudo -u ahriman -- ahriman repo-update
|
||||
sudo -u ahriman -- ahriman --log-handler console repo-update --refresh
|
||||
# stop web service lol
|
||||
[[ -z $WEB_PID ]] || kill $WEB_PID
|
||||
@@ -103,11 +103,11 @@ jobs:
|
||||
|
||||
- name: Update packages
|
||||
run: |
|
||||
sudo -u ahriman ahriman \
|
||||
! sudo -u ahriman ahriman \
|
||||
--log-handler "$AHRIMAN_OUTPUT" \
|
||||
repo-update \
|
||||
--exit-code \
|
||||
|| true
|
||||
--refresh
|
||||
|
||||
- name: Add patch
|
||||
run: |
|
||||
|
||||
+21
-23
@@ -1,10 +1,14 @@
|
||||
[tool.pylint.main]
|
||||
init-hook = "sys.path.append('tools')"
|
||||
load-plugins = [
|
||||
"pylint.extensions.docparams",
|
||||
"pylint.extensions.bad_builtin",
|
||||
"pylint.extensions.check_elif",
|
||||
"pylint.extensions.docparams",
|
||||
"pylint.extensions.overlapping_exceptions",
|
||||
"pylint.extensions.typing",
|
||||
"pylint_plugins.definition_order",
|
||||
"pylint_plugins.import_order",
|
||||
"pylint_plugins.type_annotations",
|
||||
]
|
||||
|
||||
[tool.pylint.classes]
|
||||
@@ -17,29 +21,23 @@ max-parents = 15
|
||||
|
||||
[tool.pylint."messages control"]
|
||||
disable = [
|
||||
"raw-checker-failed",
|
||||
"bad-inline-option",
|
||||
"locally-disabled",
|
||||
"file-ignored",
|
||||
"suppressed-message",
|
||||
"useless-suppression",
|
||||
"deprecated-pragma",
|
||||
"use-symbolic-message-instead",
|
||||
"use-implicit-booleaness-not-comparison-to-string",
|
||||
"use-implicit-booleaness-not-comparison-to-zero",
|
||||
"missing-module-docstring",
|
||||
"line-too-long",
|
||||
"no-name-in-module",
|
||||
"import-outside-toplevel",
|
||||
"invalid-name",
|
||||
"raise-missing-from",
|
||||
"wrong-import-order",
|
||||
"too-few-public-methods",
|
||||
"too-many-instance-attributes",
|
||||
"broad-exception-caught",
|
||||
"fixme",
|
||||
"too-many-arguments",
|
||||
"duplicate-code",
|
||||
"cyclic-import",
|
||||
"duplicate-code",
|
||||
"fixme",
|
||||
"import-outside-toplevel",
|
||||
"line-too-long",
|
||||
"missing-module-docstring",
|
||||
"no-name-in-module",
|
||||
"raise-missing-from",
|
||||
"raw-checker-failed",
|
||||
"suppressed-message",
|
||||
"too-few-public-methods",
|
||||
"too-many-arguments",
|
||||
"too-many-instance-attributes",
|
||||
"too-many-positional-arguments",
|
||||
"wrong-import-order",
|
||||
]
|
||||
|
||||
[tool.pylint.string]
|
||||
check-quote-consistency = true
|
||||
@@ -222,6 +222,7 @@ Again, the most checks can be performed by `tox` command, though some additional
|
||||
* On the other hand, it is allowed to change method signatures, however, it is recommended to add new parameters as optional if possible. Deprecated API can be dropped during major release.
|
||||
* Enumerations (`Enum` classes) are allowed and recommended. However, it is recommended to use `StrEnum` class if there are from/to string conversions and `IntEnum` otherwise.
|
||||
* `Generator` return type is not allowed. Generator functions must return generic `Iterator` object. Documentation should be described as `Yields`, however, because of pylint checks. Unfortunately, `Iterable` return type is not available for generators also, because of specific `contextlib.contextmanager` case.
|
||||
* Tests must not be parametrized. It is better to write separate test, which covers specific line of code rather than testing all over again.
|
||||
|
||||
### Other checks
|
||||
|
||||
@@ -229,6 +230,17 @@ The projects also uses typing checks (provided by `mypy`) and some linter checks
|
||||
|
||||
Frontend checks normally are performed by `eslint` (e.g. `npx run eslint`).
|
||||
|
||||
## AI usage policy
|
||||
|
||||
AI tools may be used when working on the project, including writing code, tests, and documentation, debugging problems, and preparing issue reports. Contributors remain responsible for everything they submit, including content generated or suggested by AI.
|
||||
|
||||
* Review and understand every submitted change. You must be able to explain the implementation, respond to review feedback, and correct any problems.
|
||||
* Do not list AI tools as commit authors or co-authors, including in `Co-authored-by` trailers. Authorship must remain with the human contributors responsible for the changes.
|
||||
* Discussions in issues and pull requests must be led by humans. Participate personally, explain your reasoning, and respond to questions and review feedback yourself. AI tools may help with wording or translation, but must not conduct discussions on your behalf.
|
||||
* Verify claims, references, and reproduction steps before submitting an issue or pull request. Do not submit unreviewed AI output or claim that checks passed unless they were run and you verified the results.
|
||||
|
||||
Maintainers may close submissions that do not meet these requirements. Using AI does not transfer responsibility for reviewing or fixing a contribution to maintainers.
|
||||
|
||||
## Developers how to
|
||||
|
||||
### Run automated checks
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.TH AHRIMAN "1" "2026\-10\-20" "ahriman 2.23.0" "ArcH linux ReposItory MANager"
|
||||
.TH AHRIMAN "1" "2026\-10\-30" "ahriman 2.23.6" "ArcH linux ReposItory MANager"
|
||||
.SH NAME
|
||||
ahriman \- ArcH linux ReposItory MANager
|
||||
.SH SYNOPSIS
|
||||
|
||||
@@ -17,4 +17,4 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
__version__ = "2.23.0"
|
||||
__version__ = "2.23.6"
|
||||
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2021-2026 ahriman team.
|
||||
#
|
||||
# This file is part of ahriman
|
||||
# (see https://github.com/arcan1s/ahriman).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import sys
|
||||
|
||||
from ahriman.application.ahriman import run
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run())
|
||||
@@ -22,7 +22,7 @@ from collections.abc import Callable, Iterable
|
||||
from ahriman.application.application.application_packages import ApplicationPackages
|
||||
from ahriman.application.application.application_repository import ApplicationRepository
|
||||
from ahriman.core.formatters import UpdatePrinter
|
||||
from ahriman.core.tree import Tree
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
@@ -95,43 +95,39 @@ class Application(ApplicationPackages, ApplicationRepository):
|
||||
"""
|
||||
self.repository.triggers.on_stop()
|
||||
|
||||
def print_updates(self, packages: list[Package], *, log_fn: Callable[[str], None]) -> None:
|
||||
def print_updates(self, plan: BuildPlan, log_fn: Callable[[str], None], *, bump_pkgrel: bool = True) -> None:
|
||||
"""
|
||||
print list of packages to be built. This method will build dependency tree and print updates accordingly
|
||||
print packages and their reasons, grouped by dependency step
|
||||
|
||||
Args:
|
||||
packages(list[Package]): package list to be printed
|
||||
plan(BuildPlan): packages and selection reasons to be printed
|
||||
log_fn(Callable[[str], None]): logger function to log updates
|
||||
bump_pkgrel(bool, optional): whether duplicate releases are expected to increment
|
||||
"""
|
||||
local_versions = {package.base: package.version for package in self.repository.packages()}
|
||||
UpdatePrinter(plan, local_versions, bump_pkgrel=bump_pkgrel)(verbose=True, log_fn=log_fn)
|
||||
|
||||
tree = Tree.resolve(packages)
|
||||
for level in tree:
|
||||
for package in level:
|
||||
UpdatePrinter(package, local_versions.get(package.base))(verbose=True, log_fn=log_fn, separator=" -> ")
|
||||
|
||||
def with_dependencies(self, packages: list[Package], *, process_dependencies: bool) -> list[Package]:
|
||||
def with_dependencies(self, plan: BuildPlan, *, process_dependencies: bool) -> BuildPlan:
|
||||
"""
|
||||
add missing dependencies to list of packages. This will extract known packages, check dependencies of
|
||||
the supplied packages and add packages which are not presented in the list of known packages.
|
||||
add missing dependencies to a build plan and record which packages require them
|
||||
|
||||
Args:
|
||||
packages(list[Package]): list of source packages of which dependencies have to be processed
|
||||
plan(BuildPlan): selected packages and their reasons
|
||||
process_dependencies(bool): if set to ``False``, dependencies will not be processed
|
||||
|
||||
Returns:
|
||||
list[Package]: updated packages list. Packager for dependencies will be copied from the original package
|
||||
BuildPlan: selected packages and their dependencies
|
||||
|
||||
Examples:
|
||||
In the most cases, in order to avoid build failure, it is required to add missing packages, which can be
|
||||
done by calling::
|
||||
|
||||
>>> application = ...
|
||||
>>> packages = application.with_dependencies(packages, process_dependencies=True)
|
||||
>>> application.print_updates(packages, log_fn=print)
|
||||
>>> plan = application.with_dependencies(plan, process_dependencies=True)
|
||||
>>> application.update(plan)
|
||||
"""
|
||||
if not process_dependencies or not packages:
|
||||
return packages
|
||||
if not process_dependencies or not plan:
|
||||
return plan
|
||||
|
||||
def missing_dependencies(sources: Iterable[Package]) -> dict[str, str | None]:
|
||||
# append list of known packages with packages which are in current sources
|
||||
@@ -157,20 +153,30 @@ class Application(ApplicationPackages, ApplicationRepository):
|
||||
leaf = Package.from_build(source_dir, self.repository.repository_id.architecture, packager)
|
||||
else:
|
||||
leaf = Package.from_aur(package_name, packager, include_provides=True)
|
||||
portion[leaf.base] = leaf
|
||||
# for split packages we need to load all available subpackages here
|
||||
if (existing := portion.get(leaf.base)) is not None:
|
||||
leaf.packages.update(existing.packages)
|
||||
|
||||
portion[leaf.base] = leaf
|
||||
# register package in the database
|
||||
self.reporter.set_unknown(leaf)
|
||||
|
||||
return portion
|
||||
|
||||
known_packages = self._known_packages()
|
||||
with_dependencies: dict[str, Package] = {}
|
||||
for package in packages:
|
||||
for package in plan:
|
||||
with self.in_package_context(package.base, package.version): # use the same context for the logger
|
||||
try:
|
||||
with_dependencies |= new_packages(package)
|
||||
packages = new_packages(package)
|
||||
except Exception:
|
||||
self.logger.exception("could not process dependencies of %s, skip the package", package.base)
|
||||
plan.remove(package.base)
|
||||
self.reporter.set_failed(package.base)
|
||||
continue
|
||||
|
||||
return list(with_dependencies.values())
|
||||
# update existing package
|
||||
plan.add(packages.pop(package.base))
|
||||
# append dependencies
|
||||
plan.update(packages.values(), BuildPlanReason.REQUIRED_BY, package.base)
|
||||
|
||||
return plan
|
||||
@@ -38,14 +38,14 @@ class ApplicationProperties(LazyLogging):
|
||||
"""
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration, *, report: bool,
|
||||
refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.Disabled) -> None:
|
||||
refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.DISABLED) -> None:
|
||||
"""
|
||||
Args:
|
||||
repository_id(RepositoryId): repository unique identifier
|
||||
configuration(Configuration): configuration instance
|
||||
report(bool): force enable or disable reporting
|
||||
refresh_pacman_database(PacmanSynchronization, optional): pacman database synchronization level
|
||||
(Default value = PacmanSynchronization.Disabled)
|
||||
(Default value = PacmanSynchronization.DISABLED)
|
||||
"""
|
||||
self.configuration = configuration
|
||||
self.repository_id = repository_id
|
||||
|
||||
@@ -23,6 +23,7 @@ from ahriman.application.application.application_properties import ApplicationPr
|
||||
from ahriman.application.application.workers import Updater
|
||||
from ahriman.core.build_tools.sources import Sources
|
||||
from ahriman.core.exceptions import UnknownPackageError
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.result import Result
|
||||
@@ -182,7 +183,7 @@ class ApplicationRepository(ApplicationProperties):
|
||||
return result
|
||||
|
||||
def updates(self, filter_packages: Iterable[str], *,
|
||||
aur: bool, local: bool, manual: bool, vcs: bool, check_files: bool) -> list[Package]:
|
||||
aur: bool, local: bool, manual: bool, vcs: bool, check_files: bool) -> BuildPlan:
|
||||
"""
|
||||
get list of packages to run update process
|
||||
|
||||
@@ -193,25 +194,24 @@ class ApplicationRepository(ApplicationProperties):
|
||||
manual(bool): include or exclude manual updates
|
||||
vcs(bool): enable or disable checking of VCS packages
|
||||
check_files(bool): check for broken dependencies
|
||||
|
||||
Returns:
|
||||
list[Package]: list of out-of-dated packages
|
||||
BuildPlan: selected packages and their reasons
|
||||
"""
|
||||
updates = {}
|
||||
plan = BuildPlan()
|
||||
|
||||
# always add already built packages, because they will be always added
|
||||
updates.update({
|
||||
package.base: package
|
||||
for package in self.repository.load_archives(self.repository.packages_built())
|
||||
})
|
||||
plan.update(self.repository.load_archives(self.repository.packages_built()), BuildPlanReason.PRE_BUILT)
|
||||
|
||||
if aur:
|
||||
updates.update({package.base: package for package in self.repository.updates_aur(filter_packages, vcs=vcs)})
|
||||
if local:
|
||||
updates.update({package.base: package for package in self.repository.updates_local(vcs=vcs)})
|
||||
if manual:
|
||||
updates.update({package.base: package for package in self.repository.updates_manual()})
|
||||
plan.update(self.repository.updates_manual(), BuildPlanReason.MANUAL_REQUEST)
|
||||
if aur:
|
||||
plan.update(self.repository.updates_aur(filter_packages, vcs=vcs), BuildPlanReason.REGULAR_UPDATE)
|
||||
if local:
|
||||
plan.update(self.repository.updates_local(vcs=vcs), BuildPlanReason.LOCAL_SOURCE_UPDATE)
|
||||
if check_files:
|
||||
updates.update({package.base: package for package in self.repository.updates_dependencies(filter_packages)})
|
||||
plan.update(
|
||||
self.repository.updates_dependencies(filter_packages),
|
||||
BuildPlanReason.BROKEN_IMPLICIT_DEPENDENCY,
|
||||
)
|
||||
|
||||
return [package for _, package in sorted(updates.items())]
|
||||
return plan
|
||||
@@ -85,7 +85,7 @@ class Add(Handler):
|
||||
action=argparse.BooleanOptionalAction, default=True)
|
||||
parser.add_argument("-n", "--now", help="run update function after", action="store_true")
|
||||
parser.add_argument("-s", "--source", help="explicitly specify the package source for this command",
|
||||
type=PackageSource, choices=tuple(PackageSource), default=PackageSource.Auto)
|
||||
type=PackageSource, choices=tuple(PackageSource), default=PackageSource.AUTO)
|
||||
parser.add_argument("-u", "--username", help="build as user", default=extract_user())
|
||||
parser.add_argument("-v", "--variable", help="apply specified makepkg variables to the next build",
|
||||
action="append")
|
||||
|
||||
@@ -50,10 +50,10 @@ class Archives(Handler):
|
||||
application = Application(repository_id, configuration, report=True)
|
||||
|
||||
match args.action:
|
||||
case Action.List:
|
||||
case Action.LIST:
|
||||
archives = application.repository.package_archives(args.package)
|
||||
for package in archives:
|
||||
PackagePrinter(package, BuildStatus(BuildStatusEnum.Success))(verbose=args.info)
|
||||
PackagePrinter(package, BuildStatus(BuildStatusEnum.SUCCESS))(verbose=args.info)
|
||||
|
||||
Archives.check_status(args.exit_code, bool(archives))
|
||||
|
||||
@@ -75,7 +75,7 @@ class Archives(Handler):
|
||||
action="store_true")
|
||||
parser.add_argument("--info", help="show additional package information",
|
||||
action=argparse.BooleanOptionalAction, default=False)
|
||||
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.LIST, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
arguments = [_set_package_archives_parser]
|
||||
@@ -50,11 +50,11 @@ class Change(Handler):
|
||||
client = Application(repository_id, configuration, report=True).reporter
|
||||
|
||||
match args.action:
|
||||
case Action.List:
|
||||
case Action.LIST:
|
||||
changes = client.package_changes_get(args.package)
|
||||
ChangesPrinter(changes)(verbose=True, separator="")
|
||||
Change.check_status(args.exit_code, changes.changes is not None)
|
||||
case Action.Remove:
|
||||
case Action.REMOVE:
|
||||
client.package_changes_update(args.package, Changes())
|
||||
|
||||
@staticmethod
|
||||
@@ -75,7 +75,7 @@ class Change(Handler):
|
||||
parser.add_argument("package", help="package base")
|
||||
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
|
||||
action="store_true")
|
||||
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.LIST, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
@@ -92,7 +92,7 @@ class Change(Handler):
|
||||
parser = root.add_parser("package-changes-remove", help="remove package changes",
|
||||
description="remove the package changes stored remotely")
|
||||
parser.add_argument("package", help="package base")
|
||||
parser.set_defaults(action=Action.Remove, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.REMOVE, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
arguments = [_set_package_changes_parser, _set_package_changes_remove_parser]
|
||||
@@ -103,7 +103,7 @@ class Copy(Handler):
|
||||
for source in package.packages.values()
|
||||
if source.filename is not None
|
||||
]
|
||||
application.add(source_paths, PackageSource.Archive)
|
||||
application.add(source_paths, PackageSource.ARCHIVE)
|
||||
|
||||
# copy metadata
|
||||
application.reporter.package_changes_update(
|
||||
@@ -112,6 +112,6 @@ class Copy(Handler):
|
||||
application.reporter.package_dependencies_update(
|
||||
package.base, source_application.reporter.package_dependencies_get(package.base)
|
||||
)
|
||||
application.reporter.package_update(package, BuildStatusEnum.Pending)
|
||||
application.reporter.package_update(package, BuildStatusEnum.PENDING)
|
||||
|
||||
arguments = [_set_package_copy_parser]
|
||||
@@ -46,10 +46,10 @@ class Hold(Handler):
|
||||
client = Application(repository_id, configuration, report=True).reporter
|
||||
|
||||
match args.action:
|
||||
case Action.Remove:
|
||||
case Action.REMOVE:
|
||||
for package in args.package:
|
||||
client.package_hold_update(package, enabled=False)
|
||||
case Action.Update:
|
||||
case Action.UPDATE:
|
||||
for package in args.package:
|
||||
client.package_hold_update(package, enabled=True)
|
||||
|
||||
@@ -67,7 +67,7 @@ class Hold(Handler):
|
||||
parser = root.add_parser("package-hold", help="hold package",
|
||||
description="hold package from automatic updates")
|
||||
parser.add_argument("package", help="package base", nargs="+")
|
||||
parser.set_defaults(action=Action.Update, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.UPDATE, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
@@ -84,7 +84,7 @@ class Hold(Handler):
|
||||
parser = root.add_parser("package-unhold", help="unhold package",
|
||||
description="remove package hold, allowing automatic updates")
|
||||
parser.add_argument("package", help="package base", nargs="+")
|
||||
parser.set_defaults(action=Action.Remove, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.REMOVE, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
arguments = [
|
||||
|
||||
@@ -56,15 +56,15 @@ class Patch(Handler):
|
||||
application.on_start()
|
||||
|
||||
match args.action:
|
||||
case Action.Update if args.variable is not None:
|
||||
case Action.UPDATE if args.variable is not None:
|
||||
patch = Patch.patch_create_from_function(args.variable, args.patch)
|
||||
Patch.patch_set_create(application, args.package, patch)
|
||||
case Action.Update:
|
||||
case Action.UPDATE:
|
||||
package_base, patch = Patch.patch_create_from_diff(args.package, repository_id.architecture, args.track)
|
||||
Patch.patch_set_create(application, package_base, patch)
|
||||
case Action.List:
|
||||
case Action.LIST:
|
||||
Patch.patch_set_list(application, args.package, args.variable, args.exit_code)
|
||||
case Action.Remove:
|
||||
case Action.REMOVE:
|
||||
Patch.patch_set_remove(application, args.package, args.variable)
|
||||
|
||||
@staticmethod
|
||||
@@ -89,7 +89,7 @@ class Patch(Handler):
|
||||
"it must end with ()")
|
||||
parser.add_argument("patch", help="path to file which contains function or variable value. If not set, "
|
||||
"the value will be read from stdin", type=Path, nargs="?")
|
||||
parser.set_defaults(action=Action.Update, architecture="", exit_code=False, lock=None, report=False,
|
||||
parser.set_defaults(action=Action.UPDATE, architecture="", exit_code=False, lock=None, report=False,
|
||||
repository="")
|
||||
return parser
|
||||
|
||||
@@ -111,7 +111,7 @@ class Patch(Handler):
|
||||
action="store_true")
|
||||
parser.add_argument("-v", "--variable", help="if set, show only patches for specified PKGBUILD variables",
|
||||
action="append")
|
||||
parser.set_defaults(action=Action.List, architecture="", lock=None, report=False, repository="", unsafe=True)
|
||||
parser.set_defaults(action=Action.LIST, architecture="", lock=None, report=False, repository="", unsafe=True)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
@@ -132,7 +132,7 @@ class Patch(Handler):
|
||||
"to remove only specified PKGBUILD variables. In case if not set, "
|
||||
"it will remove all patches related to the package",
|
||||
action="append")
|
||||
parser.set_defaults(action=Action.Remove, architecture="", exit_code=False, lock=None, report=False,
|
||||
parser.set_defaults(action=Action.REMOVE, architecture="", exit_code=False, lock=None, report=False,
|
||||
repository="")
|
||||
return parser
|
||||
|
||||
@@ -157,7 +157,7 @@ class Patch(Handler):
|
||||
parser.add_argument("package", help="path to directory with changed files for patch addition/update", type=Path)
|
||||
parser.add_argument("-t", "--track", help="files which has to be tracked", action="append",
|
||||
default=["*.diff", "*.patch"])
|
||||
parser.set_defaults(action=Action.Update, architecture="", exit_code=False, lock=None, report=False,
|
||||
parser.set_defaults(action=Action.UPDATE, architecture="", exit_code=False, lock=None, report=False,
|
||||
repository="", variable=None)
|
||||
return parser
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ class Pkgbuild(Handler):
|
||||
client = Application(repository_id, configuration, report=True).reporter
|
||||
|
||||
match args.action:
|
||||
case Action.List:
|
||||
case Action.LIST:
|
||||
changes = client.package_changes_get(args.package)
|
||||
PkgbuildPrinter(changes)(verbose=True, separator="")
|
||||
Pkgbuild.check_status(args.exit_code, changes.pkgbuild is not None)
|
||||
case Action.Remove:
|
||||
case Action.REMOVE:
|
||||
changes = client.package_changes_get(args.package)
|
||||
client.package_changes_update(args.package, replace(changes, pkgbuild=None))
|
||||
|
||||
@@ -77,7 +77,7 @@ class Pkgbuild(Handler):
|
||||
parser.add_argument("package", help="package base")
|
||||
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
|
||||
action="store_true")
|
||||
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.LIST, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
@@ -94,7 +94,7 @@ class Pkgbuild(Handler):
|
||||
parser = root.add_parser("package-pkgbuild-remove", help="remove package pkgbuild",
|
||||
description="remove the package PKGBUILD stored remotely")
|
||||
parser.add_argument("package", help="package base")
|
||||
parser.set_defaults(action=Action.Remove, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.REMOVE, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
arguments = [_set_package_pkgbuild_parser, _set_package_pkgbuild_remove_parser]
|
||||
@@ -21,8 +21,10 @@ import argparse
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||
from ahriman.application.handlers.update import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.utils import extract_user
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
@@ -52,12 +54,14 @@ class Rebuild(Handler):
|
||||
packages = Rebuild.extract_packages(application, args.status, from_database=args.from_database)
|
||||
packages = application.repository.packages_depend_on(packages, args.depends_on)
|
||||
|
||||
Rebuild.check_status(args.exit_code, packages)
|
||||
plan = BuildPlan().update(packages, BuildPlanReason.REBUILD)
|
||||
application.print_updates(plan, Update.log_fn(application, dry_run=args.dry_run), bump_pkgrel=args.increment)
|
||||
|
||||
if args.dry_run:
|
||||
application.print_updates(packages, log_fn=print)
|
||||
Rebuild.check_status(args.exit_code, plan)
|
||||
return
|
||||
|
||||
result = application.update(packages, Packagers(args.username), bump_pkgrel=args.increment)
|
||||
result = application.update(plan, Packagers(args.username), bump_pkgrel=args.increment)
|
||||
Rebuild.check_status(args.exit_code, not result.is_empty)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -82,7 +82,7 @@ class Rollback(Handler):
|
||||
parser.add_argument("-u", "--username", help="build as user", default=extract_user())
|
||||
parser.set_defaults(aur=False, changes=False, check_files=False, dependencies=False, dry_run=False,
|
||||
exit_code=True, increment=False, now=True, local=False, manual=False, refresh=False,
|
||||
source=PackageSource.Archive, variable=None, vcs=False)
|
||||
source=PackageSource.ARCHIVE, variable=None, vcs=False)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -23,6 +23,7 @@ from ahriman import __version__
|
||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.formatters import UpdatePrinter
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
|
||||
@@ -56,7 +57,8 @@ class ServiceUpdates(Handler):
|
||||
if same_version:
|
||||
return
|
||||
|
||||
UpdatePrinter(remote, local_version)(verbose=True, separator=" -> ")
|
||||
plan = BuildPlan().update([remote], BuildPlanReason.REGULAR_UPDATE)
|
||||
UpdatePrinter(plan, {remote.base: local_version})(verbose=True)
|
||||
ServiceUpdates.check_status(args.exit_code, same_version)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -85,7 +85,7 @@ class Statistics(Handler):
|
||||
parser.add_argument("package", help="fetch only events for the specified package", nargs="?")
|
||||
parser.add_argument("--chart", help="create updates chart and save it to the specified path", type=Path)
|
||||
parser.add_argument("-e", "--event", help="event type filter",
|
||||
type=EventType, choices=tuple(EventType), default=EventType.PackageUpdated)
|
||||
type=EventType, choices=tuple(EventType), default=EventType.PACKAGE_UPDATED)
|
||||
parser.add_argument("--from-date", help="only fetch events which are newer than the date")
|
||||
parser.add_argument("--limit", help="limit response by specified amount of events", type=int, default=-1)
|
||||
parser.add_argument("--offset", help="skip specified amount of events", type=int, default=0)
|
||||
|
||||
@@ -49,14 +49,14 @@ class StatusUpdate(Handler):
|
||||
client = Application(repository_id, configuration, report=True).reporter
|
||||
|
||||
match args.action:
|
||||
case Action.Update if args.package:
|
||||
case Action.UPDATE if args.package:
|
||||
# update packages statuses
|
||||
for package in args.package:
|
||||
client.package_status_update(package, args.status)
|
||||
case Action.Update:
|
||||
case Action.UPDATE:
|
||||
# update service status
|
||||
client.status_update(args.status)
|
||||
case Action.Remove:
|
||||
case Action.REMOVE:
|
||||
for package in args.package:
|
||||
client.package_remove(package)
|
||||
|
||||
@@ -76,7 +76,7 @@ class StatusUpdate(Handler):
|
||||
epilog="Please note that this subcommand does not remove the package itself, it just "
|
||||
"clears the status page.")
|
||||
parser.add_argument("package", help="remove specified packages from status page", nargs="+")
|
||||
parser.set_defaults(action=Action.Remove, lock=None, quiet=True, report=False, unsafe=True)
|
||||
parser.set_defaults(action=Action.REMOVE, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
@@ -96,8 +96,8 @@ class StatusUpdate(Handler):
|
||||
"If no packages supplied, service status will be updated",
|
||||
nargs="*")
|
||||
parser.add_argument("-s", "--status", help="new package build status",
|
||||
type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.Success)
|
||||
parser.set_defaults(action=Action.Update, lock=None, quiet=True, report=False, unsafe=True)
|
||||
type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.SUCCESS)
|
||||
parser.set_defaults(action=Action.UPDATE, lock=None, quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
@@ -114,8 +114,8 @@ class StatusUpdate(Handler):
|
||||
parser = root.add_parser("repo-status-update", help="update repository status",
|
||||
description="update repository status on the status page")
|
||||
parser.add_argument("-s", "--status", help="new status",
|
||||
type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.Success)
|
||||
parser.set_defaults(action=Action.Update, lock=None, package=[], quiet=True, report=False, unsafe=True)
|
||||
type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.SUCCESS)
|
||||
parser.set_defaults(action=Action.UPDATE, lock=None, package=[], quiet=True, report=False, unsafe=True)
|
||||
return parser
|
||||
|
||||
arguments = [
|
||||
|
||||
@@ -147,20 +147,19 @@ class Update(Handler):
|
||||
application(Application): application instance
|
||||
args(argparse.Namespace): command line args
|
||||
"""
|
||||
packages = application.updates(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
||||
check_files=args.check_files)
|
||||
plan = application.updates(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
||||
check_files=args.check_files)
|
||||
plan = application.with_dependencies(plan, process_dependencies=args.dependencies)
|
||||
if args.changes: # generate changes if requested
|
||||
application.changes(packages)
|
||||
application.changes(plan)
|
||||
|
||||
application.print_updates(plan, Update.log_fn(application, dry_run=args.dry_run), bump_pkgrel=args.increment)
|
||||
if args.dry_run: # exit from application if no build requested
|
||||
Update.check_status(args.exit_code, packages) # status code check
|
||||
Update.check_status(args.exit_code, plan) # status code check
|
||||
return
|
||||
|
||||
packages = application.with_dependencies(packages, process_dependencies=args.dependencies)
|
||||
packagers = Packagers(args.username, {package.base: package.packager for package in packages})
|
||||
|
||||
application.print_updates(packages, log_fn=application.logger.info)
|
||||
result = application.update(packages, packagers, bump_pkgrel=args.increment)
|
||||
packagers = Packagers(args.username, {package.base: package.packager for package in plan})
|
||||
result = application.update(plan, packagers, bump_pkgrel=args.increment)
|
||||
Update.check_status(args.exit_code, not result.is_empty)
|
||||
|
||||
arguments = [
|
||||
|
||||
@@ -53,17 +53,17 @@ class Users(Handler):
|
||||
database = SQLite.load(configuration)
|
||||
|
||||
match args.action:
|
||||
case Action.Update:
|
||||
case Action.UPDATE:
|
||||
user = Users.user_create(args)
|
||||
# if password is left blank we are not going to require salt to be set
|
||||
salt = configuration.get("auth", "salt", fallback="") if user.password else ""
|
||||
database.user_update(user.hash_password(salt))
|
||||
case Action.List:
|
||||
case Action.LIST:
|
||||
users = database.user_list(args.username, args.role)
|
||||
for user in users:
|
||||
UserPrinter(user)(verbose=True)
|
||||
Users.check_status(args.exit_code, users)
|
||||
case Action.Remove:
|
||||
case Action.REMOVE:
|
||||
database.user_remove(args.username)
|
||||
|
||||
@staticmethod
|
||||
@@ -88,8 +88,8 @@ class Users(Handler):
|
||||
"-p", "--password", help="user password. Blank password will be treated as empty password, "
|
||||
"which is in particular must be used for OAuth2 authorization type.")
|
||||
parser.add_argument("-R", "--role", help="user access level",
|
||||
type=UserAccess, choices=tuple(UserAccess), default=UserAccess.Read)
|
||||
parser.set_defaults(action=Action.Update, architecture="", exit_code=False, lock=None, quiet=True,
|
||||
type=UserAccess, choices=tuple(UserAccess), default=UserAccess.READ)
|
||||
parser.set_defaults(action=Action.UPDATE, architecture="", exit_code=False, lock=None, quiet=True,
|
||||
report=False, repository="")
|
||||
return parser
|
||||
|
||||
@@ -110,7 +110,7 @@ class Users(Handler):
|
||||
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
|
||||
action="store_true")
|
||||
parser.add_argument("-R", "--role", help="filter users by role", type=UserAccess, choices=tuple(UserAccess))
|
||||
parser.set_defaults(action=Action.List, architecture="", lock=None, quiet=True, report=False, repository="",
|
||||
parser.set_defaults(action=Action.LIST, architecture="", lock=None, quiet=True, report=False, repository="",
|
||||
unsafe=True)
|
||||
return parser
|
||||
|
||||
@@ -128,7 +128,7 @@ class Users(Handler):
|
||||
parser = root.add_parser("user-remove", help="remove user",
|
||||
description="remove user from the user mapping and update the configuration")
|
||||
parser.add_argument("username", help="username for web service")
|
||||
parser.set_defaults(action=Action.Remove, architecture="", exit_code=False, lock=None, quiet=True,
|
||||
parser.set_defaults(action=Action.REMOVE, architecture="", exit_code=False, lock=None, quiet=True,
|
||||
report=False, repository="")
|
||||
return parser
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ class Lock(LazyLogging):
|
||||
self.check_user()
|
||||
self.check_version()
|
||||
self.lock()
|
||||
self.reporter.status_update(BuildStatusEnum.Building)
|
||||
self.reporter.status_update(BuildStatusEnum.BUILDING)
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type: type[Exception] | None, exc_val: Exception | None,
|
||||
@@ -226,6 +226,6 @@ class Lock(LazyLogging):
|
||||
Literal[False]: always ``False`` (do not suppress any exception)
|
||||
"""
|
||||
self.clear()
|
||||
status = BuildStatusEnum.Success if exc_val is None else BuildStatusEnum.Failed
|
||||
status = BuildStatusEnum.SUCCESS if exc_val is None else BuildStatusEnum.FAILED
|
||||
self.reporter.status_update(status)
|
||||
return False
|
||||
@@ -96,7 +96,7 @@ class Pacman(LazyLogging):
|
||||
self.database_init(handle, self.repository_id.name, self.repository_id.architecture)
|
||||
|
||||
if use_ahriman_cache and refresh_database:
|
||||
self.database_sync(handle, force=refresh_database == PacmanSynchronization.Force)
|
||||
self.database_sync(handle, force=refresh_database == PacmanSynchronization.FORCE)
|
||||
|
||||
return handle
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import re
|
||||
import shlex
|
||||
import tree_sitter_bash
|
||||
|
||||
from collections.abc import Iterator
|
||||
from collections.abc import Iterable, Iterator
|
||||
from enum import StrEnum
|
||||
from tree_sitter import Language, Node, Parser
|
||||
from typing import IO, cast
|
||||
|
||||
from ahriman.core.configuration.shell_interpolator import ShellInterpolator
|
||||
from ahriman.core.exceptions import PkgbuildParserError
|
||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||
|
||||
@@ -35,32 +35,32 @@ class PkgbuildNodeType(StrEnum):
|
||||
tree-sitter node types used by parser
|
||||
|
||||
Attributes:
|
||||
Append(PkgbuildNodeType): append node
|
||||
Array(PkgbuildNodeType): array node
|
||||
Comment(PkgbuildNodeType): comment node
|
||||
Concatenation(PkgbuildNodeType): concatenation node
|
||||
Error(PkgbuildNodeType): syntax error node
|
||||
FunctionDefinition(PkgbuildNodeType): function definition node
|
||||
Number(PkgbuildNodeType): numeric word node
|
||||
RawString(PkgbuildNodeType): single-quoted string node
|
||||
String(PkgbuildNodeType): double-quoted string node
|
||||
StringContent(PkgbuildNodeType): string content node
|
||||
VariableAssignment(PkgbuildNodeType): assignment node
|
||||
Word(PkgbuildNodeType): word node
|
||||
APPEND(PkgbuildNodeType): append node
|
||||
ARRAY(PkgbuildNodeType): array node
|
||||
COMMENT(PkgbuildNodeType): comment node
|
||||
CONCATENATION(PkgbuildNodeType): concatenation node
|
||||
ERROR(PkgbuildNodeType): syntax error node
|
||||
FUNCTION_DEFINITION(PkgbuildNodeType): function definition node
|
||||
NUMBER(PkgbuildNodeType): numeric word node
|
||||
RAW_STRING(PkgbuildNodeType): single-quoted string node
|
||||
STRING(PkgbuildNodeType): double-quoted string node
|
||||
STRING_CONTENT(PkgbuildNodeType): string content node
|
||||
VARIABLE_ASSIGNMENT(PkgbuildNodeType): assignment node
|
||||
WORD(PkgbuildNodeType): word node
|
||||
"""
|
||||
|
||||
Append = "+="
|
||||
Array = "array"
|
||||
Comment = "comment"
|
||||
Concatenation = "concatenation"
|
||||
Error = "ERROR"
|
||||
FunctionDefinition = "function_definition"
|
||||
Number = "number"
|
||||
RawString = "raw_string"
|
||||
String = "string"
|
||||
StringContent = "string_content"
|
||||
VariableAssignment = "variable_assignment"
|
||||
Word = "word"
|
||||
APPEND = "+="
|
||||
ARRAY = "array"
|
||||
COMMENT = "comment"
|
||||
CONCATENATION = "concatenation"
|
||||
ERROR = "ERROR"
|
||||
FUNCTION_DEFINITION = "function_definition"
|
||||
NUMBER = "number"
|
||||
RAW_STRING = "raw_string"
|
||||
STRING = "string"
|
||||
STRING_CONTENT = "string_content"
|
||||
VARIABLE_ASSIGNMENT = "variable_assignment"
|
||||
WORD = "word"
|
||||
|
||||
|
||||
class PkgbuildNodeField(StrEnum):
|
||||
@@ -68,17 +68,17 @@ class PkgbuildNodeField(StrEnum):
|
||||
tree-sitter node fields used by parser
|
||||
|
||||
Attributes:
|
||||
Body(PkgbuildNodeField): function body field
|
||||
Name(PkgbuildNodeField): variable or function name field
|
||||
Value(PkgbuildNodeField): assignment value field
|
||||
BODY(PkgbuildNodeField): function body field
|
||||
NAME(PkgbuildNodeField): variable or function name field
|
||||
VALUE(PkgbuildNodeField): assignment value field
|
||||
"""
|
||||
|
||||
Body = "body"
|
||||
Name = "name"
|
||||
Value = "value"
|
||||
BODY = "body"
|
||||
NAME = "name"
|
||||
VALUE = "value"
|
||||
|
||||
|
||||
class PkgbuildParser:
|
||||
class PkgbuildParser(Iterable[PkgbuildPatch]):
|
||||
"""
|
||||
PKGBUILD parser implementation in python
|
||||
|
||||
@@ -97,48 +97,38 @@ class PkgbuildParser:
|
||||
original source, with their formatting preserved. Assignments inside shell statements and control-flow nodes are
|
||||
extracted without checking whether those statements would run.
|
||||
|
||||
Each iteration parses the stored source independently, starting from the beginning.
|
||||
|
||||
Examples:
|
||||
Parse package assignments::
|
||||
|
||||
>>> source = b"pkgname=example\\npkgver=1\\n"
|
||||
>>> for patch in PkgbuildParser(BytesIO(source)).parse():
|
||||
>>> for patch in PkgbuildParser(BytesIO(source)):
|
||||
... print(patch.key, patch.value)
|
||||
|
||||
Function bodies are returned as function patches::
|
||||
|
||||
>>> source = b"pkgver() { printf 1; }"
|
||||
>>> for patch in list(PkgbuildParser(BytesIO(source)).parse())
|
||||
>>> for patch in PkgbuildParser(BytesIO(source)):
|
||||
... print(patch.key, patch.value)
|
||||
"""
|
||||
|
||||
_BRACE_EXPANSION = re.compile(r"(.*)\{([^{}]+)\}(.*)")
|
||||
_ESCAPED_CHARACTERS = {
|
||||
"\\$": "$",
|
||||
"\\`": "`",
|
||||
"\\\"": "\"",
|
||||
"\\\n": "",
|
||||
}
|
||||
|
||||
def __init__(self, stream: IO[bytes]) -> None:
|
||||
""""""
|
||||
"""
|
||||
Args:
|
||||
stream(IO[bytes]): input PKGBUILD stream
|
||||
"""
|
||||
self._content = stream.read()
|
||||
|
||||
@staticmethod
|
||||
def _expand_array(value: str, *, expand: bool = True) -> list[str]:
|
||||
"""
|
||||
expand comma-separated brace expressions in a value
|
||||
|
||||
Args:
|
||||
value(str): value that may contain a brace expression
|
||||
expand(bool, optional): whether brace expansion is allowed (Default value = True)
|
||||
|
||||
Returns:
|
||||
list[str]: expanded values if applicable
|
||||
"""
|
||||
match = PkgbuildParser._BRACE_EXPANSION.fullmatch(value)
|
||||
# if there is no comma inside it should be treated as normal value
|
||||
if match is None or not expand or "," not in match.group(2):
|
||||
return [value]
|
||||
|
||||
prefix, values, suffix = match.groups()
|
||||
return [f"{prefix}{item}{suffix}" for item in values.split(",")]
|
||||
|
||||
@staticmethod
|
||||
def _text(node: Node) -> str:
|
||||
def text(node: Node) -> str:
|
||||
"""
|
||||
read the original source text represented by a syntax tree node
|
||||
|
||||
@@ -150,6 +140,50 @@ class PkgbuildParser:
|
||||
"""
|
||||
return cast(bytes, node.text).decode("utf8", errors="backslashreplace")
|
||||
|
||||
@staticmethod
|
||||
def unquote(value: str) -> str:
|
||||
"""
|
||||
remove shell quotes and escapes from a single value
|
||||
|
||||
Args:
|
||||
value(str): shell value to unquote
|
||||
|
||||
Returns:
|
||||
str: unquoted value
|
||||
"""
|
||||
return "".join(shlex.split(value, comments=False, posix=True))
|
||||
|
||||
@staticmethod
|
||||
def value(node: Node) -> str:
|
||||
"""
|
||||
extract a string value from a syntax tree node
|
||||
|
||||
Args:
|
||||
node(Node): syntax tree node to extract
|
||||
|
||||
Returns:
|
||||
str: extracted string value
|
||||
"""
|
||||
def unescape(source: str) -> str:
|
||||
for original, replacement in PkgbuildParser._ESCAPED_CHARACTERS.items():
|
||||
source = source.replace(original, replacement)
|
||||
return source
|
||||
|
||||
if node.type == PkgbuildNodeType.CONCATENATION:
|
||||
return "".join(PkgbuildParser.value(child) for child in node.named_children)
|
||||
|
||||
value = PkgbuildParser.text(node)
|
||||
match node.type:
|
||||
case PkgbuildNodeType.STRING | PkgbuildNodeType.STRING_CONTENT:
|
||||
if node.type == PkgbuildNodeType.STRING:
|
||||
value = PkgbuildParser.unquote(value)
|
||||
# protect escaped backslashes from being interpreted a second time.
|
||||
return "\\".join(unescape(part) for part in value.split("\\\\"))
|
||||
case PkgbuildNodeType.NUMBER | PkgbuildNodeType.RAW_STRING | PkgbuildNodeType.WORD:
|
||||
return PkgbuildParser.unquote(value)
|
||||
case _:
|
||||
return value
|
||||
|
||||
def _assignment(self, node: Node) -> PkgbuildPatch:
|
||||
"""
|
||||
convert an assignment node
|
||||
@@ -160,76 +194,103 @@ class PkgbuildParser:
|
||||
Returns:
|
||||
PkgbuildPatch: parsed assignment
|
||||
"""
|
||||
name = cast(Node, node.child_by_field_name(PkgbuildNodeField.Name))
|
||||
value = cast(Node, node.child_by_field_name(PkgbuildNodeField.Value))
|
||||
key = self._text(name)
|
||||
key = self.text(cast(Node, node.child_by_field_name(PkgbuildNodeField.NAME)))
|
||||
value = node.child_by_field_name(PkgbuildNodeField.VALUE)
|
||||
# bash permits assignments without a value (for example ``IFS=``).
|
||||
# tree-sitter represents those assignments without a value node.
|
||||
if value is None:
|
||||
return PkgbuildPatch(key, "")
|
||||
|
||||
match value.type:
|
||||
case PkgbuildNodeType.Array:
|
||||
array_values = []
|
||||
for element in filter(lambda child: child.type != PkgbuildNodeType.Comment, value.named_children):
|
||||
item = self._value(element)
|
||||
values = self._expand_array(item, expand=element.type == PkgbuildNodeType.Concatenation)
|
||||
array_values.extend(values)
|
||||
return PkgbuildPatch(key, array_values)
|
||||
case PkgbuildNodeType.ARRAY:
|
||||
values = []
|
||||
for element in filter(lambda child: child.type != PkgbuildNodeType.COMMENT, value.named_children):
|
||||
values.extend(self._expand_array(element))
|
||||
return PkgbuildPatch(key, values)
|
||||
|
||||
case _:
|
||||
return PkgbuildPatch(key, self._value(value))
|
||||
return PkgbuildPatch(key, self.value(value))
|
||||
|
||||
def _read(self, node: Node) -> Iterator[PkgbuildPatch]:
|
||||
def _expand_array(self, node: Node) -> list[str]:
|
||||
"""
|
||||
expand simple comma-separated brace groups in an array element
|
||||
|
||||
Args:
|
||||
node(Node): array element to expand
|
||||
|
||||
Returns:
|
||||
list[str]: expanded element values
|
||||
"""
|
||||
if node.type != PkgbuildNodeType.CONCATENATION:
|
||||
return [self.value(node)]
|
||||
|
||||
values = [""]
|
||||
children = node.named_children
|
||||
while children:
|
||||
match children[:3]:
|
||||
case [
|
||||
Node(type=PkgbuildNodeType.WORD, text=b"{"),
|
||||
Node(type=PkgbuildNodeType.WORD) as content,
|
||||
Node(type=PkgbuildNodeType.WORD, text=b"}"),
|
||||
] if "," in (escaped := self.text(content).replace("\\,", ShellInterpolator.DATA_LINK_ESCAPE)):
|
||||
parts = [
|
||||
self.unquote(part).replace(ShellInterpolator.DATA_LINK_ESCAPE, ",")
|
||||
for part in escaped.split(",")
|
||||
]
|
||||
children = children[3:]
|
||||
|
||||
case _:
|
||||
parts = [self.value(children.pop(0))]
|
||||
|
||||
values = [prefix + part for prefix in values for part in parts]
|
||||
|
||||
return values
|
||||
|
||||
def _read(self, node: Node, values: dict[str | None, PkgbuildPatch]) -> Iterator[PkgbuildPatch]:
|
||||
"""
|
||||
find assignments and functions in a syntax tree node
|
||||
|
||||
Args:
|
||||
node(Node): syntax tree node to inspect
|
||||
values(dict[str | None, PkgbuildPatch]): cached assignments
|
||||
|
||||
Yields:
|
||||
PkgbuildPatch: parsed entries
|
||||
"""
|
||||
match node.type:
|
||||
case PkgbuildNodeType.VariableAssignment if not any(child.type == PkgbuildNodeType.Append for child in node.children):
|
||||
yield self._assignment(node)
|
||||
case PkgbuildNodeType.VARIABLE_ASSIGNMENT if any(child.type == PkgbuildNodeType.APPEND for child in node.children):
|
||||
patch = self._assignment(node)
|
||||
match values.get(patch.key), patch.value:
|
||||
case PkgbuildPatch(value=str() as previous), str() as appended:
|
||||
patch = PkgbuildPatch(patch.key, previous + appended)
|
||||
case PkgbuildPatch(value=str() as previous), list() as appended:
|
||||
patch = PkgbuildPatch(patch.key, [previous, *appended])
|
||||
case PkgbuildPatch(value=list() as previous), list() as appended:
|
||||
patch = PkgbuildPatch(patch.key, previous + appended)
|
||||
values[patch.key] = patch
|
||||
yield patch
|
||||
|
||||
case PkgbuildNodeType.FunctionDefinition:
|
||||
name = cast(Node, node.child_by_field_name(PkgbuildNodeField.Name))
|
||||
body = cast(Node, node.child_by_field_name(PkgbuildNodeField.Body))
|
||||
yield PkgbuildPatch(f"{self._text(name)}()", self._text(body))
|
||||
case PkgbuildNodeType.VARIABLE_ASSIGNMENT:
|
||||
patch = self._assignment(node)
|
||||
values[patch.key] = patch
|
||||
yield patch
|
||||
|
||||
case PkgbuildNodeType.FUNCTION_DEFINITION:
|
||||
name = cast(Node, node.child_by_field_name(PkgbuildNodeField.NAME))
|
||||
body = cast(Node, node.child_by_field_name(PkgbuildNodeField.BODY))
|
||||
yield PkgbuildPatch(f"{self.text(name)}()", self.text(body))
|
||||
|
||||
case _:
|
||||
# descend into statements, but skip command arguments and values
|
||||
for child in node.named_children:
|
||||
if child.type not in (
|
||||
PkgbuildNodeType.Array,
|
||||
PkgbuildNodeType.Comment,
|
||||
PkgbuildNodeType.RawString,
|
||||
PkgbuildNodeType.String,
|
||||
PkgbuildNodeType.Word,
|
||||
PkgbuildNodeType.ARRAY,
|
||||
PkgbuildNodeType.COMMENT,
|
||||
PkgbuildNodeType.RAW_STRING,
|
||||
PkgbuildNodeType.STRING,
|
||||
PkgbuildNodeType.WORD,
|
||||
):
|
||||
yield from self._read(child)
|
||||
|
||||
def _value(self, node: Node) -> str:
|
||||
"""
|
||||
extract a string value from a syntax tree node
|
||||
|
||||
Args:
|
||||
node(Node): syntax tree node to extract
|
||||
|
||||
Returns:
|
||||
str: extracted string value
|
||||
"""
|
||||
if node.type in (PkgbuildNodeType.Concatenation, PkgbuildNodeType.String):
|
||||
return "".join(self._value(child) for child in node.named_children)
|
||||
|
||||
value = self._text(node)
|
||||
match node.type:
|
||||
case PkgbuildNodeType.StringContent:
|
||||
value = f'"{value}"'
|
||||
case PkgbuildNodeType.Number | PkgbuildNodeType.RawString | PkgbuildNodeType.Word:
|
||||
pass
|
||||
case _:
|
||||
return value
|
||||
|
||||
return "".join(shlex.split(value, comments=False, posix=True))
|
||||
yield from self._read(child, values)
|
||||
|
||||
def parse(self) -> Iterator[PkgbuildPatch]:
|
||||
"""
|
||||
@@ -255,4 +316,13 @@ class PkgbuildParser:
|
||||
f"syntax error at line {error.start_point.row + 1}, column {error.start_point.column + 1}"
|
||||
)
|
||||
|
||||
yield from self._read(tree.root_node)
|
||||
yield from self._read(tree.root_node, {})
|
||||
|
||||
def __iter__(self) -> Iterator[PkgbuildPatch]:
|
||||
"""
|
||||
iterate over the parsed entries
|
||||
|
||||
Returns:
|
||||
Iterator[PkgbuildPatch]: parsed entries
|
||||
"""
|
||||
return self.parse()
|
||||
@@ -46,7 +46,7 @@ class Printer:
|
||||
if not verbose and not prop.is_required:
|
||||
continue
|
||||
indent = "\t" * prop.indent
|
||||
log_fn(f"{indent}{prop.name}{separator}{prop.value}")
|
||||
log_fn(f"{indent}{prop.name}{separator if prop.separator is None else prop.separator}{prop.value}")
|
||||
|
||||
def properties(self) -> list[Property]:
|
||||
"""
|
||||
|
||||
@@ -17,30 +17,38 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from collections.abc import Iterator
|
||||
|
||||
from ahriman.core.formatters.string_printer import StringPrinter
|
||||
from ahriman.core.tree import Tree
|
||||
from ahriman.core.utils import full_version, parse_version
|
||||
from ahriman.models.build_plan import BuildPlan
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.property import Property
|
||||
|
||||
|
||||
class UpdatePrinter(StringPrinter):
|
||||
"""
|
||||
print content of the package update
|
||||
print content of the packages update
|
||||
|
||||
Attributes:
|
||||
package(Package): remote (new) package object
|
||||
local_version(str | None): local version of the package if any
|
||||
plan(BuildPlan): plan to display
|
||||
local_versions(dict[str, str]): published package versions indexed by base
|
||||
bump_pkgrel(bool): whether duplicate package releases are expected to increment
|
||||
"""
|
||||
|
||||
def __init__(self, remote: Package, local_version: str | None) -> None:
|
||||
def __init__(self, plan: BuildPlan, local_versions: dict[str, str], *, bump_pkgrel: bool = True) -> None:
|
||||
"""
|
||||
Args:
|
||||
remote(Package): remote (new) package object
|
||||
local_version(str | None): local version of the package if any
|
||||
plan(BuildPlan): plan to display
|
||||
local_versions(dict[str, str]): published package versions indexed by base
|
||||
bump_pkgrel(bool, optional): whether duplicate package releases are expected to increment
|
||||
(Default value = True)
|
||||
"""
|
||||
StringPrinter.__init__(self, remote.base)
|
||||
self.package = remote
|
||||
self.local_version = local_version
|
||||
StringPrinter.__init__(self, "Build plan" if plan else "No packages selected")
|
||||
self.plan = plan
|
||||
self.local_versions = local_versions
|
||||
self.bump_pkgrel = bump_pkgrel
|
||||
|
||||
def properties(self) -> list[Property]:
|
||||
"""
|
||||
@@ -49,9 +57,48 @@ class UpdatePrinter(StringPrinter):
|
||||
Returns:
|
||||
list[Property]: list of content properties
|
||||
"""
|
||||
if (pkgrel := self.package.next_pkgrel(self.local_version)) is not None:
|
||||
epoch, pkgver, _ = parse_version(self.package.version)
|
||||
return [
|
||||
prop
|
||||
for level in Tree.resolve(self.plan)
|
||||
for package in level
|
||||
for prop in self.properties_package(package)
|
||||
]
|
||||
|
||||
def properties_package(self, package: Package) -> Iterator[Property]:
|
||||
"""
|
||||
generate list of properties for the specific package
|
||||
|
||||
Args:
|
||||
package(Package): package object
|
||||
|
||||
Yields:
|
||||
Property: list of properties belonging to the package
|
||||
"""
|
||||
# package header
|
||||
yield Property(package.base, "", is_required=True)
|
||||
|
||||
# set version update message
|
||||
local_version, remote_version = self.versions(package)
|
||||
yield Property(local_version, remote_version, is_required=True, indent=2, separator=" -> ")
|
||||
|
||||
# set reason
|
||||
item = self.plan.item(package.base)
|
||||
reason = item.reason.value if item.requester is None else f"{item.reason} {item.requester}"
|
||||
yield Property("Reason", reason, indent=2)
|
||||
|
||||
def versions(self, package: Package) -> tuple[str, str]:
|
||||
"""
|
||||
generate version property
|
||||
|
||||
Returns:
|
||||
tuple[str, str]: extract current and updated versions for the package
|
||||
"""
|
||||
local_version = self.local_versions.get(package.base)
|
||||
|
||||
if self.bump_pkgrel and (pkgrel := package.next_pkgrel(local_version)) is not None:
|
||||
epoch, pkgver, _ = parse_version(package.version)
|
||||
effective_new_version = full_version(epoch, pkgver, pkgrel)
|
||||
else:
|
||||
effective_new_version = self.package.version
|
||||
return [Property(self.local_version or "N/A", effective_new_version, is_required=True)]
|
||||
effective_new_version = package.version
|
||||
|
||||
return local_version or "N/A", effective_new_version
|
||||
@@ -55,7 +55,7 @@ class RemotePull(LazyLogging):
|
||||
web_url="",
|
||||
path=".",
|
||||
branch=configuration.get(section, "pull_branch", fallback="master"),
|
||||
source=PackageSource.Local,
|
||||
source=PackageSource.LOCAL,
|
||||
)
|
||||
self.architecture = repository_id.architecture
|
||||
self.repository_paths = configuration.repository_paths
|
||||
|
||||
@@ -62,7 +62,7 @@ class RemotePush(LazyLogging):
|
||||
web_url="",
|
||||
path=".",
|
||||
branch=configuration.get(section, "push_branch", fallback="master"),
|
||||
source=PackageSource.Local,
|
||||
source=PackageSource.LOCAL,
|
||||
)
|
||||
|
||||
def package_update(self, package: Package, target_dir: Path) -> str:
|
||||
|
||||
@@ -52,9 +52,9 @@ class LogLoader:
|
||||
"""
|
||||
try to guess default log handler. In case if ``selected`` is set, it will return specified value with appended
|
||||
_handler suffix. Otherwise, it will try to import journald handler and returns
|
||||
:attr:`ahriman.models.log_handler.LogHandler.Journald` if library is available. Otherwise, it will check if
|
||||
there is ``/dev/log`` device and returns :attr:`ahriman.models.log_handler.LogHandler.Syslog` in this
|
||||
case. And, finally, it will fall back to :attr:`ahriman.models.log_handler.LogHandler.Console`
|
||||
:attr:`ahriman.models.log_handler.LogHandler.JOURNALD` if library is available. Otherwise, it will check if
|
||||
there is ``/dev/log`` device and returns :attr:`ahriman.models.log_handler.LogHandler.SYSLOG` in this
|
||||
case. And, finally, it will fall back to :attr:`ahriman.models.log_handler.LogHandler.CONSOLE`
|
||||
if none were found
|
||||
|
||||
Args:
|
||||
@@ -67,10 +67,10 @@ class LogLoader:
|
||||
return selected
|
||||
|
||||
if optional_module("systemd.journal"):
|
||||
return LogHandler.Journald # journald import was found
|
||||
return LogHandler.JOURNALD # journald import was found
|
||||
if LogLoader.DEFAULT_SYSLOG_DEVICE.exists():
|
||||
return LogHandler.Syslog
|
||||
return LogHandler.Console
|
||||
return LogHandler.SYSLOG
|
||||
return LogHandler.CONSOLE
|
||||
|
||||
@staticmethod
|
||||
def load(repository_id: RepositoryId, configuration: Configuration, handler: LogHandler, *,
|
||||
|
||||
@@ -155,8 +155,8 @@ class JinjaTemplate:
|
||||
homepage=self.homepage,
|
||||
last_update=self.format_datetime(utcnow()),
|
||||
link_path=self.link_path,
|
||||
has_package_signed=SignSettings.Packages in self.sign_targets,
|
||||
has_repo_signed=SignSettings.Repository in self.sign_targets,
|
||||
has_package_signed=SignSettings.PACKAGES in self.sign_targets,
|
||||
has_repo_signed=SignSettings.REPOSITORY in self.sign_targets,
|
||||
packages=self.sort_content(content),
|
||||
pgp_key=self.default_pgp_key,
|
||||
repository=self.name,
|
||||
|
||||
@@ -81,19 +81,19 @@ class Report(LazyLogging):
|
||||
case ReportSettings.HTML:
|
||||
from ahriman.core.report.html import HTML
|
||||
return HTML(repository_id, configuration, section)
|
||||
case ReportSettings.Email:
|
||||
case ReportSettings.EMAIL:
|
||||
from ahriman.core.report.email import Email
|
||||
return Email(repository_id, configuration, section)
|
||||
case ReportSettings.Console:
|
||||
case ReportSettings.CONSOLE:
|
||||
from ahriman.core.report.console import Console
|
||||
return Console(repository_id, configuration, section)
|
||||
case ReportSettings.Telegram:
|
||||
case ReportSettings.TELEGRAM:
|
||||
from ahriman.core.report.telegram import Telegram
|
||||
return Telegram(repository_id, configuration, section)
|
||||
case ReportSettings.RSS:
|
||||
from ahriman.core.report.rss import RSS
|
||||
return RSS(repository_id, configuration, section)
|
||||
case ReportSettings.RemoteCall:
|
||||
case ReportSettings.REMOTE_CALL:
|
||||
from ahriman.core.report.remote_call import RemoteCall
|
||||
return RemoteCall(repository_id, configuration, section)
|
||||
case _:
|
||||
|
||||
@@ -103,7 +103,7 @@ class RSS(Report, JinjaTemplate):
|
||||
"""
|
||||
ctx = context.get()
|
||||
reporter = ctx.get(Client)
|
||||
events = reporter.event_get(EventType.PackageUpdated, None, limit=self.max_entries)
|
||||
events = reporter.event_get(EventType.PACKAGE_UPDATED, None, limit=self.max_entries)
|
||||
|
||||
known_packages = {package.base: package for package in packages}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class EventLogger:
|
||||
This method must be used as simple wrapper for :class:`ahriman.core.status.Client` methods, e.g.::
|
||||
|
||||
>>> do_something()
|
||||
>>> self.event(package_base, EventType.PackageUpdated)
|
||||
>>> self.event(package_base, EventType.PACKAGE_UPDATED)
|
||||
"""
|
||||
self.reporter.event_add(Event(event, package_base, message))
|
||||
|
||||
@@ -68,7 +68,7 @@ class EventLogger:
|
||||
Examples:
|
||||
This method must be used to perform action in context with time measurement::
|
||||
|
||||
>>> with self.in_event(package_base, EventType.PackageUpdated):
|
||||
>>> with self.in_event(package_base, EventType.PACKAGE_UPDATED):
|
||||
>>> do_something()
|
||||
|
||||
Additional parameter ``failure`` can be set in order to emit an event on exception occurred. If none set
|
||||
|
||||
@@ -117,7 +117,7 @@ class Executor(PackageInfo, Cleaner):
|
||||
package_base(str): package base name
|
||||
"""
|
||||
try:
|
||||
with self.in_event(package_base, EventType.PackageRemoved):
|
||||
with self.in_event(package_base, EventType.PACKAGE_REMOVED):
|
||||
self.reporter.package_remove(package_base)
|
||||
except Exception:
|
||||
self.logger.exception("could not remove base %s", package_base)
|
||||
@@ -169,7 +169,7 @@ class Executor(PackageInfo, Cleaner):
|
||||
with self.in_package_context(single.base, local_versions.get(single.base)), \
|
||||
TemporaryDirectory(ignore_cleanup_errors=True) as dir_name:
|
||||
try:
|
||||
with self.in_event(single.base, EventType.PackageUpdated, failure=EventType.PackageUpdateFailed):
|
||||
with self.in_event(single.base, EventType.PACKAGE_UPDATED, failure=EventType.PACKAGE_UPDATE_FAILED):
|
||||
packager = self.packager(packagers, single.base)
|
||||
local_version = local_versions.get(single.base) if bump_pkgrel else None
|
||||
commit_sha = self._package_build(single, Path(dir_name), packager.packager_id, local_version)
|
||||
|
||||
@@ -57,7 +57,7 @@ class Repository(Executor, UpdateHandler):
|
||||
|
||||
@classmethod
|
||||
def load(cls, repository_id: RepositoryId, configuration: Configuration, database: SQLite, *, report: bool,
|
||||
refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.Disabled) -> Self:
|
||||
refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.DISABLED) -> Self:
|
||||
"""
|
||||
load instance from argument list
|
||||
|
||||
@@ -67,7 +67,7 @@ class Repository(Executor, UpdateHandler):
|
||||
database(SQLite): database instance
|
||||
report(bool): force enable or disable reporting
|
||||
refresh_pacman_database(PacmanSynchronization, optional): pacman database synchronization level
|
||||
(Default value = PacmanSynchronization.Disabled)
|
||||
(Default value = PacmanSynchronization.DISABLED)
|
||||
|
||||
Returns:
|
||||
Self: fully loaded repository class instance
|
||||
|
||||
@@ -90,9 +90,9 @@ class RepositoryProperties(EventLogger, LazyLogging):
|
||||
"""
|
||||
username = packagers.for_base(package_base)
|
||||
if username is None: # none to search
|
||||
return User(username="", password="", access=UserAccess.Read, packager_id=None, key=None) # nosec
|
||||
return User(username="", password="", access=UserAccess.READ, packager_id=None, key=None) # nosec
|
||||
|
||||
if (user := self.database.user_get(username)) is not None: # found user
|
||||
return user
|
||||
# empty user with the username
|
||||
return User(username=username, password="", access=UserAccess.Read, packager_id=None, key=None) # nosec
|
||||
return User(username=username, password="", access=UserAccess.READ, packager_id=None, key=None) # nosec
|
||||
@@ -62,7 +62,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
# try to load package from base and if none found try to load by separated packages
|
||||
for probe in [package.base] + sorted(package.packages.keys()):
|
||||
try:
|
||||
if package.remote.source == PackageSource.Repository:
|
||||
if package.remote.source == PackageSource.REPOSITORY:
|
||||
return Package.from_official(probe, self.pacman, None)
|
||||
return Package.from_aur(probe, None)
|
||||
except UnknownPackageError:
|
||||
@@ -85,10 +85,10 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
|
||||
if PackageVersion(local).is_outdated(remote, self.configuration, calculate_version=vcs):
|
||||
self.reporter.set_pending(local.base)
|
||||
self.event(local.base, EventType.PackageOutdated, "Remote version is newer than local")
|
||||
self.event(local.base, EventType.PACKAGE_OUTDATED, "Remote version is newer than local")
|
||||
result.append(remote)
|
||||
else:
|
||||
self.reporter.package_status_update(local.base, BuildStatusEnum.Success)
|
||||
self.reporter.package_status_update(local.base, BuildStatusEnum.SUCCESS)
|
||||
except Exception:
|
||||
self.reporter.set_failed(local.base)
|
||||
self.logger.exception("could not load remote package %s", local.base)
|
||||
@@ -136,7 +136,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
|
||||
# there are no packages found in filesystem with the same paths
|
||||
self.reporter.set_pending(local.base)
|
||||
self.event(local.base, EventType.PackageOutdated, "Implicit dependencies are broken")
|
||||
self.event(local.base, EventType.PACKAGE_OUTDATED, "Implicit dependencies are broken")
|
||||
result.append(local)
|
||||
|
||||
break
|
||||
@@ -165,7 +165,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
with self.in_package_context(cache_dir.name, local_versions.get(cache_dir.name)):
|
||||
try:
|
||||
source = RemoteSource(
|
||||
source=PackageSource.Local,
|
||||
source=PackageSource.LOCAL,
|
||||
git_url=cache_dir.absolute().as_uri(),
|
||||
web_url="",
|
||||
path=".",
|
||||
@@ -186,8 +186,9 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
|
||||
if PackageVersion(local).is_outdated(remote, self.configuration, calculate_version=vcs):
|
||||
self.reporter.set_pending(local.base)
|
||||
self.event(local.base, EventType.PackageOutdated, "Locally pulled sources are outdated")
|
||||
self.event(local.base, EventType.PACKAGE_OUTDATED, "Locally pulled sources are outdated")
|
||||
result.append(remote)
|
||||
|
||||
except Exception:
|
||||
self.logger.exception("could not process package at %s", cache_dir)
|
||||
|
||||
@@ -210,7 +211,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
self.reporter.set_unknown(local)
|
||||
else:
|
||||
self.reporter.set_pending(local.base)
|
||||
self.event(local.base, EventType.PackageOutdated, "Manual update is requested")
|
||||
self.event(local.base, EventType.PACKAGE_OUTDATED, "Manual update is requested")
|
||||
|
||||
except Exception:
|
||||
self.logger.exception("could not load packages from database")
|
||||
|
||||
@@ -53,7 +53,7 @@ class GPG(SyncHttpClient):
|
||||
Returns:
|
||||
list[str]: command line arguments for repo-add command to sign database
|
||||
"""
|
||||
if SignSettings.Repository not in self.targets:
|
||||
if SignSettings.REPOSITORY not in self.targets:
|
||||
return []
|
||||
if self.default_key is None:
|
||||
self.logger.error("no default key set, skip repository sign")
|
||||
@@ -88,7 +88,7 @@ class GPG(SyncHttpClient):
|
||||
targets: set[SignSettings] = set()
|
||||
for option in configuration.getlist("sign", "target", fallback=[]):
|
||||
target = SignSettings.from_option(option)
|
||||
if target == SignSettings.Disabled:
|
||||
if target == SignSettings.DISABLED:
|
||||
continue
|
||||
targets.add(target)
|
||||
default_key = configuration.get("sign", "key") if targets else None
|
||||
@@ -204,7 +204,7 @@ class GPG(SyncHttpClient):
|
||||
# the file was already signed before, just use its signature
|
||||
return [path, signature]
|
||||
|
||||
if SignSettings.Packages not in self.targets:
|
||||
if SignSettings.PACKAGES not in self.targets:
|
||||
return [path]
|
||||
|
||||
key = packager_key or self.default_key
|
||||
@@ -226,7 +226,7 @@ class GPG(SyncHttpClient):
|
||||
Returns:
|
||||
list[Path]: list of generated files including original file
|
||||
"""
|
||||
if SignSettings.Repository not in self.targets:
|
||||
if SignSettings.REPOSITORY not in self.targets:
|
||||
return [path]
|
||||
if self.default_key is None:
|
||||
self.logger.error("no default key set, skip repository sign")
|
||||
|
||||
@@ -341,7 +341,7 @@ class Client:
|
||||
Args:
|
||||
package_base(str): package base to update
|
||||
"""
|
||||
self.package_status_update(package_base, BuildStatusEnum.Building)
|
||||
self.package_status_update(package_base, BuildStatusEnum.BUILDING)
|
||||
|
||||
def set_failed(self, package_base: str) -> None:
|
||||
"""
|
||||
@@ -350,7 +350,7 @@ class Client:
|
||||
Args:
|
||||
package_base(str): package base to update
|
||||
"""
|
||||
self.package_status_update(package_base, BuildStatusEnum.Failed)
|
||||
self.package_status_update(package_base, BuildStatusEnum.FAILED)
|
||||
|
||||
def set_pending(self, package_base: str) -> None:
|
||||
"""
|
||||
@@ -359,7 +359,7 @@ class Client:
|
||||
Args:
|
||||
package_base(str): package base to update
|
||||
"""
|
||||
self.package_status_update(package_base, BuildStatusEnum.Pending)
|
||||
self.package_status_update(package_base, BuildStatusEnum.PENDING)
|
||||
|
||||
def set_success(self, package: Package) -> None:
|
||||
"""
|
||||
@@ -368,7 +368,7 @@ class Client:
|
||||
Args:
|
||||
package(Package): current package properties
|
||||
"""
|
||||
self.package_update(package, BuildStatusEnum.Success)
|
||||
self.package_update(package, BuildStatusEnum.SUCCESS)
|
||||
|
||||
def set_unknown(self, package: Package) -> None:
|
||||
"""
|
||||
@@ -380,7 +380,7 @@ class Client:
|
||||
"""
|
||||
if self.package_get(package.base):
|
||||
return # skip update in case if package is already known
|
||||
self.package_update(package, BuildStatusEnum.Unknown)
|
||||
self.package_update(package, BuildStatusEnum.UNKNOWN)
|
||||
|
||||
def statistics(self) -> RepositoryStats:
|
||||
"""
|
||||
|
||||
@@ -197,7 +197,7 @@ class Watcher(LazyLogging):
|
||||
self._known[package_base] = (package, replace(status, is_held=enabled))
|
||||
self.client.package_hold_update(package_base, enabled=enabled)
|
||||
|
||||
await self.event_bus.broadcast(EventType.PackageHeld, package_base, is_held=enabled)
|
||||
await self.event_bus.broadcast(EventType.PACKAGE_HELD, package_base, is_held=enabled)
|
||||
|
||||
async def package_logs_add(self, log_record: LogRecord) -> None:
|
||||
"""
|
||||
@@ -208,7 +208,7 @@ class Watcher(LazyLogging):
|
||||
"""
|
||||
self.client.package_logs_add(log_record)
|
||||
|
||||
await self.event_bus.broadcast(EventType.BuildLog, log_record.log_record_id.package_base, **log_record.view())
|
||||
await self.event_bus.broadcast(EventType.BUILD_LOG, log_record.log_record_id.package_base, **log_record.view())
|
||||
|
||||
async def package_logs_get(self, package_base: str, version: str | None = None, process_id: str | None = None,
|
||||
limit: int = -1, offset: int = 0) -> list[LogRecord]:
|
||||
@@ -281,7 +281,7 @@ class Watcher(LazyLogging):
|
||||
self._known.pop(package_base, None)
|
||||
self.client.package_remove(package_base)
|
||||
|
||||
await self.event_bus.broadcast(EventType.PackageRemoved, package_base)
|
||||
await self.event_bus.broadcast(EventType.PACKAGE_REMOVED, package_base)
|
||||
|
||||
async def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None:
|
||||
"""
|
||||
@@ -296,7 +296,7 @@ class Watcher(LazyLogging):
|
||||
self._known[package_base] = (package, BuildStatus(status, is_held=current_status.is_held))
|
||||
self.client.package_status_update(package_base, status)
|
||||
|
||||
await self.event_bus.broadcast(EventType.PackageStatusChanged, package_base, status=status.value)
|
||||
await self.event_bus.broadcast(EventType.PACKAGE_STATUS_CHANGED, package_base, status=status.value)
|
||||
|
||||
async def package_update(self, package: Package, status: BuildStatusEnum) -> None:
|
||||
"""
|
||||
@@ -312,7 +312,7 @@ class Watcher(LazyLogging):
|
||||
self.client.package_update(package, status)
|
||||
|
||||
await self.event_bus.broadcast(
|
||||
EventType.PackageUpdated, package.base, status=status.value, version=package.version,
|
||||
EventType.PACKAGE_UPDATED, package.base, status=status.value, version=package.version,
|
||||
)
|
||||
|
||||
async def packages(self) -> list[tuple[Package, BuildStatus]]:
|
||||
@@ -340,7 +340,7 @@ class Watcher(LazyLogging):
|
||||
"""
|
||||
self.status = BuildStatus(status)
|
||||
|
||||
await self.event_bus.broadcast(EventType.ServiceStatusChanged, None, status=status.value)
|
||||
await self.event_bus.broadcast(EventType.SERVICE_STATUS_CHANGED, None, status=status.value)
|
||||
|
||||
def __call__(self, package_base: str | None) -> Self:
|
||||
"""
|
||||
|
||||
@@ -79,16 +79,16 @@ class Upload(LazyLogging):
|
||||
"""
|
||||
section, provider_name = configuration.gettype(target, repository_id)
|
||||
match UploadSettings.from_option(provider_name):
|
||||
case UploadSettings.Rsync:
|
||||
case UploadSettings.RSYNC:
|
||||
from ahriman.core.upload.rsync import Rsync
|
||||
return Rsync(repository_id, configuration, section)
|
||||
case UploadSettings.S3:
|
||||
from ahriman.core.upload.s3 import S3
|
||||
return S3(repository_id, configuration, section)
|
||||
case UploadSettings.GitHub:
|
||||
case UploadSettings.GITHUB:
|
||||
from ahriman.core.upload.github import GitHub
|
||||
return GitHub(repository_id, configuration, section)
|
||||
case UploadSettings.RemoteService:
|
||||
case UploadSettings.REMOTE_SERVICE:
|
||||
from ahriman.core.upload.remote_service import RemoteService
|
||||
return RemoteService(repository_id, configuration, section)
|
||||
case _:
|
||||
|
||||
@@ -25,11 +25,11 @@ class Action(StrEnum):
|
||||
base action enumeration
|
||||
|
||||
Attributes:
|
||||
List(Action): list available values
|
||||
Remove(Action): remove everything from local storage
|
||||
Update(Action): update local storage or add to
|
||||
LIST(Action): list available values
|
||||
REMOVE(Action): remove everything from local storage
|
||||
UPDATE(Action): update local storage or add to
|
||||
"""
|
||||
|
||||
List = "list"
|
||||
Remove = "remove"
|
||||
Update = "update"
|
||||
LIST = "list"
|
||||
REMOVE = "remove"
|
||||
UPDATE = "update"
|
||||
@@ -27,15 +27,15 @@ class AuthSettings(StrEnum):
|
||||
web authorization type
|
||||
|
||||
Attributes:
|
||||
Disabled(AuthSettings): authorization is disabled
|
||||
Configuration(AuthSettings): configuration based authorization
|
||||
OAuth(AuthSettings): OAuth based provider
|
||||
DISABLED(AuthSettings): authorization is disabled
|
||||
CONFIGURATION(AuthSettings): configuration based authorization
|
||||
OAUTH(AuthSettings): OAuth based provider
|
||||
PAM(AuthSettings): PAM based provider
|
||||
"""
|
||||
|
||||
Disabled = "disabled"
|
||||
Configuration = "configuration"
|
||||
OAuth = "oauth2"
|
||||
DISABLED = "disabled"
|
||||
CONFIGURATION = "configuration"
|
||||
OAUTH = "oauth2"
|
||||
PAM = "pam"
|
||||
|
||||
@property
|
||||
@@ -46,7 +46,7 @@ class AuthSettings(StrEnum):
|
||||
Returns:
|
||||
bool: ``False`` in case if authorization is disabled and ``True`` otherwise
|
||||
"""
|
||||
return self != AuthSettings.Disabled
|
||||
return self != AuthSettings.DISABLED
|
||||
|
||||
@staticmethod
|
||||
def from_option(value: str) -> AuthSettings:
|
||||
@@ -61,10 +61,10 @@ class AuthSettings(StrEnum):
|
||||
"""
|
||||
match value.lower():
|
||||
case "configuration" | "mapping":
|
||||
return AuthSettings.Configuration
|
||||
return AuthSettings.CONFIGURATION
|
||||
case "oauth" | "oauth2":
|
||||
return AuthSettings.OAuth
|
||||
return AuthSettings.OAUTH
|
||||
case "pam":
|
||||
return AuthSettings.PAM
|
||||
case _:
|
||||
return AuthSettings.Disabled
|
||||
return AuthSettings.DISABLED
|
||||
@@ -0,0 +1,196 @@
|
||||
#
|
||||
# Copyright (c) 2021-2026 ahriman team.
|
||||
#
|
||||
# This file is part of ahriman
|
||||
# (see https://github.com/arcan1s/ahriman).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from collections.abc import Iterable, Iterator
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
from typing import Any, Self
|
||||
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
class BuildPlanReason(StrEnum):
|
||||
"""
|
||||
reason why package was selected for a build plan
|
||||
|
||||
Attributes:
|
||||
BROKEN_IMPLICIT_DEPENDENCY(BuildPlanReason): package has a broken implicit dependency
|
||||
LOCAL_SOURCE_UPDATE(BuildPlanReason): locally sourced package has an update
|
||||
MANUAL_REQUEST(BuildPlanReason): package was manually queued
|
||||
PRE_BUILT(BuildPlanReason): package has already been built
|
||||
REBUILD(BuildPlanReason): package was selected for rebuild
|
||||
REGULAR_UPDATE(BuildPlanReason): package has an AUR update
|
||||
REQUIRED_BY(BuildPlanReason): package is required by another selected package
|
||||
"""
|
||||
|
||||
BROKEN_IMPLICIT_DEPENDENCY = "broken implicit dependency"
|
||||
LOCAL_SOURCE_UPDATE = "local source update"
|
||||
MANUAL_REQUEST = "manual request"
|
||||
PRE_BUILT = "pre-built"
|
||||
REBUILD = "rebuild"
|
||||
REGULAR_UPDATE = "regular update"
|
||||
REQUIRED_BY = "required by"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BuildPlanItem:
|
||||
"""
|
||||
one package and the reason it appears in a build plan
|
||||
|
||||
Attributes:
|
||||
package(Package): package selected for the plan
|
||||
reason(BuildPlanReason): why the package was selected
|
||||
requester(str | None): package that requires this package
|
||||
"""
|
||||
|
||||
package: Package
|
||||
reason: BuildPlanReason
|
||||
requester: str | None = None
|
||||
|
||||
|
||||
class BuildPlan(Iterable[Package]):
|
||||
"""
|
||||
in-memory preview of the packages selected for a build operation
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
initialize an empty build plan
|
||||
"""
|
||||
self._items: dict[str, BuildPlanItem] = {}
|
||||
|
||||
@property
|
||||
def items(self) -> list[BuildPlanItem]:
|
||||
"""
|
||||
get plan items in stable package-base order
|
||||
|
||||
Returns:
|
||||
list[BuildPlanItem]: selected plan items
|
||||
"""
|
||||
return [self._items[base] for base in sorted(self._items)]
|
||||
|
||||
@property
|
||||
def packages(self) -> list[Package]:
|
||||
"""
|
||||
get packages in stable package-base order
|
||||
|
||||
Returns:
|
||||
list[Package]: selected packages
|
||||
"""
|
||||
return [item.package for item in self.items]
|
||||
|
||||
def add(self, package: Package, reason: BuildPlanReason = BuildPlanReason.MANUAL_REQUEST,
|
||||
requester: str | None = None) -> BuildPlanItem:
|
||||
"""
|
||||
add or update a package while preserving its first reason and requester
|
||||
|
||||
Args:
|
||||
package(Package): package selected for the plan
|
||||
reason(BuildPlanReason, optional): reason for selecting it (Default value = BuildPlanReason.MANUAL_REQUEST)
|
||||
requester(str | None, optional): package requiring this dependency (Default value = None)
|
||||
|
||||
Returns:
|
||||
BuildPlanItem: plan item for the package
|
||||
"""
|
||||
if (existing := self._items.get(package.base)) is not None:
|
||||
reason, requester = existing.reason, existing.requester
|
||||
item = self._items[package.base] = BuildPlanItem(package, reason, requester)
|
||||
return item
|
||||
|
||||
def item(self, package_base: str) -> BuildPlanItem:
|
||||
"""
|
||||
get a plan item by package base
|
||||
|
||||
Args:
|
||||
package_base(str): package base to look up
|
||||
|
||||
Returns:
|
||||
BuildPlanItem: matching item
|
||||
"""
|
||||
return self._items[package_base]
|
||||
|
||||
def remove(self, package_base: str) -> None:
|
||||
"""
|
||||
remove a package from the plan
|
||||
|
||||
Args:
|
||||
package_base(str): package base to remove
|
||||
"""
|
||||
del self._items[package_base]
|
||||
|
||||
def update(self, packages: Iterable[Package], reason: BuildPlanReason = BuildPlanReason.MANUAL_REQUEST,
|
||||
requester: str | None = None) -> Self:
|
||||
"""
|
||||
bulk update packages with the same reason
|
||||
|
||||
Args:
|
||||
packages(Iterable[Package]): list of new packages to be added
|
||||
reason(BuildPlanReason, optional): reason for selecting it (Default value = BuildPlanReason.MANUAL_REQUEST)
|
||||
requester(str | None, optional): package requiring these dependencies (Default value = None)
|
||||
|
||||
Returns:
|
||||
Self: updated plan instance
|
||||
"""
|
||||
for package in packages:
|
||||
self.add(package, reason, requester)
|
||||
return self
|
||||
|
||||
def __contains__(self, item: Package) -> bool:
|
||||
"""
|
||||
check whether plan holds a package or not
|
||||
|
||||
Args:
|
||||
item(Package): package to lookup
|
||||
|
||||
Returns:
|
||||
bool: ``True`` in case if the package is already in the plan and ``False`` otherwise
|
||||
"""
|
||||
return item.base in self._items
|
||||
|
||||
def __eq__(self, other: Any) -> bool:
|
||||
"""
|
||||
check if other is the same object
|
||||
|
||||
Args:
|
||||
other(Any): other object instance
|
||||
|
||||
Returns:
|
||||
bool: ``True`` if the other object is the same and ``False`` otherwise
|
||||
"""
|
||||
if not isinstance(other, BuildPlan):
|
||||
return False
|
||||
return self.items == other.items
|
||||
|
||||
def __iter__(self) -> Iterator[Package]:
|
||||
"""
|
||||
iterate over selected packages in stable package-base order
|
||||
|
||||
Returns:
|
||||
Package: selected package
|
||||
"""
|
||||
return iter(self.packages)
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""
|
||||
get number of selected packages
|
||||
|
||||
Returns:
|
||||
int: number of selected packages
|
||||
"""
|
||||
return len(self._items)
|
||||
@@ -29,18 +29,18 @@ class BuildStatusEnum(StrEnum):
|
||||
build status enumeration
|
||||
|
||||
Attributes:
|
||||
Unknown(BuildStatusEnum): build status is unknown
|
||||
Pending(BuildStatusEnum): package is out-of-dated and will be built soon
|
||||
Building(BuildStatusEnum): package is building right now
|
||||
Failed(BuildStatusEnum): package build failed
|
||||
Success(BuildStatusEnum): package has been built without errors
|
||||
UNKNOWN(BuildStatusEnum): build status is unknown
|
||||
PENDING(BuildStatusEnum): package is out-of-dated and will be built soon
|
||||
BUILDING(BuildStatusEnum): package is building right now
|
||||
FAILED(BuildStatusEnum): package build failed
|
||||
SUCCESS(BuildStatusEnum): package has been built without errors
|
||||
"""
|
||||
|
||||
Unknown = "unknown"
|
||||
Pending = "pending"
|
||||
Building = "building"
|
||||
Failed = "failed"
|
||||
Success = "success"
|
||||
UNKNOWN = "unknown"
|
||||
PENDING = "pending"
|
||||
BUILDING = "building"
|
||||
FAILED = "failed"
|
||||
SUCCESS = "success"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -54,7 +54,7 @@ class BuildStatus:
|
||||
is_held(bool | None): whether package held or not
|
||||
"""
|
||||
|
||||
status: BuildStatusEnum = BuildStatusEnum.Unknown
|
||||
status: BuildStatusEnum = BuildStatusEnum.UNKNOWN
|
||||
timestamp: int = field(default_factory=lambda: int(utcnow().timestamp()))
|
||||
is_held: bool | None = field(default=None, kw_only=True)
|
||||
|
||||
|
||||
@@ -28,24 +28,24 @@ class EventType(StrEnum):
|
||||
predefined event types
|
||||
|
||||
Attributes:
|
||||
BuildLog(EventType): new build log line
|
||||
PackageHeld(EventType): package hold status has been changed
|
||||
PackageOutdated(EventType): package has been marked as out-of-date
|
||||
PackageRemoved(EventType): package has been removed
|
||||
PackageStatusChanged(EventType): package build status has been changed
|
||||
PackageUpdateFailed(EventType): package update has been failed
|
||||
PackageUpdated(EventType): package has been updated
|
||||
ServiceStatusChanged(EventType): service status has been changed
|
||||
BUILD_LOG(EventType): new build log line
|
||||
PACKAGE_HELD(EventType): package hold status has been changed
|
||||
PACKAGE_OUTDATED(EventType): package has been marked as out-of-date
|
||||
PACKAGE_REMOVED(EventType): package has been removed
|
||||
PACKAGE_STATUS_CHANGED(EventType): package build status has been changed
|
||||
PACKAGE_UPDATE_FAILED(EventType): package update has been failed
|
||||
PACKAGE_UPDATED(EventType): package has been updated
|
||||
SERVICE_STATUS_CHANGED(EventType): service status has been changed
|
||||
"""
|
||||
|
||||
BuildLog = "build-log"
|
||||
PackageHeld = "package-held"
|
||||
PackageOutdated = "package-outdated"
|
||||
PackageRemoved = "package-removed"
|
||||
PackageStatusChanged = "package-status-changed"
|
||||
PackageUpdateFailed = "package-update-failed"
|
||||
PackageUpdated = "package-updated"
|
||||
ServiceStatusChanged = "service-status-changed"
|
||||
BUILD_LOG = "build-log"
|
||||
PACKAGE_HELD = "package-held"
|
||||
PACKAGE_OUTDATED = "package-outdated"
|
||||
PACKAGE_REMOVED = "package-removed"
|
||||
PACKAGE_STATUS_CHANGED = "package-status-changed"
|
||||
PACKAGE_UPDATE_FAILED = "package-update-failed"
|
||||
PACKAGE_UPDATED = "package-updated"
|
||||
SERVICE_STATUS_CHANGED = "service-status-changed"
|
||||
|
||||
|
||||
class Event:
|
||||
@@ -61,7 +61,7 @@ class Event:
|
||||
"""
|
||||
|
||||
def __init__(self, event: str | EventType, object_id: str, message: str | None = None, created: int | None = None,
|
||||
**kwargs: Any):
|
||||
**kwargs: Any) -> None:
|
||||
"""
|
||||
Args:
|
||||
event(str | EventType): event type
|
||||
|
||||
@@ -25,11 +25,11 @@ class LogHandler(StrEnum):
|
||||
log handler as described by default configuration
|
||||
|
||||
Attributes:
|
||||
Console(LogHandler): write logs to console
|
||||
Syslog(LogHandler): write logs to syslog device /dev/null
|
||||
Journald(LogHandler): write logs to journald directly
|
||||
CONSOLE(LogHandler): write logs to console
|
||||
SYSLOG(LogHandler): write logs to syslog device /dev/null
|
||||
JOURNALD(LogHandler): write logs to journald directly
|
||||
"""
|
||||
|
||||
Console = "console"
|
||||
Syslog = "syslog"
|
||||
Journald = "journald"
|
||||
CONSOLE = "console"
|
||||
SYSLOG = "syslog"
|
||||
JOURNALD = "journald"
|
||||
@@ -50,13 +50,8 @@ class LogRecord:
|
||||
Returns:
|
||||
Self: log record object
|
||||
"""
|
||||
if "process_id" in dump:
|
||||
log_record_id = LogRecordId(package_base, dump["version"], dump["process_id"])
|
||||
else:
|
||||
log_record_id = LogRecordId(package_base, dump["version"])
|
||||
|
||||
return cls(
|
||||
log_record_id=log_record_id,
|
||||
log_record_id=LogRecordId(package_base, dump["version"], dump.get("process_id", "")),
|
||||
created=dump["created"],
|
||||
message=dump["message"],
|
||||
)
|
||||
|
||||
@@ -62,10 +62,10 @@ class Package(LazyLogging):
|
||||
|
||||
The specific class load method must be defined based on the source provided. The following methods (mostly) must
|
||||
be used: :func:`from_archive()`, :func:`from_aur()`, :func:`from_build()`, :func:`from_official()` for sources
|
||||
:attr:`ahriman.models.package_source.PackageSource.Archive`,
|
||||
:attr:`ahriman.models.package_source.PackageSource.ARCHIVE`,
|
||||
:attr:`ahriman.models.package_source.PackageSource.AUR`,
|
||||
:attr:`ahriman.models.package_source.PackageSource.Local` and
|
||||
:attr:`ahriman.models.package_source.PackageSource.Repository` respectively:
|
||||
:attr:`ahriman.models.package_source.PackageSource.LOCAL` and
|
||||
:attr:`ahriman.models.package_source.PackageSource.REPOSITORY` respectively:
|
||||
|
||||
>>> ahriman_package = Package.from_aur("ahriman")
|
||||
>>> pacman_package = Package.from_official("pacman", pacman)
|
||||
@@ -192,7 +192,7 @@ class Package(LazyLogging):
|
||||
return cls(
|
||||
base=package.base or package.name,
|
||||
version=package.version,
|
||||
remote=RemoteSource(source=PackageSource.Archive),
|
||||
remote=RemoteSource(source=PackageSource.ARCHIVE),
|
||||
packages={package.name: description},
|
||||
packager=package.packager,
|
||||
)
|
||||
@@ -255,7 +255,7 @@ class Package(LazyLogging):
|
||||
version = full_version(pkgbuild.get("epoch"), pkgbuild["pkgver"], pkgbuild["pkgrel"])
|
||||
|
||||
remote = RemoteSource(
|
||||
source=PackageSource.Local,
|
||||
source=PackageSource.LOCAL,
|
||||
git_url=path.absolute().as_uri(),
|
||||
web_url=None,
|
||||
path=".",
|
||||
@@ -315,7 +315,7 @@ class Package(LazyLogging):
|
||||
package = impl.info(name, pacman=pacman, include_provides=include_provides)
|
||||
|
||||
remote = RemoteSource(
|
||||
source=PackageSource.Repository,
|
||||
source=PackageSource.REPOSITORY,
|
||||
git_url=Official.remote_git_url(package.package_base, package.repository),
|
||||
web_url=Official.remote_web_url(package.package_base),
|
||||
path=".",
|
||||
|
||||
@@ -32,31 +32,31 @@ class PackageSource(StrEnum):
|
||||
package source for addition enumeration
|
||||
|
||||
Attributes:
|
||||
Auto(PackageSource): automatically determine type of the source
|
||||
Archive(PackageSource): source is a package archive
|
||||
AUTO(PackageSource): automatically determine type of the source
|
||||
ARCHIVE(PackageSource): source is a package archive
|
||||
AUR(PackageSource): source is an AUR package for which it should search
|
||||
Directory(PackageSource): source is a directory which contains packages
|
||||
Local(PackageSource): source is locally stored PKGBUILD
|
||||
Remote(PackageSource): source is remote (http, ftp etc...) link
|
||||
Repository(PackageSource): source is official repository
|
||||
DIRECTORY(PackageSource): source is a directory which contains packages
|
||||
LOCAL(PackageSource): source is locally stored PKGBUILD
|
||||
REMOTE(PackageSource): source is remote (http, ftp etc...) link
|
||||
REPOSITORY(PackageSource): source is official repository
|
||||
|
||||
Examples:
|
||||
In case if source is unknown the :func:`resolve()` and the source
|
||||
descriptor is available method must be used::
|
||||
|
||||
>>> real_source = PackageSource.Auto.resolve("ahriman", configuration.repository_paths)
|
||||
>>> real_source = PackageSource.AUTO.resolve("ahriman", configuration.repository_paths)
|
||||
|
||||
the code above will ensure that the presudo-source :attr:`Auto`
|
||||
the code above will ensure that the presudo-source :attr:`AUTO`
|
||||
will not be processed later.
|
||||
"""
|
||||
|
||||
Auto = "auto"
|
||||
Archive = "archive"
|
||||
AUTO = "auto"
|
||||
ARCHIVE = "archive"
|
||||
AUR = "aur"
|
||||
Directory = "directory"
|
||||
Local = "local"
|
||||
Remote = "remote"
|
||||
Repository = "repository"
|
||||
DIRECTORY = "directory"
|
||||
LOCAL = "local"
|
||||
REMOTE = "remote"
|
||||
REPOSITORY = "repository"
|
||||
|
||||
def resolve(self, source: str, paths: RepositoryPaths) -> PackageSource:
|
||||
"""
|
||||
@@ -69,21 +69,21 @@ class PackageSource(StrEnum):
|
||||
Returns:
|
||||
PackageSource: non-auto type of the package source
|
||||
"""
|
||||
if self != PackageSource.Auto:
|
||||
if self != PackageSource.AUTO:
|
||||
return self
|
||||
|
||||
maybe_url = urlparse(source) # handle file:// like paths
|
||||
maybe_path = Path(maybe_url.path)
|
||||
|
||||
if maybe_url.scheme and maybe_url.scheme not in ("data", "file") and package_like(maybe_path):
|
||||
return PackageSource.Remote
|
||||
return PackageSource.REMOTE
|
||||
try:
|
||||
if (maybe_path / "PKGBUILD").is_file() or paths.cache_for(source).is_dir():
|
||||
return PackageSource.Local
|
||||
return PackageSource.LOCAL
|
||||
if maybe_path.is_dir():
|
||||
return PackageSource.Directory
|
||||
return PackageSource.DIRECTORY
|
||||
if maybe_path.is_file() and package_like(maybe_path):
|
||||
return PackageSource.Archive
|
||||
return PackageSource.ARCHIVE
|
||||
except PermissionError:
|
||||
# in some cases (e.g. if you run from your home directory with sudo)
|
||||
# it will try to read files to which it has no access.
|
||||
|
||||
@@ -25,11 +25,11 @@ class PacmanSynchronization(IntEnum):
|
||||
pacman database synchronization flag
|
||||
|
||||
Attributes:
|
||||
Disabled(PacmanSynchronization): do not synchronize local database
|
||||
Enabled(PacmanSynchronization): synchronize local database (same as pacman -Sy)
|
||||
Force(PacmanSynchronization): force synchronize local database (same as pacman -Syy)
|
||||
DISABLED(PacmanSynchronization): do not synchronize local database
|
||||
ENABLED(PacmanSynchronization): synchronize local database (same as pacman -Sy)
|
||||
FORCE(PacmanSynchronization): force synchronize local database (same as pacman -Syy)
|
||||
"""
|
||||
|
||||
Disabled = 0
|
||||
Enabled = 1
|
||||
Force = 2
|
||||
DISABLED = 0
|
||||
ENABLED = 1
|
||||
FORCE = 2
|
||||
@@ -80,8 +80,7 @@ class Pkgbuild(Mapping[str, Any]):
|
||||
Returns:
|
||||
Self: constructed instance of self
|
||||
"""
|
||||
parser = PkgbuildParser(stream)
|
||||
fields = {patch.key: patch for patch in parser.parse()}
|
||||
fields = {patch.key: patch for patch in PkgbuildParser(stream)}
|
||||
|
||||
# pkgbase is optional field, the pkgname must be used instead if not set
|
||||
# however, pkgname is not presented is "package()" functions which we are parsing here too,
|
||||
|
||||
@@ -20,9 +20,10 @@
|
||||
import json
|
||||
import shlex
|
||||
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass, fields
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterator, Self
|
||||
from typing import Any, Self
|
||||
|
||||
from ahriman.core.configuration.shell_template import ShellTemplate
|
||||
from ahriman.core.utils import dataclass_view, filter_json
|
||||
|
||||
@@ -31,9 +31,11 @@ class Property:
|
||||
value(Any): property value
|
||||
is_required(bool): if set to ``True`` then this property is required
|
||||
indent(int): property indentation level
|
||||
separator(str | None): optional override for separator
|
||||
"""
|
||||
|
||||
name: str
|
||||
value: Any
|
||||
is_required: bool = field(default=False, kw_only=True)
|
||||
indent: int = 1
|
||||
separator: str | None = None
|
||||
@@ -59,7 +59,7 @@ class RemoteSource:
|
||||
Returns:
|
||||
bool: ``True`` in case if package is well-known remote source (e.g. AUR) and ``False`` otherwise
|
||||
"""
|
||||
return self.source in (PackageSource.AUR, PackageSource.Repository)
|
||||
return self.source in (PackageSource.AUR, PackageSource.REPOSITORY)
|
||||
|
||||
@property
|
||||
def pkgbuild_dir(self) -> Path | None:
|
||||
|
||||
@@ -27,22 +27,22 @@ class ReportSettings(StrEnum):
|
||||
report targets enumeration
|
||||
|
||||
Attributes:
|
||||
Disabled(ReportSettings): option which generates no report for testing purpose
|
||||
DISABLED(ReportSettings): option which generates no report for testing purpose
|
||||
HTML(ReportSettings): HTML report generation
|
||||
Email(ReportSettings): email report generation
|
||||
Console(ReportSettings): print result to console
|
||||
Telegram(ReportSettings): Markdown report to telegram channel
|
||||
EMAIL(ReportSettings): email report generation
|
||||
CONSOLE(ReportSettings): print result to console
|
||||
TELEGRAM(ReportSettings): Markdown report to telegram channel
|
||||
RSS(ReportSettings): RSS report generation
|
||||
RemoteCall(ReportSettings): remote ahriman server call
|
||||
REMOTE_CALL(ReportSettings): remote ahriman server call
|
||||
"""
|
||||
|
||||
Disabled = "disabled" # for testing purpose
|
||||
DISABLED = "disabled" # for testing purpose
|
||||
HTML = "html"
|
||||
Email = "email"
|
||||
Console = "console"
|
||||
Telegram = "telegram"
|
||||
EMAIL = "email"
|
||||
CONSOLE = "console"
|
||||
TELEGRAM = "telegram"
|
||||
RSS = "rss"
|
||||
RemoteCall = "remote-call"
|
||||
REMOTE_CALL = "remote-call"
|
||||
|
||||
@staticmethod
|
||||
def from_option(value: str) -> ReportSettings: # pylint: disable=too-many-return-statements
|
||||
@@ -59,14 +59,14 @@ class ReportSettings(StrEnum):
|
||||
case "html":
|
||||
return ReportSettings.HTML
|
||||
case "email":
|
||||
return ReportSettings.Email
|
||||
return ReportSettings.EMAIL
|
||||
case "console":
|
||||
return ReportSettings.Console
|
||||
return ReportSettings.CONSOLE
|
||||
case "telegram":
|
||||
return ReportSettings.Telegram
|
||||
return ReportSettings.TELEGRAM
|
||||
case "rss":
|
||||
return ReportSettings.RSS
|
||||
case "ahriman" | "remote-call":
|
||||
return ReportSettings.RemoteCall
|
||||
return ReportSettings.REMOTE_CALL
|
||||
case _:
|
||||
return ReportSettings.Disabled
|
||||
return ReportSettings.DISABLED
|
||||
@@ -27,14 +27,14 @@ class SignSettings(StrEnum):
|
||||
sign targets enumeration
|
||||
|
||||
Attributes:
|
||||
Disabled(SignSettings): option which generates no report for testing purpose
|
||||
Packages(SignSettings): sign each package
|
||||
Repository(SignSettings): sign repository database file
|
||||
DISABLED(SignSettings): option which generates no report for testing purpose
|
||||
PACKAGES(SignSettings): sign each package
|
||||
REPOSITORY(SignSettings): sign repository database file
|
||||
"""
|
||||
|
||||
Disabled = "disabled"
|
||||
Packages = "packages"
|
||||
Repository = "repository"
|
||||
DISABLED = "disabled"
|
||||
PACKAGES = "packages"
|
||||
REPOSITORY = "repository"
|
||||
|
||||
@staticmethod
|
||||
def from_option(value: str) -> SignSettings:
|
||||
@@ -49,8 +49,8 @@ class SignSettings(StrEnum):
|
||||
"""
|
||||
match value.lower():
|
||||
case "package" | "packages" | "sign-package":
|
||||
return SignSettings.Packages
|
||||
return SignSettings.PACKAGES
|
||||
case "repository" | "sign-repository":
|
||||
return SignSettings.Repository
|
||||
return SignSettings.REPOSITORY
|
||||
case _:
|
||||
return SignSettings.Disabled
|
||||
return SignSettings.DISABLED
|
||||
@@ -27,12 +27,12 @@ class SmtpSSLSettings(StrEnum):
|
||||
SMTP SSL mode enumeration
|
||||
|
||||
Attributes:
|
||||
Disabled(SmtpSSLSettings): no SSL enabled
|
||||
DISABLED(SmtpSSLSettings): no SSL enabled
|
||||
SSL(SmtpSSLSettings): use SMTP_SSL instead of normal SMTP client
|
||||
STARTTLS(SmtpSSLSettings): use STARTTLS in normal SMTP client
|
||||
"""
|
||||
|
||||
Disabled = "disabled"
|
||||
DISABLED = "disabled"
|
||||
SSL = "ssl"
|
||||
STARTTLS = "starttls"
|
||||
|
||||
@@ -53,4 +53,4 @@ class SmtpSSLSettings(StrEnum):
|
||||
case "starttls":
|
||||
return SmtpSSLSettings.STARTTLS
|
||||
case _:
|
||||
return SmtpSSLSettings.Disabled
|
||||
return SmtpSSLSettings.DISABLED
|
||||
@@ -27,18 +27,18 @@ class UploadSettings(StrEnum):
|
||||
remote synchronization targets enumeration
|
||||
|
||||
Attributes:
|
||||
Disabled(UploadSettings): no sync will be performed, required for testing purpose
|
||||
Rsync(UploadSettings): sync via rsync
|
||||
DISABLED(UploadSettings): no sync will be performed, required for testing purpose
|
||||
RSYNC(UploadSettings): sync via rsync
|
||||
S3(UploadSettings): sync to Amazon S3
|
||||
GitHub(UploadSettings): sync to GitHub releases page
|
||||
RemoteService(UploadSettings): sync to another ahriman instance
|
||||
GITHUB(UploadSettings): sync to GitHub releases page
|
||||
REMOTE_SERVICE(UploadSettings): sync to another ahriman instance
|
||||
"""
|
||||
|
||||
Disabled = "disabled" # for testing purpose
|
||||
Rsync = "rsync"
|
||||
DISABLED = "disabled" # for testing purpose
|
||||
RSYNC = "rsync"
|
||||
S3 = "s3"
|
||||
GitHub = "github"
|
||||
RemoteService = "remote-service"
|
||||
GITHUB = "github"
|
||||
REMOTE_SERVICE = "remote-service"
|
||||
|
||||
@staticmethod
|
||||
def from_option(value: str) -> UploadSettings:
|
||||
@@ -53,12 +53,12 @@ class UploadSettings(StrEnum):
|
||||
"""
|
||||
match value.lower():
|
||||
case "rsync":
|
||||
return UploadSettings.Rsync
|
||||
return UploadSettings.RSYNC
|
||||
case "s3":
|
||||
return UploadSettings.S3
|
||||
case "github":
|
||||
return UploadSettings.GitHub
|
||||
return UploadSettings.GITHUB
|
||||
case "ahriman" | "remote-service":
|
||||
return UploadSettings.RemoteService
|
||||
return UploadSettings.REMOTE_SERVICE
|
||||
case _:
|
||||
return UploadSettings.Disabled
|
||||
return UploadSettings.DISABLED
|
||||
@@ -43,7 +43,7 @@ class User:
|
||||
Simply create user from database data and perform required validation::
|
||||
|
||||
>>> password = User.generate_password(24)
|
||||
>>> user = User(username="ahriman", password=password, access=UserAccess.Full)
|
||||
>>> user = User(username="ahriman", password=password, access=UserAccess.FULL)
|
||||
|
||||
Since the password supplied may be plain text, the :func:`hash_password()` method can be used to hash
|
||||
the password::
|
||||
@@ -59,7 +59,7 @@ class User:
|
||||
|
||||
...and finally access can be verified::
|
||||
|
||||
>>> if user.verify_access(UserAccess.Read):
|
||||
>>> if user.verify_access(UserAccess.READ):
|
||||
>>> print(f"user {user.username} has read access")
|
||||
"""
|
||||
|
||||
|
||||
@@ -27,17 +27,17 @@ class UserAccess(StrEnum):
|
||||
web user access enumeration
|
||||
|
||||
Attributes:
|
||||
Unauthorized(UserAccess): user can access specific resources which are marked as available
|
||||
UNAUTHORIZED(UserAccess): user can access specific resources which are marked as available
|
||||
without authorization (e.g. login, logout, static)
|
||||
Read(UserAccess): user can read the page
|
||||
Reporter(UserAccess): user can read everything and is able to perform some modifications
|
||||
Full(UserAccess): user has full access
|
||||
READ(UserAccess): user can read the page
|
||||
REPORTER(UserAccess): user can read everything and is able to perform some modifications
|
||||
FULL(UserAccess): user has full access
|
||||
"""
|
||||
|
||||
Unauthorized = "unauthorized"
|
||||
Read = "read"
|
||||
Reporter = "reporter"
|
||||
Full = "full"
|
||||
UNAUTHORIZED = "unauthorized"
|
||||
READ = "read"
|
||||
REPORTER = "reporter"
|
||||
FULL = "full"
|
||||
|
||||
def permits(self, other: UserAccess) -> bool:
|
||||
"""
|
||||
|
||||
@@ -4,8 +4,10 @@ from typing import Any
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
from ahriman.core.tree import Tree
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
@@ -54,13 +56,11 @@ def test_print_updates(application: Application, package_ahriman: Package, mocke
|
||||
"""
|
||||
must print updates
|
||||
"""
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
application.print_updates([package_ahriman], log_fn=print)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=print, separator=" -> ")
|
||||
application.print_updates(BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE), log_fn=print)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=print, separator=": ")
|
||||
|
||||
|
||||
def test_with_dependencies(application: Application, package_ahriman: Package, package_python_schedule: Package,
|
||||
@@ -68,14 +68,14 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
"""
|
||||
must append list of missing dependencies
|
||||
"""
|
||||
def create_package_mock(package_base) -> MagicMock:
|
||||
def package(package_base: str) -> MagicMock:
|
||||
mock = MagicMock()
|
||||
mock.base = package_base
|
||||
mock.depends_build = []
|
||||
mock.packages_full = [package_base]
|
||||
return mock
|
||||
|
||||
def get_package(name: str | Path, *args: Any, **kwargs: Any) -> Package:
|
||||
def get_package(name: str | Path, *_args: Any, **_kwargs: Any) -> Package:
|
||||
name = name if isinstance(name, str) else name.name
|
||||
return packages[name]
|
||||
|
||||
@@ -88,8 +88,8 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
packages = {
|
||||
package_ahriman.base: package_ahriman,
|
||||
package_python_schedule.base: package_python_schedule,
|
||||
"python": create_package_mock("python"),
|
||||
"python-installer": create_package_mock("python-installer"),
|
||||
"python": package("python"),
|
||||
"python-installer": package("python-installer"),
|
||||
}
|
||||
|
||||
mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p.name == "python")
|
||||
@@ -99,8 +99,11 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
return_value={"devtools", "python-build", "python-pytest"})
|
||||
status_client_mock = mocker.patch("ahriman.core.status.Client.set_unknown")
|
||||
|
||||
result = application.with_dependencies([package_ahriman], process_dependencies=True)
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
result = application.with_dependencies(plan, process_dependencies=True)
|
||||
assert {package.base: package for package in result} == packages
|
||||
assert result.item(package_ahriman.base).requester is None
|
||||
assert result.item(package_python_schedule.base).requester == package_ahriman.base
|
||||
package_aur_mock.assert_has_calls([
|
||||
MockCall(package_python_schedule.base, package_ahriman.packager, include_provides=True),
|
||||
MockCall("python-installer", package_ahriman.packager, include_provides=True),
|
||||
@@ -117,12 +120,48 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
], any_order=True)
|
||||
|
||||
|
||||
def test_with_dependencies_split(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must preserve resolved subpackages during dependency resolution
|
||||
"""
|
||||
def package(package_base: str, package_name: str, dependencies: list[str]) -> Package:
|
||||
return Package(
|
||||
base=package_base,
|
||||
version="1-1",
|
||||
remote=package_ahriman.remote,
|
||||
packages={package_name: PackageDescription(depends=dependencies)},
|
||||
)
|
||||
|
||||
packages = {
|
||||
"ahriman-core": package("ahriman", "ahriman-core", ["python-tree-sitter-bash"]),
|
||||
"ahriman-web": package("ahriman", "ahriman-web", ["ahriman-core"]),
|
||||
"python-tree-sitter-bash": package("python-tree-sitter-bash", "python-tree-sitter-bash", []),
|
||||
}
|
||||
mocker.patch("ahriman.application.application.Application._known_packages", return_value=set())
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda name, *args, **kwargs: packages[name])
|
||||
mocker.patch("ahriman.core.status.Client.set_unknown")
|
||||
|
||||
plan = BuildPlan().update([
|
||||
package("ahriman", "ahriman", ["ahriman-core", "ahriman-web"])
|
||||
], BuildPlanReason.MANUAL_REQUEST)
|
||||
result = application.with_dependencies(plan, process_dependencies=True)
|
||||
assert [[item.base for item in level] for level in Tree.resolve(result)] == [
|
||||
["python-tree-sitter-bash"], ["ahriman"],
|
||||
]
|
||||
|
||||
plan_item = result.item("ahriman")
|
||||
assert plan_item.package.packages.keys() == {"ahriman", "ahriman-core", "ahriman-web"}
|
||||
assert plan_item.reason == BuildPlanReason.MANUAL_REQUEST
|
||||
assert plan_item.requester is None
|
||||
|
||||
|
||||
def test_with_dependencies_exception(application: Application, package_ahriman: Package,
|
||||
package_python_schedule: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must skip packages if exception occurs
|
||||
"""
|
||||
def create_package_mock(package_base) -> MagicMock:
|
||||
def package(package_base: str) -> MagicMock:
|
||||
mock = MagicMock()
|
||||
mock.base = package_base
|
||||
mock.depends_build = []
|
||||
@@ -132,23 +171,28 @@ def test_with_dependencies_exception(application: Application, package_ahriman:
|
||||
package_python_schedule.packages = {
|
||||
package_python_schedule.base: package_python_schedule.packages[package_python_schedule.base]
|
||||
}
|
||||
package_ahriman.packages[package_ahriman.base].depends = ["devtools", "python", package_python_schedule.base]
|
||||
package_ahriman.packages[package_ahriman.base].depends = ["devtools", package_python_schedule.base]
|
||||
package_ahriman.packages[package_ahriman.base].make_depends = ["python-build", "python-installer"]
|
||||
package_python_installer = package("python-installer")
|
||||
|
||||
packages = {
|
||||
package_ahriman.base: package_ahriman,
|
||||
package_python_schedule.base: package_python_schedule,
|
||||
"python": create_package_mock("python"),
|
||||
"python-installer": create_package_mock("python-installer"),
|
||||
"python": package("python"),
|
||||
"python-installer": package_python_installer,
|
||||
}
|
||||
|
||||
mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p.name == "python")
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda *args: packages[args[0]])
|
||||
mocker.patch("ahriman.models.package.Package.from_build", side_effect=Exception)
|
||||
mocker.patch("ahriman.application.application.Application._known_packages",
|
||||
return_value={"devtools", "python-build", "python-pytest"})
|
||||
return_value={"devtools", "python-build"})
|
||||
failed_mock = mocker.patch("ahriman.core.status.Client.set_failed")
|
||||
|
||||
assert not application.with_dependencies([package_ahriman], process_dependencies=True)
|
||||
plan = BuildPlan().update([package_ahriman, package_python_installer], BuildPlanReason.REGULAR_UPDATE)
|
||||
application.with_dependencies(plan, process_dependencies=True)
|
||||
assert plan.packages == [package_python_installer]
|
||||
failed_mock.assert_called_once_with(package_ahriman.base)
|
||||
|
||||
|
||||
def test_with_dependencies_skip(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@@ -157,8 +201,9 @@ def test_with_dependencies_skip(application: Application, package_ahriman: Packa
|
||||
"""
|
||||
packages_mock = mocker.patch("ahriman.application.application.Application._known_packages")
|
||||
|
||||
assert application.with_dependencies([package_ahriman], process_dependencies=False) == [package_ahriman]
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
assert application.with_dependencies(plan, process_dependencies=False).packages == [package_ahriman]
|
||||
packages_mock.assert_not_called()
|
||||
|
||||
assert application.with_dependencies([], process_dependencies=True) == []
|
||||
assert not application.with_dependencies(BuildPlan(), process_dependencies=True)
|
||||
packages_mock.assert_not_called()
|
||||
@@ -167,7 +167,7 @@ def test_add_add_archive(application_packages: ApplicationPackages, package_ahri
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_archive")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.Archive, "packager")
|
||||
application_packages.add([package_ahriman.base], PackageSource.ARCHIVE, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ def test_add_add_directory(application_packages: ApplicationPackages, package_ah
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_directory")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.Directory, "packager")
|
||||
application_packages.add([package_ahriman.base], PackageSource.DIRECTORY, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ def test_add_add_local(application_packages: ApplicationPackages, package_ahrima
|
||||
"""
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_local")
|
||||
|
||||
application_packages.add([package_ahriman.base], PackageSource.Local, "packager")
|
||||
application_packages.add([package_ahriman.base], PackageSource.LOCAL, "packager")
|
||||
add_mock.assert_called_once_with(package_ahriman.base, "packager")
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ def test_add_add_remote(application_packages: ApplicationPackages, package_descr
|
||||
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_remote")
|
||||
url = f"https://host/{package_description_ahriman.filename}"
|
||||
|
||||
application_packages.add([url], PackageSource.Remote, "packager")
|
||||
application_packages.add([url], PackageSource.REMOTE, "packager")
|
||||
add_mock.assert_called_once_with(url, "packager")
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_call(args: argparse.Namespace, configuration: Configuration, mocker: Mo
|
||||
must call inside lock
|
||||
"""
|
||||
args.configuration = Path("")
|
||||
args.log_handler = LogHandler.Console
|
||||
args.log_handler = LogHandler.CONSOLE
|
||||
args.quiet = False
|
||||
args.report = False
|
||||
mocker.patch("ahriman.application.handlers.handler.Handler.run")
|
||||
|
||||
@@ -24,7 +24,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.package = ["ahriman"]
|
||||
args.now = False
|
||||
args.refresh = 0
|
||||
args.source = PackageSource.Auto
|
||||
args.source = PackageSource.AUTO
|
||||
args.username = "username"
|
||||
args.variable = None
|
||||
return args
|
||||
|
||||
@@ -21,7 +21,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
Returns:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.action = Action.List
|
||||
args.action = Action.LIST
|
||||
args.exit_code = False
|
||||
args.info = False
|
||||
args.package = "package"
|
||||
|
||||
@@ -21,7 +21,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
Returns:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.action = Action.List
|
||||
args.action = Action.LIST
|
||||
args.exit_code = False
|
||||
args.package = "package"
|
||||
return args
|
||||
@@ -68,7 +68,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
|
||||
must remove package changes
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
args.action = Action.REMOVE
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
||||
|
||||
|
||||
@@ -102,9 +102,9 @@ def test_copy_package(package_ahriman: Package, application: Application, mocker
|
||||
path = application.repository.paths.repository / package_ahriman.packages[package_ahriman.base].filename
|
||||
|
||||
Copy.copy_package(package_ahriman, application, application)
|
||||
add_mock.assert_called_once_with([str(path)], PackageSource.Archive)
|
||||
add_mock.assert_called_once_with([str(path)], PackageSource.ARCHIVE)
|
||||
changes_get_mock.assert_called_once_with(package_ahriman.base)
|
||||
changes_update_mock.assert_called_once_with(package_ahriman.base, changes_get_mock.return_value)
|
||||
deps_get_mock.assert_called_once_with(package_ahriman.base)
|
||||
deps_update_mock.assert_called_once_with(package_ahriman.base, deps_get_mock.return_value)
|
||||
package_update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Pending)
|
||||
package_update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.PENDING)
|
||||
@@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
@@ -29,7 +28,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Update
|
||||
args.action = Action.UPDATE
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
hold_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_hold_update")
|
||||
|
||||
@@ -44,7 +43,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
|
||||
must remove held status
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
args.action = Action.REMOVE
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
hold_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_hold_update")
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
must run command
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Update
|
||||
args.action = Action.UPDATE
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
patch_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_create_from_diff",
|
||||
return_value=(args.package, PkgbuildPatch(None, "patch")))
|
||||
@@ -56,7 +56,7 @@ def test_run_function(args: argparse.Namespace, configuration: Configuration, re
|
||||
must run command with patch function flag
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Update
|
||||
args.action = Action.UPDATE
|
||||
args.patch = "patch"
|
||||
args.variable = "version"
|
||||
patch = PkgbuildPatch(args.variable, args.patch)
|
||||
@@ -77,7 +77,7 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, reposi
|
||||
must run command with list flag
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.List
|
||||
args.action = Action.LIST
|
||||
args.variable = ["version"]
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_list")
|
||||
@@ -93,7 +93,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
|
||||
must run command with remove flag
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
args.action = Action.REMOVE
|
||||
args.variable = ["version"]
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_remove")
|
||||
@@ -169,7 +169,7 @@ def test_patch_set_list(application: Application, mocker: MockerFixture) -> None
|
||||
Patch.patch_set_list(application, "ahriman", ["version"], False)
|
||||
get_mock.assert_called_once_with("ahriman", None)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
|
||||
check_mock.assert_called_once_with(False, [PkgbuildPatch(key='version', value='value')])
|
||||
check_mock.assert_called_once_with(False, [PkgbuildPatch(key="version", value="value")])
|
||||
|
||||
|
||||
def test_patch_set_list_all(application: Application, mocker: MockerFixture) -> None:
|
||||
@@ -184,7 +184,7 @@ def test_patch_set_list_all(application: Application, mocker: MockerFixture) ->
|
||||
Patch.patch_set_list(application, "ahriman", None, False)
|
||||
get_mock.assert_called_once_with("ahriman", None)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
|
||||
check_mock.assert_called_once_with(False, [PkgbuildPatch(key=None, value='patch')])
|
||||
check_mock.assert_called_once_with(False, [PkgbuildPatch(key=None, value="patch")])
|
||||
|
||||
|
||||
def test_patch_set_list_empty_exception(application: Application, mocker: MockerFixture) -> None:
|
||||
|
||||
@@ -21,7 +21,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
Returns:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.action = Action.List
|
||||
args.action = Action.LIST
|
||||
args.exit_code = False
|
||||
args.package = "package"
|
||||
return args
|
||||
@@ -68,7 +68,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
|
||||
must remove package pkgbuild
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
args.action = Action.REMOVE
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
changes = Changes("sha", "change", "pkgbuild content")
|
||||
mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes)
|
||||
|
||||
@@ -2,12 +2,12 @@ import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.handlers.rebuild import Rebuild
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
@@ -48,15 +48,18 @@ def test_run(args: argparse.Namespace, package_ahriman: Package, configuration:
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on",
|
||||
return_value=[package_ahriman])
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REBUILD)
|
||||
extract_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.status, from_database=args.from_database)
|
||||
application_packages_mock.assert_called_once_with([package_ahriman], None)
|
||||
application_mock.assert_called_once_with([package_ahriman], Packagers(args.username), bump_pkgrel=args.increment)
|
||||
check_mock.assert_has_calls([MockCall(False, [package_ahriman]), MockCall(False, True)])
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
application_mock.assert_called_once_with(plan, Packagers(args.username), bump_pkgrel=args.increment)
|
||||
check_mock.assert_called_once_with(False, True)
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
@@ -94,8 +97,9 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, rep
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
application_mock.assert_not_called()
|
||||
check_mock.assert_called_once_with(False, [package_ahriman])
|
||||
print_mock.assert_called_once_with([package_ahriman], log_fn=pytest.helpers.anyvar(int))
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REBUILD)
|
||||
check_mock.assert_called_once_with(False, plan)
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
|
||||
|
||||
def test_run_filter(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@@ -109,6 +113,7 @@ def test_run_filter(args: argparse.Namespace, configuration: Configuration, repo
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
@@ -125,6 +130,7 @@ def test_run_without_filter(args: argparse.Namespace, configuration: Configurati
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
@@ -147,7 +153,7 @@ def test_run_update_empty_exception(args: argparse.Namespace, configuration: Con
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
check_mock.assert_called_once_with(True, [])
|
||||
check_mock.assert_called_once_with(True, BuildPlan())
|
||||
|
||||
|
||||
def test_run_build_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@@ -161,11 +167,12 @@ def test_run_build_empty_exception(args: argparse.Namespace, configuration: Conf
|
||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages")
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.update", return_value=Result())
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
check_mock.assert_has_calls([MockCall(True, [package_ahriman]), MockCall(True, False)])
|
||||
check_mock.assert_called_once_with(True, False)
|
||||
|
||||
|
||||
def test_extract_packages(application: Application, mocker: MockerFixture) -> None:
|
||||
@@ -182,10 +189,10 @@ def test_extract_packages_by_status(application: Application, mocker: MockerFixt
|
||||
must extract packages from database and filter them by status
|
||||
"""
|
||||
packages_mock = mocker.patch("ahriman.core.database.SQLite.packages_get", return_value=[
|
||||
("package1", BuildStatus(BuildStatusEnum.Success)),
|
||||
("package2", BuildStatus(BuildStatusEnum.Failed)),
|
||||
("package1", BuildStatus(BuildStatusEnum.SUCCESS)),
|
||||
("package2", BuildStatus(BuildStatusEnum.FAILED)),
|
||||
])
|
||||
assert Rebuild.extract_packages(application, BuildStatusEnum.Failed, from_database=True) == ["package2"]
|
||||
assert Rebuild.extract_packages(application, BuildStatusEnum.FAILED, from_database=True) == ["package2"]
|
||||
packages_mock.assert_called_once_with(application.repository_id)
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
_, repository_id = configuration.check_loaded()
|
||||
ServiceUpdates.run(args, repository_id, configuration, report=False)
|
||||
package_mock.assert_called_once_with(package_ahriman.base, None)
|
||||
application_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" -> ")
|
||||
application_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=": ")
|
||||
check_mock.assert_called_once_with(args.exit_code, False)
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
args.repository = "aur"
|
||||
args.server = None
|
||||
args.sign_key = "key"
|
||||
args.sign_target = [SignSettings.Packages]
|
||||
args.sign_target = [SignSettings.PACKAGES]
|
||||
args.web_port = 8080
|
||||
args.web_unix_socket = Path("/var/lib/ahriman/ahriman-web.sock")
|
||||
return args
|
||||
@@ -244,7 +244,7 @@ def test_configuration_create_directory(configuration: Configuration, mocker: Mo
|
||||
"""
|
||||
must create writable directory for includes
|
||||
"""
|
||||
configuration.set_option("settings", "include", f"/path1 /path2 /path3")
|
||||
configuration.set_option("settings", "include", "/path1 /path2 /path3")
|
||||
mkdir_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.ensure_exists",
|
||||
side_effect=[OSError, "/path2", "/path3"])
|
||||
access_mock = mocker.patch("os.access", side_effect=[False, True])
|
||||
|
||||
@@ -25,7 +25,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.chart = None
|
||||
args.event = EventType.PackageUpdated
|
||||
args.event = EventType.PACKAGE_UPDATED
|
||||
args.from_date = None
|
||||
args.limit = -1
|
||||
args.offset = 0
|
||||
|
||||
@@ -37,8 +37,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
"""
|
||||
args = _default_args(args)
|
||||
packages = [
|
||||
(package_ahriman, BuildStatus(BuildStatusEnum.Success)),
|
||||
(package_python_schedule, BuildStatus(BuildStatusEnum.Failed)),
|
||||
(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS)),
|
||||
(package_python_schedule, BuildStatus(BuildStatusEnum.FAILED)),
|
||||
]
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
application_mock = mocker.patch("ahriman.core.status.Client.status_get")
|
||||
@@ -83,7 +83,7 @@ def test_run_verbose(args: argparse.Namespace, configuration: Configuration, rep
|
||||
args.info = True
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.core.status.local_client.LocalClient.package_get",
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success))])
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS))])
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
@@ -103,7 +103,7 @@ def test_run_with_package_filter(args: argparse.Namespace, configuration: Config
|
||||
args.package = [package_ahriman.base]
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
packages_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_get",
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success))])
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS))])
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Status.run(args, repository_id, configuration, report=False)
|
||||
@@ -116,10 +116,10 @@ def test_run_by_status(args: argparse.Namespace, configuration: Configuration, r
|
||||
must filter packages by status
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.status = BuildStatusEnum.Failed
|
||||
args.status = BuildStatusEnum.FAILED
|
||||
mocker.patch("ahriman.core.status.local_client.LocalClient.package_get",
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success)),
|
||||
(package_python_schedule, BuildStatus(BuildStatusEnum.Failed))])
|
||||
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS)),
|
||||
(package_python_schedule, BuildStatus(BuildStatusEnum.FAILED))])
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.package = None
|
||||
args.action = Action.Update
|
||||
args.status = BuildStatusEnum.Success
|
||||
args.action = Action.UPDATE
|
||||
args.status = BuildStatusEnum.SUCCESS
|
||||
return args
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.package = [package_ahriman.base]
|
||||
args.action = Action.Remove
|
||||
args.action = Action.REMOVE
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_remove")
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from ahriman.application.application import Application
|
||||
from ahriman.application.handlers.update import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.result import Result
|
||||
@@ -65,22 +66,23 @@ def test_perform_action(args: argparse.Namespace, application: Application, pack
|
||||
result.add_updated(package_ahriman)
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
|
||||
return_value=[package_ahriman])
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
return_value=plan)
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
application_mock.assert_called_once_with([package_ahriman],
|
||||
application_mock.assert_called_once_with(plan,
|
||||
Packagers(args.username, {package_ahriman.base: "packager"}),
|
||||
bump_pkgrel=args.increment)
|
||||
updates_mock.assert_called_once_with(
|
||||
args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs, check_files=args.check_files)
|
||||
changes_mock.assert_called_once_with([package_ahriman])
|
||||
dependencies_mock.assert_called_once_with([package_ahriman], process_dependencies=args.dependencies)
|
||||
changes_mock.assert_called_once_with(plan)
|
||||
dependencies_mock.assert_called_once_with(plan, process_dependencies=args.dependencies)
|
||||
check_mock.assert_called_once_with(False, True)
|
||||
print_mock.assert_called_once_with([package_ahriman], log_fn=pytest.helpers.anyvar(int))
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
|
||||
|
||||
def test_perform_action_empty_exception(args: argparse.Namespace, application: Application,
|
||||
@@ -91,11 +93,13 @@ def test_perform_action_empty_exception(args: argparse.Namespace, application: A
|
||||
args = _default_args(args)
|
||||
args.exit_code = True
|
||||
args.dry_run = True
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=[])
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=BuildPlan())
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
check_mock.assert_called_once_with(True, [])
|
||||
print_mock.assert_called_once_with(BuildPlan(), pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
check_mock.assert_called_once_with(True, BuildPlan())
|
||||
|
||||
|
||||
def test_perform_action_update_empty_exception(args: argparse.Namespace, application: Application,
|
||||
@@ -106,10 +110,11 @@ def test_perform_action_update_empty_exception(args: argparse.Namespace, applica
|
||||
args = _default_args(args)
|
||||
args.exit_code = True
|
||||
mocker.patch("ahriman.application.application.Application.update", return_value=Result())
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=plan)
|
||||
mocker.patch("ahriman.application.application.Application.changes")
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
@@ -125,15 +130,21 @@ def test_perform_action_dry_run(args: argparse.Namespace, application: Applicati
|
||||
args.dry_run = True
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
|
||||
return_value=plan)
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
updates_mock.assert_called_once_with(
|
||||
args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs, check_files=args.check_files)
|
||||
application_mock.assert_not_called()
|
||||
changes_mock.assert_called_once_with([package_ahriman])
|
||||
check_mock.assert_called_once_with(False, [package_ahriman])
|
||||
changes_mock.assert_called_once_with(plan)
|
||||
dependencies_mock.assert_called_once_with(plan, process_dependencies=args.dependencies)
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
check_mock.assert_called_once_with(False, plan)
|
||||
|
||||
|
||||
def test_perform_action_no_changes(args: argparse.Namespace, application: Application, mocker: MockerFixture) -> None:
|
||||
@@ -145,7 +156,9 @@ def test_perform_action_no_changes(args: argparse.Namespace, application: Applic
|
||||
args.changes = False
|
||||
mocker.patch("ahriman.application.application.Application.update")
|
||||
mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
mocker.patch("ahriman.application.application.Application.updates")
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=BuildPlan())
|
||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=BuildPlan())
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
|
||||
@@ -24,12 +24,12 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
||||
argparse.Namespace: generated arguments for these test cases
|
||||
"""
|
||||
args.username = "user"
|
||||
args.action = Action.Update
|
||||
args.action = Action.UPDATE
|
||||
args.exit_code = False
|
||||
args.key = "key"
|
||||
args.packager = "packager"
|
||||
args.password = "pa55w0rd"
|
||||
args.role = UserAccess.Reporter
|
||||
args.role = UserAccess.REPORTER
|
||||
return args
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, databa
|
||||
must list available users
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.List
|
||||
args.action = Action.LIST
|
||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
list_mock = mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[user])
|
||||
@@ -114,7 +114,7 @@ def test_run_empty_exception(args: argparse.Namespace, configuration: Configurat
|
||||
must raise ExitCode exception on empty user list
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.List
|
||||
args.action = Action.LIST
|
||||
args.exit_code = True
|
||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
||||
mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[])
|
||||
@@ -131,7 +131,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, data
|
||||
must remove user if remove flag supplied
|
||||
"""
|
||||
args = _default_args(args)
|
||||
args.action = Action.Remove
|
||||
args.action = Action.REMOVE
|
||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
||||
remove_mock = mocker.patch("ahriman.core.database.SQLite.user_remove")
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ def test_subparsers_package_archives(parser: argparse.ArgumentParser) -> None:
|
||||
package-archives command must imply action, exit code, info, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-archives", "ahriman"])
|
||||
assert args.action == Action.List
|
||||
assert args.action == Action.LIST
|
||||
assert args.architecture == "x86_64"
|
||||
assert not args.exit_code
|
||||
assert not args.info
|
||||
@@ -304,7 +304,7 @@ def test_subparsers_package_changes(parser: argparse.ArgumentParser) -> None:
|
||||
package-changes command must imply action, exit code, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes", "ahriman"])
|
||||
assert args.action == Action.List
|
||||
assert args.action == Action.LIST
|
||||
assert args.architecture == "x86_64"
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
@@ -319,7 +319,7 @@ def test_subparsers_package_changes_remove(parser: argparse.ArgumentParser) -> N
|
||||
package-changes-remove command must imply action, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes-remove", "ahriman"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.action == Action.REMOVE
|
||||
assert args.architecture == "x86_64"
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
@@ -362,7 +362,7 @@ def test_subparsers_package_pkgbuild(parser: argparse.ArgumentParser) -> None:
|
||||
package-pkgbuild command must imply action, exit code, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild", "ahriman"])
|
||||
assert args.action == Action.List
|
||||
assert args.action == Action.LIST
|
||||
assert args.architecture == "x86_64"
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
@@ -377,7 +377,7 @@ def test_subparsers_package_pkgbuild_remove(parser: argparse.ArgumentParser) ->
|
||||
package-pkgbuild-remove command must imply action, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild-remove", "ahriman"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.action == Action.REMOVE
|
||||
assert args.architecture == "x86_64"
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
@@ -496,7 +496,7 @@ def test_subparsers_package_status_remove(parser: argparse.ArgumentParser) -> No
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-remove", "ahriman"])
|
||||
assert args.architecture == "x86_64"
|
||||
assert args.action == Action.Remove
|
||||
assert args.action == Action.REMOVE
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
assert not args.report
|
||||
@@ -510,7 +510,7 @@ def test_subparsers_package_status_update(parser: argparse.ArgumentParser) -> No
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-update"])
|
||||
assert args.architecture == "x86_64"
|
||||
assert args.action == Action.Update
|
||||
assert args.action == Action.UPDATE
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
assert not args.report
|
||||
@@ -543,7 +543,7 @@ def test_subparsers_package_hold(parser: argparse.ArgumentParser) -> None:
|
||||
package-hold command must imply action, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["package-hold", "ahriman"])
|
||||
assert args.action == Action.Update
|
||||
assert args.action == Action.UPDATE
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
assert not args.report
|
||||
@@ -555,7 +555,7 @@ def test_subparsers_package_unhold(parser: argparse.ArgumentParser) -> None:
|
||||
package-unhold command must imply action, lock, quiet, report and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["package-unhold", "ahriman"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.action == Action.REMOVE
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
assert not args.report
|
||||
@@ -567,7 +567,7 @@ def test_subparsers_patch_add(parser: argparse.ArgumentParser) -> None:
|
||||
patch-add command must imply action, architecture list, exit code, lock, report and repository
|
||||
"""
|
||||
args = parser.parse_args(["patch-add", "ahriman", "version"])
|
||||
assert args.action == Action.Update
|
||||
assert args.action == Action.UPDATE
|
||||
assert args.architecture == ""
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
@@ -596,7 +596,7 @@ def test_subparsers_patch_list(parser: argparse.ArgumentParser) -> None:
|
||||
patch-list command must imply action, architecture list, lock, report, repository and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["patch-list", "ahriman"])
|
||||
assert args.action == Action.List
|
||||
assert args.action == Action.LIST
|
||||
assert args.architecture == ""
|
||||
assert args.lock is None
|
||||
assert not args.report
|
||||
@@ -651,7 +651,7 @@ def test_subparsers_patch_remove(parser: argparse.ArgumentParser) -> None:
|
||||
patch-remove command must imply action, architecture list, exit code, lock, report and repository
|
||||
"""
|
||||
args = parser.parse_args(["patch-remove", "ahriman"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.action == Action.REMOVE
|
||||
assert args.architecture == ""
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
@@ -706,7 +706,7 @@ def test_subparsers_patch_set_add(parser: argparse.ArgumentParser) -> None:
|
||||
patch-set-add command must imply action, architecture list, exit code, lock, report, repository and variable
|
||||
"""
|
||||
args = parser.parse_args(["patch-set-add", "ahriman"])
|
||||
assert args.action == Action.Update
|
||||
assert args.action == Action.UPDATE
|
||||
assert args.architecture == ""
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
@@ -1172,7 +1172,7 @@ def test_subparsers_repo_status_update(parser: argparse.ArgumentParser) -> None:
|
||||
"""
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "repo-status-update"])
|
||||
assert args.architecture == "x86_64"
|
||||
assert args.action == Action.Update
|
||||
assert args.action == Action.UPDATE
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
assert not args.report
|
||||
@@ -1537,7 +1537,7 @@ def test_subparsers_service_setup_option_sign_target_multiple(parser: argparse.A
|
||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
|
||||
"--packager", "ahriman bot <ahriman@example.com>", "--sign-target", "packages",
|
||||
"--sign-target", "repository"])
|
||||
assert args.sign_target == [SignSettings.Packages, SignSettings.Repository]
|
||||
assert args.sign_target == [SignSettings.PACKAGES, SignSettings.REPOSITORY]
|
||||
|
||||
|
||||
def test_subparsers_service_shell(parser: argparse.ArgumentParser) -> None:
|
||||
@@ -1564,7 +1564,7 @@ def test_subparsers_user_add(parser: argparse.ArgumentParser) -> None:
|
||||
user-add command must imply action, architecture, exit code, lock, quiet, report and repository
|
||||
"""
|
||||
args = parser.parse_args(["user-add", "username"])
|
||||
assert args.action == Action.Update
|
||||
assert args.action == Action.UPDATE
|
||||
assert args.architecture == ""
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
@@ -1604,7 +1604,7 @@ def test_subparsers_user_list(parser: argparse.ArgumentParser) -> None:
|
||||
user-list command must imply action, architecture, lock, quiet, report, repository and unsafe
|
||||
"""
|
||||
args = parser.parse_args(["user-list"])
|
||||
assert args.action == Action.List
|
||||
assert args.action == Action.LIST
|
||||
assert args.architecture == ""
|
||||
assert args.lock is None
|
||||
assert args.quiet
|
||||
@@ -1652,7 +1652,7 @@ def test_subparsers_user_remove(parser: argparse.ArgumentParser) -> None:
|
||||
user-remove command must imply action, architecture, exit code, lock, quiet, report and repository
|
||||
"""
|
||||
args = parser.parse_args(["user-remove", "username"])
|
||||
assert args.action == Action.Remove
|
||||
assert args.action == Action.REMOVE
|
||||
assert args.architecture == ""
|
||||
assert not args.exit_code
|
||||
assert args.lock is None
|
||||
|
||||
@@ -278,7 +278,7 @@ def test_enter(lock: Lock, mocker: MockerFixture) -> None:
|
||||
check_user_mock.assert_called_once_with()
|
||||
check_version_mock.assert_called_once_with()
|
||||
lock_mock.assert_called_once_with()
|
||||
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.Building), MockCall(BuildStatusEnum.Success)])
|
||||
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.BUILDING), MockCall(BuildStatusEnum.SUCCESS)])
|
||||
|
||||
|
||||
def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None:
|
||||
@@ -293,4 +293,4 @@ def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None:
|
||||
with pytest.raises(ValueError):
|
||||
with lock:
|
||||
raise ValueError()
|
||||
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.Building), MockCall(BuildStatusEnum.Failed)])
|
||||
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.BUILDING), MockCall(BuildStatusEnum.FAILED)])
|
||||
@@ -96,7 +96,7 @@ def pacman(configuration: Configuration) -> Pacman:
|
||||
Pacman: pacman wrapper test instance
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
return Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
||||
return Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.DISABLED)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -107,10 +107,10 @@ def passwd() -> MagicMock:
|
||||
Returns:
|
||||
MagicMock: passwd structure test instance
|
||||
"""
|
||||
passwd = MagicMock()
|
||||
passwd.pw_dir = "home"
|
||||
passwd.pw_name = "ahriman"
|
||||
return passwd
|
||||
mock = MagicMock()
|
||||
mock.pw_dir = "home"
|
||||
mock.pw_name = "ahriman"
|
||||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.alpm.pacman_database import PacmanDatabase
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
from ahriman.core.alpm.pacman_database import PacmanDatabase
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ def test_multisearch_empty(pacman: Pacman, mocker: MockerFixture) -> None:
|
||||
terms = ["it", "is"]
|
||||
search_mock = mocker.patch("ahriman.core.alpm.remote.Remote.package_search")
|
||||
|
||||
assert Remote.multisearch(*terms, pacman=pacman) == []
|
||||
assert not Remote.multisearch(*terms, pacman=pacman)
|
||||
search_mock.assert_not_called()
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_init_with_local_cache(configuration: Configuration, mocker: MockerFixtu
|
||||
with TemporaryDirectory(ignore_cleanup_errors=True) as pacman_root:
|
||||
mocker.patch.object(RepositoryPaths, "pacman", Path(pacman_root))
|
||||
# during the creation pyalpm.Handle will create also version file which we would like to remove later
|
||||
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Enabled)
|
||||
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.ENABLED)
|
||||
assert pacman.handle
|
||||
sync_mock.assert_called_once_with(pytest.helpers.anyvar(int), force=False)
|
||||
|
||||
@@ -45,7 +45,7 @@ def test_init_with_local_cache_forced(configuration: Configuration, mocker: Mock
|
||||
with TemporaryDirectory(ignore_cleanup_errors=True) as pacman_root:
|
||||
mocker.patch.object(RepositoryPaths, "pacman", Path(pacman_root))
|
||||
# during the creation pyalpm.Handle will create also version file which we would like to remove later
|
||||
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Force)
|
||||
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.FORCE)
|
||||
assert pacman.handle
|
||||
sync_mock.assert_called_once_with(pytest.helpers.anyvar(int), force=True)
|
||||
|
||||
|
||||
@@ -18,9 +18,48 @@ def test_expand_array() -> None:
|
||||
parser = PkgbuildParser(BytesIO(b"array=(prefix{first,second}suffix)"))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("array", ["prefixfirstsuffix", "prefixsecondsuffix"])]
|
||||
|
||||
parser = PkgbuildParser(BytesIO(br"array=(prefix{first\,second,third}suffix)"))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("array", ["prefixfirst,secondsuffix", "prefixthirdsuffix"])]
|
||||
|
||||
parser = PkgbuildParser(BytesIO(b"""array=("prefix{first,second}suffix")"""))
|
||||
assert list(parser.parse()) == [PkgbuildPatch("array", ["prefix{first,second}suffix"])]
|
||||
|
||||
parser = PkgbuildParser(BytesIO(b"""array=(x"{a,b}" x'{a,b}' "{x,y}"{a,b})"""))
|
||||
assert list(parser) == [PkgbuildPatch("array", ["x{a,b}", "x{a,b}", "{x,y}a", "{x,y}b"])]
|
||||
|
||||
parser = PkgbuildParser(BytesIO(b"""array=(${v:-a,b}suffix ${v:-a,b}{,.sig} $(echo '{a,b}')suffix)"""))
|
||||
assert list(parser) == [PkgbuildPatch("array", [
|
||||
"${v:-a,b}suffix", "${v:-a,b}", "${v:-a,b}.sig", "$(echo '{a,b}')suffix",
|
||||
])]
|
||||
|
||||
|
||||
def test_parse_append_array() -> None:
|
||||
"""
|
||||
must retain original array elements when appending and iterating again
|
||||
"""
|
||||
parser = PkgbuildParser(BytesIO(
|
||||
b"source=(base.patch)\nsource+=(extra.patch)\nsource+=(last.patch)\nsource=(reset.patch)\nsource+=(extra.patch)"
|
||||
))
|
||||
expected = [
|
||||
PkgbuildPatch("source", ["base.patch"]),
|
||||
PkgbuildPatch("source", ["base.patch", "extra.patch"]),
|
||||
PkgbuildPatch("source", ["base.patch", "extra.patch", "last.patch"]),
|
||||
PkgbuildPatch("source", ["reset.patch"]),
|
||||
PkgbuildPatch("source", ["reset.patch", "extra.patch"]),
|
||||
]
|
||||
assert list(parser) == expected
|
||||
|
||||
|
||||
def test_parse_append_array_to_string() -> None:
|
||||
"""
|
||||
must preserve a string as the first element when appending an array
|
||||
"""
|
||||
parser = PkgbuildParser(BytesIO(b"source=base.patch\nsource+=(extra.patch)"))
|
||||
assert list(parser) == [
|
||||
PkgbuildPatch("source", "base.patch"),
|
||||
PkgbuildPatch("source", ["base.patch", "extra.patch"]),
|
||||
]
|
||||
|
||||
|
||||
def test_parse_array() -> None:
|
||||
"""
|
||||
@@ -71,7 +110,7 @@ def test_parse_array_exception() -> None:
|
||||
"""
|
||||
parser = PkgbuildParser(BytesIO(b"var=(first second"))
|
||||
with pytest.raises(PkgbuildParserError):
|
||||
assert list(parser.parse())
|
||||
list(parser.parse())
|
||||
|
||||
|
||||
def test_parse_function() -> None:
|
||||
@@ -119,11 +158,11 @@ def test_parse_function_exception() -> None:
|
||||
"""
|
||||
parser = PkgbuildParser(BytesIO(b"var() echo hello world } "))
|
||||
with pytest.raises(PkgbuildParserError):
|
||||
assert list(parser.parse())
|
||||
list(parser.parse())
|
||||
|
||||
parser = PkgbuildParser(BytesIO(b"var() { echo hello world"))
|
||||
with pytest.raises(PkgbuildParserError):
|
||||
assert list(parser.parse())
|
||||
list(parser.parse())
|
||||
|
||||
|
||||
def test_parse_function_inner_shell() -> None:
|
||||
@@ -243,4 +282,12 @@ def test_parse(resource_path_root: Path) -> None:
|
||||
_ver="$(cat CMakeLists.txt | grep -e SO_MAJOR_VERSION -e SO_MINOR_VERSION -e SO_BUILD_VERSION | cut -d '"' -f2 | head -n3)"
|
||||
echo "$(echo ${_ver} | tr ' ' .).r$(git rev-list --count HEAD).$(git rev-parse --short HEAD)"
|
||||
}"""),
|
||||
PkgbuildPatch("var", "say \"hello\""),
|
||||
PkgbuildPatch("var", "a\\b"),
|
||||
PkgbuildPatch("var", "$name"),
|
||||
PkgbuildPatch("var", "`date`"),
|
||||
PkgbuildPatch("var", "firstsecond"),
|
||||
PkgbuildPatch("var", "a\\qb"),
|
||||
PkgbuildPatch("var", "\\$name"),
|
||||
PkgbuildPatch("var", "first\nsecond"),
|
||||
]
|
||||
@@ -61,7 +61,7 @@ def test_extend_architectures_any(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_file", return_value=True)
|
||||
mocker.patch("ahriman.models.pkgbuild.Pkgbuild.supported_architectures", return_value={"any"})
|
||||
assert Sources.extend_architectures(Path("local"), "i686") == []
|
||||
assert not Sources.extend_architectures(Path("local"), "i686")
|
||||
|
||||
|
||||
def test_fetch_empty(remote_source: RemoteSource, mocker: MockerFixture) -> None:
|
||||
@@ -137,7 +137,7 @@ def test_fetch_new_without_remote(sources: Sources, mocker: MockerFixture) -> No
|
||||
head_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.head", return_value="sha")
|
||||
|
||||
local = Path("local")
|
||||
assert sources.fetch(local, RemoteSource(source=PackageSource.Archive)) == "sha"
|
||||
assert sources.fetch(local, RemoteSource(source=PackageSource.ARCHIVE)) == "sha"
|
||||
check_output_mock.assert_has_calls([
|
||||
MockCall(*sources.git(), "checkout", "--force", sources.DEFAULT_BRANCH,
|
||||
cwd=local, logger=pytest.helpers.anyvar(int)),
|
||||
@@ -347,7 +347,7 @@ def test_add_skip(sources: Sources, mocker: MockerFixture) -> None:
|
||||
check_output_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_add_force(sources: Sources, tmp_path: Path, mocker: MockerFixture) -> None:
|
||||
def test_add_force(sources: Sources, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must add files to git with --force flag
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import configparser
|
||||
import pytest
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import pytest
|
||||
|
||||
from dataclasses import replace
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
@@ -38,7 +36,7 @@ def test_move_packages(repository_paths: RepositoryPaths, package_ahriman: Packa
|
||||
must move packages to the archive directory
|
||||
"""
|
||||
|
||||
def is_file(self: Path, *args: Any, **kwargs: Any) -> bool:
|
||||
def is_file(self: Path, **_: Any) -> bool:
|
||||
return "file" in self.name
|
||||
|
||||
mocker.patch("pathlib.Path.iterdir", return_value=[
|
||||
|
||||
@@ -29,9 +29,9 @@ def test_user_list_filter_by_username(database: SQLite) -> None:
|
||||
"""
|
||||
must return users filtered by its id
|
||||
"""
|
||||
first = User(username="1", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.Full, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
first = User(username="1", password="", access=UserAccess.READ, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.FULL, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.READ, packager_id=None, key=None)
|
||||
|
||||
database.user_update(first)
|
||||
database.user_update(second)
|
||||
@@ -46,15 +46,15 @@ def test_user_list_filter_by_access(database: SQLite) -> None:
|
||||
"""
|
||||
must return users filtered by its access
|
||||
"""
|
||||
first = User(username="1", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.Full, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
first = User(username="1", password="", access=UserAccess.READ, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.FULL, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.READ, packager_id=None, key=None)
|
||||
|
||||
database.user_update(first)
|
||||
database.user_update(second)
|
||||
database.user_update(third)
|
||||
|
||||
users = database.user_list(None, UserAccess.Read)
|
||||
users = database.user_list(None, UserAccess.READ)
|
||||
assert len(users) == 2
|
||||
assert first in users
|
||||
assert third in users
|
||||
@@ -64,16 +64,16 @@ def test_user_list_filter_by_username_access(database: SQLite) -> None:
|
||||
"""
|
||||
must return users filtered by its access and username
|
||||
"""
|
||||
first = User(username="1", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.Full, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.Read, packager_id=None, key=None)
|
||||
first = User(username="1", password="", access=UserAccess.READ, packager_id=None, key=None)
|
||||
second = User(username="2", password="", access=UserAccess.FULL, packager_id=None, key=None)
|
||||
third = User(username="3", password="", access=UserAccess.READ, packager_id=None, key=None)
|
||||
|
||||
database.user_update(first)
|
||||
database.user_update(second)
|
||||
database.user_update(third)
|
||||
|
||||
assert database.user_list("1", UserAccess.Read) == [first]
|
||||
assert not database.user_list("1", UserAccess.Full)
|
||||
assert database.user_list("1", UserAccess.READ) == [first]
|
||||
assert not database.user_list("1", UserAccess.FULL)
|
||||
|
||||
|
||||
def test_user_remove_update(database: SQLite, user: User) -> None:
|
||||
@@ -92,7 +92,7 @@ def test_user_update(database: SQLite, user: User) -> None:
|
||||
database.user_update(user)
|
||||
assert database.user_get(user.username) == user
|
||||
|
||||
new_user = User(username=user.username, password=user.hash_password("salt").password, access=UserAccess.Full,
|
||||
new_user = User(username=user.username, password=user.hash_password("salt").password, access=UserAccess.FULL,
|
||||
packager_id=None, key="new key")
|
||||
database.user_update(new_user)
|
||||
assert database.user_get(new_user.username) == new_user
|
||||
@@ -8,7 +8,7 @@ def test_event_insert_get(database: SQLite, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must insert and get event
|
||||
"""
|
||||
event = Event(EventType.PackageUpdated, package_ahriman.base, "Updated", key="value")
|
||||
event = Event(EventType.PACKAGE_UPDATED, package_ahriman.base, "Updated", key="value")
|
||||
database.event_insert(event)
|
||||
assert database.event_get() == [event]
|
||||
|
||||
@@ -24,11 +24,11 @@ def test_event_insert_get_filter(database: SQLite) -> None:
|
||||
"""
|
||||
database.event_insert(Event("event 1", "object 1", created=1))
|
||||
database.event_insert(Event("event 2", "object 2"))
|
||||
database.event_insert(Event(EventType.PackageUpdated, "package"))
|
||||
database.event_insert(Event(EventType.PACKAGE_UPDATED, "package"))
|
||||
|
||||
assert database.event_get(event="event 1") == [Event("event 1", "object 1", created=1)]
|
||||
assert database.event_get(object_id="object 1") == [Event("event 1", "object 1", created=1)]
|
||||
assert all(event.event == EventType.PackageUpdated for event in database.event_get(event=EventType.PackageUpdated))
|
||||
assert all(event.event == EventType.PACKAGE_UPDATED for event in database.event_get(event=EventType.PACKAGE_UPDATED))
|
||||
|
||||
|
||||
def test_event_insert_get_pagination(database: SQLite) -> None:
|
||||
|
||||
@@ -144,7 +144,7 @@ def test_package_remove(database: SQLite, package_ahriman: Package, mocker: Mock
|
||||
database._repository_id)
|
||||
|
||||
|
||||
def test_package_update(database: SQLite, package_ahriman: Package, mocker: MockerFixture):
|
||||
def test_package_update(database: SQLite, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must update package status
|
||||
"""
|
||||
|
||||
@@ -23,6 +23,7 @@ from ahriman.core.formatters import (
|
||||
VersionPrinter
|
||||
)
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.changes import Changes
|
||||
from ahriman.models.package import Package
|
||||
@@ -219,7 +220,8 @@ def update_printer(package_ahriman: Package) -> UpdatePrinter:
|
||||
Returns:
|
||||
UpdatePrinter: update printer test instance
|
||||
"""
|
||||
return UpdatePrinter(package_ahriman, None)
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
return UpdatePrinter(plan, {})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -53,11 +53,23 @@ def test_print_indent(mocker: MockerFixture) -> None:
|
||||
log_mock.assert_has_calls([MockCall("key: value"), MockCall("\tkey: value"), MockCall("\t\tkey: value")])
|
||||
|
||||
|
||||
def test_print_separator(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must use property separator instead of default separator
|
||||
"""
|
||||
log_mock = MagicMock()
|
||||
|
||||
mocker.patch("ahriman.core.formatters.Printer.properties", return_value=[Property("key", "value", separator=" ")])
|
||||
Printer().print(verbose=True, log_fn=log_mock)
|
||||
|
||||
log_mock.assert_called_once_with("\tkey value")
|
||||
|
||||
|
||||
def test_properties() -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert Printer().properties() == []
|
||||
assert not Printer().properties()
|
||||
|
||||
|
||||
def test_title() -> None:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from ahriman.core.formatters import UpdatePrinter
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.property import Property
|
||||
|
||||
|
||||
@@ -13,25 +15,52 @@ def test_properties_na(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must return N/A if local version is unknown
|
||||
"""
|
||||
assert update_printer.properties() == [Property("N/A", update_printer.package.version, is_required=True)]
|
||||
package = update_printer.plan.packages[0]
|
||||
assert update_printer.properties() == [
|
||||
Property(package.base, "", is_required=True),
|
||||
Property("N/A", package.version, is_required=True, indent=2, separator=" -> "),
|
||||
Property("Reason", BuildPlanReason.REGULAR_UPDATE.value, indent=2),
|
||||
]
|
||||
|
||||
|
||||
def test_properties_bump_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
def test_properties_package_required_by(package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must include requestee package to properties
|
||||
"""
|
||||
plan = BuildPlan()
|
||||
plan.add(package_python_schedule, BuildPlanReason.REQUIRED_BY, requester="ahriman")
|
||||
|
||||
properties = list(UpdatePrinter(plan, {}, bump_pkgrel=False).properties_package(package_python_schedule))
|
||||
assert properties[-1].value == "required by ahriman"
|
||||
|
||||
|
||||
def test_versions_bump_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must bump pkgrel if local version is the same
|
||||
"""
|
||||
update_printer.local_version = update_printer.package.version
|
||||
assert update_printer.properties() == [Property(update_printer.package.version, "2.6.0-1.1", is_required=True)]
|
||||
package = update_printer.plan.packages[0]
|
||||
update_printer.local_versions[package.base] = package.version
|
||||
assert update_printer.versions(package) == (package.version, "2.6.0-1.1")
|
||||
|
||||
|
||||
def test_properties_keep_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
def test_versions_keep_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must keep pkgrel if local version is not the same
|
||||
"""
|
||||
update_printer.local_version = "2.5.0-1"
|
||||
assert update_printer.properties() == [
|
||||
Property(update_printer.local_version, update_printer.package.version, is_required=True),
|
||||
]
|
||||
package = update_printer.plan.packages[0]
|
||||
update_printer.local_versions[package.base] = "2.5.0-1"
|
||||
assert update_printer.versions(package) == ("2.5.0-1", package.version)
|
||||
|
||||
|
||||
def test_versions_no_increment(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must preserve the package version when release incrementing is disabled
|
||||
"""
|
||||
package = update_printer.plan.packages[0]
|
||||
update_printer.local_versions[package.base] = package.version
|
||||
update_printer.bump_pkgrel = False
|
||||
|
||||
assert update_printer.versions(package) == (package.version, package.version)
|
||||
|
||||
|
||||
def test_title(update_printer: UpdatePrinter) -> None:
|
||||
|
||||
@@ -98,7 +98,7 @@ def test_headers() -> None:
|
||||
"""
|
||||
must return empty additional headers
|
||||
"""
|
||||
assert SyncHttpClient().headers() == {}
|
||||
assert not SyncHttpClient().headers()
|
||||
|
||||
|
||||
def test_make_request(mocker: MockerFixture) -> None:
|
||||
|
||||
@@ -16,14 +16,14 @@ def test_handler() -> None:
|
||||
"""
|
||||
must extract journald handler if available
|
||||
"""
|
||||
assert LogLoader.handler(None) == LogHandler.Journald
|
||||
assert LogLoader.handler(None) == LogHandler.JOURNALD
|
||||
|
||||
|
||||
def test_handler_selected() -> None:
|
||||
"""
|
||||
must return selected log handler
|
||||
"""
|
||||
assert LogLoader.handler(LogHandler.Console) == LogHandler.Console
|
||||
assert LogLoader.handler(LogHandler.CONSOLE) == LogHandler.CONSOLE
|
||||
|
||||
|
||||
def test_handler_syslog(mocker: MockerFixture) -> None:
|
||||
@@ -32,7 +32,7 @@ def test_handler_syslog(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.exists", return_value=True)
|
||||
mocker.patch.dict(sys.modules, {"systemd.journal": None})
|
||||
assert LogLoader.handler(None) == LogHandler.Syslog
|
||||
assert LogLoader.handler(None) == LogHandler.SYSLOG
|
||||
|
||||
|
||||
def test_handler_console(mocker: MockerFixture) -> None:
|
||||
@@ -41,7 +41,7 @@ def test_handler_console(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
mocker.patch("pathlib.Path.exists", return_value=False)
|
||||
mocker.patch.dict(sys.modules, {"systemd.journal": None})
|
||||
assert LogLoader.handler(None) == LogHandler.Console
|
||||
assert LogLoader.handler(None) == LogHandler.CONSOLE
|
||||
|
||||
|
||||
def test_load(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@@ -52,7 +52,7 @@ def test_load(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
http_log_mock = mocker.patch("ahriman.core.log.http_log_handler.HttpLogHandler.load")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
LogLoader.load(repository_id, configuration, LogHandler.Journald, quiet=False, report=False)
|
||||
LogLoader.load(repository_id, configuration, LogHandler.JOURNALD, quiet=False, report=False)
|
||||
logging_mock.assert_called_once_with(pytest.helpers.anyvar(int), disable_existing_loggers=True)
|
||||
http_log_mock.assert_called_once_with(repository_id, configuration, report=False)
|
||||
assert all(isinstance(handler, JournalHandler) for handler in logging.getLogger().handlers)
|
||||
@@ -64,7 +64,7 @@ def test_load_fallback(configuration: Configuration, mocker: MockerFixture) -> N
|
||||
"""
|
||||
mocker.patch("ahriman.core.log.log_loader.fileConfig", side_effect=PermissionError)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
LogLoader.load(repository_id, configuration, LogHandler.Journald, quiet=False, report=False)
|
||||
LogLoader.load(repository_id, configuration, LogHandler.JOURNALD, quiet=False, report=False)
|
||||
|
||||
|
||||
def test_load_quiet(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@@ -74,7 +74,7 @@ def test_load_quiet(configuration: Configuration, mocker: MockerFixture) -> None
|
||||
disable_mock = mocker.patch("logging.disable")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
LogLoader.load(repository_id, configuration, LogHandler.Journald, quiet=True, report=False)
|
||||
LogLoader.load(repository_id, configuration, LogHandler.JOURNALD, quiet=True, report=False)
|
||||
disable_mock.assert_called_once_with(logging.WARNING)
|
||||
|
||||
|
||||
|
||||
Loaded 100 of 257 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user