mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-28 10:39:29 +00:00
Compare commits
11
Commits
22c763ed52
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fcb4cdb84 | ||
|
|
c70640c492 | ||
|
|
aff4bb70a9 | ||
|
|
afc2e749b9 | ||
|
|
941a51d496 | ||
|
|
11787f740e | ||
|
|
239149f2b4 | ||
|
|
b28c156e78 | ||
|
|
a428b62993 | ||
|
|
0bd22a049c | ||
|
|
71c5d58264 |
No files matched your search
@@ -8,6 +8,7 @@ load-plugins = [
|
||||
"pylint.extensions.typing",
|
||||
"pylint_plugins.definition_order",
|
||||
"pylint_plugins.import_order",
|
||||
"pylint_plugins.type_annotations",
|
||||
]
|
||||
|
||||
[tool.pylint.classes]
|
||||
|
||||
@@ -147,9 +147,6 @@ Again, the most checks can be performed by `tox` command, though some additional
|
||||
* Import order must be the following:
|
||||
|
||||
```python
|
||||
# optional imports from future module
|
||||
from __future__ import annotations
|
||||
|
||||
# Module import for those which are installed into environment (no matter standard library or not)...
|
||||
import os
|
||||
# ...one per line...
|
||||
|
||||
@@ -60,12 +60,14 @@ triggers[] = ahriman.core.gitremote.RemotePullTrigger
|
||||
triggers[] = ahriman.core.report.ReportTrigger
|
||||
triggers[] = ahriman.core.upload.UploadTrigger
|
||||
triggers[] = ahriman.core.gitremote.RemotePushTrigger
|
||||
triggers[] = ahriman.core.housekeeping.EventsRotationTrigger
|
||||
triggers[] = ahriman.core.housekeeping.LogsRotationTrigger
|
||||
triggers[] = ahriman.core.housekeeping.ArchiveRotationTrigger
|
||||
; List of well-known triggers. Used only for configuration purposes.
|
||||
triggers_known[] = ahriman.core.gitremote.RemotePullTrigger
|
||||
triggers_known[] = ahriman.core.gitremote.RemotePushTrigger
|
||||
triggers_known[] = ahriman.core.housekeeping.ArchiveRotationTrigger
|
||||
triggers_known[] = ahriman.core.housekeeping.EventsRotationTrigger
|
||||
triggers_known[] = ahriman.core.housekeeping.LogsRotationTrigger
|
||||
triggers_known[] = ahriman.core.report.ReportTrigger
|
||||
triggers_known[] = ahriman.core.upload.UploadTrigger
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
; Keep amount of last built packages in archive. 0 means keep all packages
|
||||
keep_built_packages = 1
|
||||
|
||||
[events-rotation]
|
||||
; Keep the most recent audit events for each object. 0 removes all events.
|
||||
keep_last_events = 1000
|
||||
|
||||
[logs-rotation]
|
||||
; Keep last build logs for each package
|
||||
keep_last_logs = 5
|
||||
|
||||
@@ -45,7 +45,7 @@ class Application(ApplicationPackages, ApplicationRepository):
|
||||
>>> application.add(["ahriman"], PackageSource.AUR)
|
||||
>>>
|
||||
>>> # check for updates
|
||||
>>> updates = application.updates([], aur=True, local=True, manual=True, vcs=True)
|
||||
>>> updates = application.updates([], aur=True, local=True, manual=True, vcs=True, check_files=False)
|
||||
>>> # updates for specified packages
|
||||
>>> application.update(updates)
|
||||
|
||||
@@ -170,6 +170,8 @@ class Application(ApplicationPackages, ApplicationRepository):
|
||||
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
|
||||
|
||||
# update existing package
|
||||
|
||||
@@ -41,7 +41,7 @@ class UpdatesIterator(Iterator[list[str] | None]):
|
||||
Typical usage of this class is something like:
|
||||
|
||||
>>> application = ...
|
||||
>>> iterator = UpdatesIterator(application, None)
|
||||
>>> iterator = UpdatesIterator(application, 3600)
|
||||
>>>
|
||||
>>> for updates in iterator:
|
||||
>>> print(updates)
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
@@ -158,7 +158,7 @@ class Statistics(Handler):
|
||||
Args:
|
||||
event_type(str): event type
|
||||
events(list[Event]): list of events
|
||||
chart_path(Path): path to save plot if any
|
||||
chart_path(Path | None): path to save plot if any
|
||||
"""
|
||||
# event statistics
|
||||
Statistics.event_stats(event_type, events)
|
||||
@@ -175,7 +175,7 @@ class Statistics(Handler):
|
||||
Args:
|
||||
event_type(str): event type
|
||||
events(list[Event]): list of events
|
||||
chart_path(Path): path to save plot if any
|
||||
chart_path(Path | None): path to save plot if any
|
||||
"""
|
||||
key: Callable[[Event], str] = lambda event: event.object_id
|
||||
by_object_id = {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse
|
||||
import itertools
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
@@ -56,9 +57,9 @@ class Status(Handler):
|
||||
service_status = client.status_get()
|
||||
StatusPrinter(service_status.status)(verbose=args.info)
|
||||
if args.package:
|
||||
packages: list[tuple[Package, BuildStatus]] = sum(
|
||||
(client.package_get(base) for base in args.package),
|
||||
start=[])
|
||||
packages: list[tuple[Package, BuildStatus]] = list(
|
||||
itertools.chain.from_iterable(client.package_get(base) for base in args.package)
|
||||
)
|
||||
else:
|
||||
packages = client.package_get(None)
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class UnsafeCommands(Handler):
|
||||
check if command is unsafe
|
||||
|
||||
Args:
|
||||
command(str): command to check
|
||||
command(list[str]): command and arguments to check
|
||||
unsafe_commands(list[str]): list of unsafe commands
|
||||
parser(argparse.ArgumentParser): generated argument parser
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#
|
||||
import argparse
|
||||
import copy
|
||||
import itertools
|
||||
|
||||
from typing import Any
|
||||
|
||||
@@ -97,7 +98,7 @@ class Validate(Handler):
|
||||
|
||||
# create trigger loader instance
|
||||
loader = TriggerLoader()
|
||||
triggers = loader.selected_triggers(configuration) + loader.known_triggers(configuration)
|
||||
triggers = itertools.chain(loader.selected_triggers(configuration), loader.known_triggers(configuration))
|
||||
|
||||
for trigger in set(triggers):
|
||||
try:
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import argparse
|
||||
import itertools
|
||||
import re
|
||||
import sys
|
||||
|
||||
@@ -99,7 +100,7 @@ class Versions(Handler):
|
||||
keys.extend(portion)
|
||||
portion = {
|
||||
key
|
||||
for key in sum((list(dependencies_by_key(key)) for key in portion), start=[])
|
||||
for key in itertools.chain.from_iterable(dependencies_by_key(key) for key in portion)
|
||||
if key not in keys
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class _Context:
|
||||
iterate over keys in local storage
|
||||
|
||||
Returns:
|
||||
str: context key iterator
|
||||
Iterator[str]: context key iterator
|
||||
"""
|
||||
return iter(self._content)
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class Configuration(configparser.RawConfigParser):
|
||||
repository identifier
|
||||
|
||||
Returns:
|
||||
RepositoryId: repository unique identifier
|
||||
RepositoryId | None: repository unique identifier
|
||||
"""
|
||||
return self._repository_id
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class Migrations(LazyLogging):
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
MigrationResult: current schema version
|
||||
MigrationResult: schema versions before and after migration
|
||||
"""
|
||||
return Migrations(connection, configuration).run()
|
||||
|
||||
@@ -144,8 +144,8 @@ class Migrations(LazyLogging):
|
||||
"""
|
||||
perform migrations
|
||||
|
||||
Return:
|
||||
MigrationResult: current schema version
|
||||
Returns:
|
||||
MigrationResult: schema versions before and after migration
|
||||
"""
|
||||
migrations = self.migrations()
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class BuildOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str | None): optional filter by package base
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -57,9 +57,9 @@ class BuildOperations(Operations):
|
||||
retrieve packages from build queue
|
||||
|
||||
Args:
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Return:
|
||||
Returns:
|
||||
list[Package]: list of packages to be built
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
@@ -81,7 +81,7 @@ class BuildOperations(Operations):
|
||||
|
||||
Args:
|
||||
package(Package): package to be inserted
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class ChangesOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str): package base to search
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Returns:
|
||||
Changes: changes for the package base if available
|
||||
@@ -69,7 +69,7 @@ class ChangesOperations(Operations):
|
||||
Args:
|
||||
package_base(str): package base to insert
|
||||
changes(Changes): package changes (as in patch format)
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -101,7 +101,7 @@ class ChangesOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str | None): optional filter by package base
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@ class DependenciesOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str | None): package base to search
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Returns:
|
||||
Dependencies: dependencies for the package base if available
|
||||
dict[str, Dependencies]: dependencies keyed by package base, optionally filtered by package base
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -69,7 +69,7 @@ class DependenciesOperations(Operations):
|
||||
Args:
|
||||
package_base(str): package base
|
||||
dependencies(Dependencies): package dependencies
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -97,7 +97,7 @@ class DependenciesOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str | None): optional filter by package base
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class EventOperations(Operations):
|
||||
to_date(int | float | None, optional): maximal creation date, exclusive (Default value = None)
|
||||
limit(int, optional): limit records to the specified count, -1 means unlimited (Default value = -1)
|
||||
offset(int, optional): records offset (Default value = 0)
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Returns:
|
||||
list[Event]: list of audit log events
|
||||
@@ -84,7 +84,7 @@ class EventOperations(Operations):
|
||||
|
||||
Args:
|
||||
event(Event): event to insert
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -106,3 +106,33 @@ class EventOperations(Operations):
|
||||
})
|
||||
|
||||
return self.with_connection(run, commit=True)
|
||||
|
||||
def events_rotate(self, keep_last_records: int, repository_id: RepositoryId | None = None) -> None:
|
||||
"""
|
||||
rotate events in storage, keeping only the last N records for each object
|
||||
|
||||
Args:
|
||||
keep_last_records(int): number of last records to keep
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
def run(connection: Connection) -> None:
|
||||
connection.execute(
|
||||
"""
|
||||
delete from auditlog
|
||||
where rowid in (
|
||||
select rowid from (
|
||||
select rowid, row_number() over (
|
||||
partition by object_id order by created desc, rowid desc
|
||||
) as rn
|
||||
from auditlog
|
||||
where repository = :repository
|
||||
)
|
||||
where rn > :keep_last_records
|
||||
)
|
||||
""",
|
||||
{"keep_last_records": keep_last_records, "repository": repository_id.id},
|
||||
)
|
||||
|
||||
self.with_connection(run, commit=True)
|
||||
@@ -40,9 +40,9 @@ class LogsOperations(Operations):
|
||||
process_id(str | None, optional): process identifier to filter (Default value = None)
|
||||
limit(int, optional): limit records to the specified count, -1 means unlimited (Default value = -1)
|
||||
offset(int, optional): records offset (Default value = 0)
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Return:
|
||||
Returns:
|
||||
list[LogRecord]: sorted package log records
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
@@ -79,7 +79,7 @@ class LogsOperations(Operations):
|
||||
|
||||
Args:
|
||||
log_record(LogRecord): log record object
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -106,7 +106,7 @@ class LogsOperations(Operations):
|
||||
Args:
|
||||
package_base(str): package base to remove logs
|
||||
version(str | None): package version. If set it will remove only logs belonging to another version
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -133,7 +133,7 @@ class LogsOperations(Operations):
|
||||
|
||||
Args:
|
||||
keep_last_records(int): number of last records to keep
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class Operations(LazyLogging):
|
||||
dictionary factory based on official documentation
|
||||
|
||||
Args:
|
||||
cursor(Cursor): cursor descriptor
|
||||
cursor(sqlite3.Cursor): cursor descriptor
|
||||
row(tuple[Any, ...]): fetched row
|
||||
|
||||
Returns:
|
||||
@@ -82,7 +82,7 @@ class Operations(LazyLogging):
|
||||
perform operation in connection
|
||||
|
||||
Args:
|
||||
query(Callable[[Connection], T]): function to be called with connection
|
||||
query(Callable[[sqlite3.Connection], T]): function to be called with connection
|
||||
commit(bool, optional): if ``True`` commit() will be called on success (Default value = False)
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -225,7 +225,7 @@ class PackageOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str): package base name
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
enabled(bool): new hold status
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
@@ -248,7 +248,7 @@ class PackageOperations(Operations):
|
||||
|
||||
Args:
|
||||
package_base(str): package base name
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -264,7 +264,7 @@ class PackageOperations(Operations):
|
||||
|
||||
Args:
|
||||
package(Package): package properties
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
@@ -280,9 +280,9 @@ class PackageOperations(Operations):
|
||||
get package list and their build statuses from database
|
||||
|
||||
Args:
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Return:
|
||||
Returns:
|
||||
list[tuple[Package, BuildStatus]]: list of package properties and their statuses
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
@@ -303,7 +303,7 @@ class PackageOperations(Operations):
|
||||
Args:
|
||||
package_base(str): package base name
|
||||
status(BuildStatus): new build status
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
"""
|
||||
repository_id = repository_id or self._repository_id
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class SQLite(
|
||||
|
||||
Args:
|
||||
package_base(str): package base to remove
|
||||
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None)
|
||||
repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
|
||||
|
||||
Examples:
|
||||
This method completely removes the package from all tables and must be used, e.g. on package removal::
|
||||
|
||||
@@ -254,7 +254,7 @@ class PasswordError(ValueError):
|
||||
def __init__(self, details: Any) -> None:
|
||||
"""
|
||||
Args:
|
||||
details(Any); error details
|
||||
details(Any): error details
|
||||
"""
|
||||
ValueError.__init__(self, f"Password error: {details}")
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class RepositoryStatsPrinter(StringPrinter):
|
||||
def __init__(self, repository_id: RepositoryId, statistics: RepositoryStats) -> None:
|
||||
"""
|
||||
Args:
|
||||
repository_id(RepositoryId): repository unique identifier
|
||||
statistics(RepositoryStats): repository statistics
|
||||
"""
|
||||
StringPrinter.__init__(self, str(repository_id))
|
||||
|
||||
@@ -90,6 +90,9 @@ class UpdatePrinter(StringPrinter):
|
||||
"""
|
||||
generate version property
|
||||
|
||||
Args:
|
||||
package(Package): package whose current and updated versions are shown
|
||||
|
||||
Returns:
|
||||
tuple[str, str]: extract current and updated versions for the package
|
||||
"""
|
||||
|
||||
@@ -18,4 +18,5 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from ahriman.core.housekeeping.archive_rotation_trigger import ArchiveRotationTrigger
|
||||
from ahriman.core.housekeeping.events_rotation_trigger import EventsRotationTrigger
|
||||
from ahriman.core.housekeeping.logs_rotation_trigger import LogsRotationTrigger
|
||||
@@ -0,0 +1,85 @@
|
||||
#
|
||||
# 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 ahriman.core import context
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.status import Client
|
||||
from ahriman.core.triggers import Trigger
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
class EventsRotationTrigger(Trigger):
|
||||
"""
|
||||
rotate events after build processes
|
||||
|
||||
Attributes:
|
||||
keep_last_records(int): number of last records to keep
|
||||
"""
|
||||
|
||||
CONFIGURATION_SCHEMA = {
|
||||
"events-rotation": {
|
||||
"type": "dict",
|
||||
"schema": {
|
||||
"keep_last_events": {
|
||||
"type": "integer",
|
||||
"required": True,
|
||||
"coerce": "integer",
|
||||
"min": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self, repository_id: RepositoryId, configuration: Configuration) -> None:
|
||||
"""
|
||||
Args:
|
||||
repository_id(RepositoryId): repository unique identifier
|
||||
configuration(Configuration): configuration instance
|
||||
"""
|
||||
Trigger.__init__(self, repository_id, configuration)
|
||||
|
||||
section = next(iter(self.configuration_sections(configuration)))
|
||||
self.keep_last_records = configuration.getint(section, "keep_last_events")
|
||||
|
||||
@classmethod
|
||||
def configuration_sections(cls, configuration: Configuration) -> list[str]:
|
||||
"""
|
||||
extract configuration sections from configuration
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration instance
|
||||
|
||||
Returns:
|
||||
list[str]: read configuration sections belong to this trigger
|
||||
"""
|
||||
return list(cls.CONFIGURATION_SCHEMA.keys())
|
||||
|
||||
def on_result(self, result: Result, packages: list[Package]) -> None:
|
||||
"""
|
||||
run trigger
|
||||
|
||||
Args:
|
||||
result(Result): build result
|
||||
packages(list[Package]): list of all available packages
|
||||
"""
|
||||
ctx = context.get()
|
||||
reporter = ctx.get(Client)
|
||||
reporter.events_rotate(self.keep_last_records)
|
||||
@@ -81,7 +81,7 @@ class SyncHttpClient(LazyLogging):
|
||||
get or create session
|
||||
|
||||
Returns:
|
||||
request.Session: created session object
|
||||
requests.Session: created session object
|
||||
"""
|
||||
session = requests.Session()
|
||||
|
||||
|
||||
@@ -107,10 +107,10 @@ class JinjaTemplate:
|
||||
sort content before rendering
|
||||
|
||||
Args:
|
||||
content(list[dict[str, str]]): content of the template
|
||||
content(list[dict[str, Any]]): content of the template
|
||||
|
||||
Returns:
|
||||
list[dict[str, str]]: sorted content according to comparator defined
|
||||
list[dict[str, Any]]: sorted content according to comparator defined
|
||||
"""
|
||||
comparator: Callable[[dict[str, str]], Comparable] = lambda item: item["filename"]
|
||||
return sorted(content, key=comparator)
|
||||
@@ -122,6 +122,9 @@ class JinjaTemplate:
|
||||
Args:
|
||||
result(Result): build result
|
||||
template_name(Path | str): name of the template or path to it (legacy configuration)
|
||||
|
||||
Returns:
|
||||
str: rendered report
|
||||
"""
|
||||
templates = self.templates[:]
|
||||
if isinstance(template_name, Path):
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import ReportError
|
||||
from ahriman.core.log import LazyLogging
|
||||
|
||||
@@ -82,10 +82,10 @@ class RSS(Report, JinjaTemplate):
|
||||
sort content before rendering
|
||||
|
||||
Args:
|
||||
content(list[dict[str, str]]): content of the template
|
||||
content(list[dict[str, Any]]): content of the template
|
||||
|
||||
Returns:
|
||||
list[dict[str, str]]: sorted content according to comparator defined
|
||||
list[dict[str, Any]]: sorted content according to comparator defined
|
||||
"""
|
||||
comparator: Callable[[dict[str, str]], Comparable] = \
|
||||
lambda item: parsedate_to_datetime(item["build_date"])
|
||||
|
||||
@@ -86,7 +86,7 @@ class RepositoryProperties(EventLogger, LazyLogging):
|
||||
package_base(str): package base to lookup
|
||||
|
||||
Returns:
|
||||
User | None: user found in database if any and empty object otherwise
|
||||
User: user found in database if any and empty user object otherwise
|
||||
"""
|
||||
username = packagers.for_base(package_base)
|
||||
if username is None: # none to search
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# 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 itertools
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
||||
from ahriman.core.build_tools.package_version import PackageVersion
|
||||
@@ -126,7 +128,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
if not dependencies.paths:
|
||||
continue # skip check if no package dependencies found
|
||||
|
||||
required_packages = {dep for dep_packages in dependencies.paths.values() for dep in dep_packages}
|
||||
required_packages = set(itertools.chain.from_iterable(dependencies.paths.values()))
|
||||
filesystem = extract_files(required_packages)
|
||||
|
||||
for path, packages in dependencies.paths.items():
|
||||
|
||||
@@ -103,7 +103,7 @@ class GPG(SyncHttpClient):
|
||||
filepath(Path): path to the file which will be signed
|
||||
|
||||
Returns:
|
||||
str: path to signature file
|
||||
Path: path to signature file
|
||||
"""
|
||||
return filepath.parent / f"{filepath.name}.sig"
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import itertools
|
||||
import uuid
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
from multiprocessing import Process, Queue
|
||||
from multiprocessing import Process, get_context
|
||||
from multiprocessing.queues import Queue
|
||||
from threading import Lock, Thread
|
||||
|
||||
from ahriman.core.log import LazyLogging
|
||||
@@ -57,8 +57,7 @@ class Spawn(Thread, LazyLogging):
|
||||
|
||||
self._lock = Lock()
|
||||
self.active: dict[str, Process] = {}
|
||||
# stupid pylint does not know that it is possible
|
||||
self.queue: Queue[ProcessStatus | None] = Queue() # pylint: disable=unsubscriptable-object
|
||||
self.queue: Queue[ProcessStatus | None] = get_context("spawn").Queue()
|
||||
|
||||
@staticmethod
|
||||
def boolean_action_argument(name: str, value: bool) -> str:
|
||||
@@ -76,7 +75,7 @@ class Spawn(Thread, LazyLogging):
|
||||
|
||||
@staticmethod
|
||||
def process(callback: Callable[[argparse.Namespace, RepositoryId], bool], args: argparse.Namespace,
|
||||
repository_id: RepositoryId, process_id: str, queue: Queue[ProcessStatus | None]) -> None: # pylint: disable=unsubscriptable-object
|
||||
repository_id: RepositoryId, process_id: str, queue: Queue[ProcessStatus | None]) -> None:
|
||||
"""
|
||||
helper to run external process
|
||||
|
||||
@@ -119,7 +118,7 @@ class Spawn(Thread, LazyLogging):
|
||||
continue # skip null values
|
||||
flag = f"--{argument}"
|
||||
if isinstance(value, list):
|
||||
arguments.extend(list(sum(((flag, v) for v in value), ())))
|
||||
arguments.extend(itertools.chain.from_iterable((flag, v) for v in value))
|
||||
elif value:
|
||||
arguments.extend([flag, value])
|
||||
else:
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# pylint: disable=too-many-public-methods
|
||||
from __future__ import annotations
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
@@ -120,6 +118,18 @@ class Client:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def events_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older events from storage
|
||||
|
||||
Args:
|
||||
keep_last_records(int): number of last records to keep
|
||||
|
||||
Raises:
|
||||
NotImplementedError: not implemented method
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def logs_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older logs from storage
|
||||
@@ -164,7 +174,7 @@ class Client:
|
||||
package_base(str): package base to retrieve
|
||||
|
||||
Returns:
|
||||
list[Dependencies]: package implicit dependencies if available
|
||||
Dependencies: package implicit dependencies if available
|
||||
|
||||
Raises:
|
||||
NotImplementedError: not implemented method
|
||||
|
||||
@@ -75,6 +75,15 @@ class LocalClient(Client):
|
||||
"""
|
||||
return self.database.event_get(event, object_id, from_date, to_date, limit, offset, self.repository_id)
|
||||
|
||||
def events_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older events from storage
|
||||
|
||||
Args:
|
||||
keep_last_records(int): number of last records to keep
|
||||
"""
|
||||
self.database.events_rotate(keep_last_records, self.repository_id)
|
||||
|
||||
def logs_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older logs from storage
|
||||
@@ -114,7 +123,7 @@ class LocalClient(Client):
|
||||
package_base(str): package base to retrieve
|
||||
|
||||
Returns:
|
||||
list[Dependencies]: package implicit dependencies if available
|
||||
Dependencies: package implicit dependencies if available
|
||||
"""
|
||||
return self.database.dependencies_get(package_base, self.repository_id).get(package_base, Dependencies())
|
||||
|
||||
|
||||
@@ -90,6 +90,15 @@ class Watcher(LazyLogging):
|
||||
"""
|
||||
return self.client.event_get(event, object_id, from_date, to_date, limit, offset)
|
||||
|
||||
async def events_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older events from storage
|
||||
|
||||
Args:
|
||||
keep_last_records(int): number of last records to keep
|
||||
"""
|
||||
self.client.events_rotate(keep_last_records)
|
||||
|
||||
async def load(self) -> None:
|
||||
"""
|
||||
load packages from local database
|
||||
@@ -151,7 +160,7 @@ class Watcher(LazyLogging):
|
||||
package_base(str): package base to retrieve
|
||||
|
||||
Returns:
|
||||
list[Dependencies]: package implicit dependencies if available
|
||||
Dependencies: package implicit dependencies if available
|
||||
"""
|
||||
return self.client.package_dependencies_get(package_base)
|
||||
|
||||
|
||||
@@ -218,6 +218,18 @@ class WebClient(Client, SyncAhrimanClient):
|
||||
|
||||
return []
|
||||
|
||||
def events_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older events from storage
|
||||
|
||||
Args:
|
||||
keep_last_records(int): number of last records to keep
|
||||
"""
|
||||
query = self.repository_id.query() + [("keep_last_records", str(keep_last_records))]
|
||||
|
||||
with contextlib.suppress(Exception):
|
||||
self.make_request("DELETE", self._events_url(), params=query)
|
||||
|
||||
def logs_rotate(self, keep_last_records: int) -> None:
|
||||
"""
|
||||
remove older logs from storage
|
||||
@@ -269,7 +281,7 @@ class WebClient(Client, SyncAhrimanClient):
|
||||
package_base(str): package base to retrieve
|
||||
|
||||
Returns:
|
||||
list[Dependencies]: package implicit dependencies if available
|
||||
Dependencies: package implicit dependencies if available
|
||||
"""
|
||||
with contextlib.suppress(Exception):
|
||||
response = self.make_request("GET", self._dependencies_url(package_base),
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from functools import partial
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class RemoteService(Upload, HttpUpload):
|
||||
get or create session
|
||||
|
||||
Returns:
|
||||
request.Session: created session object
|
||||
requests.Session: created session object
|
||||
"""
|
||||
return self.client.session
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
|
||||
@@ -101,8 +101,8 @@ def check_output(*args: str, exception: Exception | Callable[[int, list[str], st
|
||||
|
||||
Args:
|
||||
*args(str): command line arguments
|
||||
exception(Exception | Callable[[int, list[str], str, str]] | None, optional): exception which has to be raised
|
||||
instead of default subprocess exception. If callable us is supplied, the
|
||||
exception(Exception | Callable[[int, list[str], str, str], Exception] | None, optional): exception to raise
|
||||
instead of the default subprocess exception. If a callable is supplied, the
|
||||
:exc:`subprocess.CalledProcessError` arguments will be passed (Default value = None)
|
||||
cwd(Path | None, optional): current working directory (Default value = None)
|
||||
input_data(str | None, optional): data which will be written to command stdin (Default value = None)
|
||||
|
||||
@@ -69,11 +69,13 @@ class AURPackage:
|
||||
>>>
|
||||
>>> from ahriman.core.alpm.pacman import Pacman
|
||||
>>> from ahriman.core.configuration import Configuration
|
||||
>>> from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||
>>> from ahriman.models.repository_id import RepositoryId
|
||||
>>>
|
||||
>>> configuration = Configuration()
|
||||
>>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration)
|
||||
>>> metadata = pacman.package_get("pacman")
|
||||
>>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration,
|
||||
>>> refresh_database=PacmanSynchronization.DISABLED)
|
||||
>>> metadata = pacman.package("pacman")
|
||||
>>> package = AURPackage.from_pacman(next(metadata)) # load package from pyalpm wrapper
|
||||
"""
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
|
||||
@@ -125,6 +125,15 @@ class BuildPlan(Iterable[Package]):
|
||||
"""
|
||||
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:
|
||||
"""
|
||||
@@ -173,7 +182,7 @@ class BuildPlan(Iterable[Package]):
|
||||
iterate over selected packages in stable package-base order
|
||||
|
||||
Returns:
|
||||
Package: selected package
|
||||
Iterator[Package]: iterator over selected packages
|
||||
"""
|
||||
return iter(self.packages)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@@ -34,7 +32,7 @@ class FilesystemPackage:
|
||||
Attributes:
|
||||
package_name(str): package name
|
||||
depends(set[str]): list of package dependencies
|
||||
directories(set[Path]): list of directories this package contains
|
||||
directories(list[Path]): list of directories this package contains
|
||||
files(list[Path]): list of files this package contains
|
||||
opt_depends(set[str]): list of package optional dependencies
|
||||
"""
|
||||
@@ -80,7 +78,8 @@ class FilesystemPackage:
|
||||
include_optional(bool): include optional dependencies to check
|
||||
|
||||
Returns:
|
||||
bool: whether this package depends on any other package in the list of packages
|
||||
bool: ``True`` if this package has no dependencies among the supplied packages, ignoring packages
|
||||
that have a required dependency on this package
|
||||
"""
|
||||
return not any(
|
||||
package
|
||||
|
||||
@@ -38,9 +38,9 @@ class MetricsTimer:
|
||||
|
||||
>>> with MetricsTimer() as timer:
|
||||
>>> do_something()
|
||||
>>> print("Time elapsed for first function: %f", timer.elapsed)
|
||||
>>> print(f"Time elapsed for first function: {timer.elapsed:f}")
|
||||
>>> do_something_different()
|
||||
>>> print("Time elapsed for all functions: %f", timer.elapsed)
|
||||
>>> print(f"Time elapsed for all functions: {timer.elapsed:f}")
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@@ -44,8 +42,8 @@ class Package(LazyLogging):
|
||||
Attributes:
|
||||
base(str): package base name
|
||||
packager(str | None): package packager if available
|
||||
packages(dict[str, PackageDescription): map of package names to their properties.
|
||||
Filled only on load from archive
|
||||
packages(dict[str, PackageDescription]): map of package names to their properties.
|
||||
Available properties depend on the source used to load the package
|
||||
remote(RemoteSource): package remote source if applicable
|
||||
version(str): package full version
|
||||
|
||||
@@ -56,7 +54,7 @@ class Package(LazyLogging):
|
||||
|
||||
it will contain every data available in the JSON body. Otherwise, if generate package from local archive::
|
||||
|
||||
>>> package = Package.from_archive(local_path, pacman)
|
||||
>>> package = Package.from_archive(local_path)
|
||||
|
||||
it will probably miss file descriptions (in case if there are multiple packages which belong to the base).
|
||||
|
||||
|
||||
@@ -57,11 +57,13 @@ class PackageDescription:
|
||||
>>> from pathlib import Path
|
||||
>>> from ahriman.core.alpm.pacman import Pacman
|
||||
>>> from ahriman.core.configuration import Configuration
|
||||
>>> from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||
>>> from ahriman.models.repository_id import RepositoryId
|
||||
>>>
|
||||
>>> configuration = Configuration()
|
||||
>>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration)
|
||||
>>> pyalpm_description = next(package for package in pacman.package_get("pacman"))
|
||||
>>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration,
|
||||
>>> refresh_database=PacmanSynchronization.DISABLED)
|
||||
>>> pyalpm_description = next(package for package in pacman.package("pacman"))
|
||||
>>> description = PackageDescription.from_package(
|
||||
>>> pyalpm_description, Path("/var/cache/pacman/pkg/pacman-6.0.1-4-x86_64.pkg.tar.zst"))
|
||||
"""
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -27,7 +27,7 @@ class Packagers:
|
||||
|
||||
Attributes:
|
||||
default(str | None): default packager username if any to be used if no override for the specified base was found
|
||||
overrides: dict[str, str | None]: packager username override for specific package base
|
||||
overrides(dict[str, str | None]): packager username override for specific package base
|
||||
"""
|
||||
|
||||
default: str | None = None
|
||||
|
||||
@@ -109,7 +109,7 @@ class PkgbuildPatch:
|
||||
|
||||
Args:
|
||||
key(str | None): variable key
|
||||
source(str): source value string to parse
|
||||
source(str | list[str]): source string to parse or list to use as is
|
||||
|
||||
Returns:
|
||||
Self: parsed patch object
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class RepositoryStats:
|
||||
construct statistics from list of repository packages
|
||||
|
||||
Args:
|
||||
packages(list[Packages]): list of repository packages
|
||||
packages(list[Package]): list of repository packages
|
||||
|
||||
Returns:
|
||||
Self: constructed statistics object
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# 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 __future__ import annotations
|
||||
import itertools
|
||||
|
||||
from collections.abc import Callable, Iterable
|
||||
from typing import Any, ClassVar, Self
|
||||
@@ -102,7 +102,7 @@ class Result:
|
||||
Returns:
|
||||
list[Package]: list of packages with success result
|
||||
"""
|
||||
return list(self._added.values()) + list(self._updated.values())
|
||||
return list(itertools.chain(self._added.values(), self._updated.values()))
|
||||
|
||||
def add_added(self, package: Package) -> None:
|
||||
"""
|
||||
|
||||
@@ -41,7 +41,7 @@ class ScanPaths:
|
||||
compiled regular expressions
|
||||
|
||||
Returns:
|
||||
list[re.Pattern]: a list of compiled regular expressions
|
||||
list[re.Pattern[str]]: a list of compiled regular expressions
|
||||
"""
|
||||
return [re.compile(path) for path in self.paths]
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
@@ -124,12 +124,12 @@ def test_with_dependencies_split(application: Application, package_ahriman: Pack
|
||||
"""
|
||||
must preserve resolved subpackages during dependency resolution
|
||||
"""
|
||||
def package(base: str, name: str, dependencies: list[str]) -> Package:
|
||||
def package(package_base: str, package_name: str, dependencies: list[str]) -> Package:
|
||||
return Package(
|
||||
base=base,
|
||||
base=package_base,
|
||||
version="1-1",
|
||||
remote=package_ahriman.remote,
|
||||
packages={name: PackageDescription(depends=dependencies)},
|
||||
packages={package_name: PackageDescription(depends=dependencies)},
|
||||
)
|
||||
|
||||
packages = {
|
||||
@@ -161,7 +161,7 @@ def test_with_dependencies_exception(application: Application, package_ahriman:
|
||||
"""
|
||||
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 = []
|
||||
@@ -171,26 +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")
|
||||
|
||||
plan = BuildPlan()
|
||||
plan.add(package_ahriman, BuildPlanReason.REGULAR_UPDATE)
|
||||
assert application.with_dependencies(plan, process_dependencies=True) is plan
|
||||
assert plan.packages == [package_ahriman]
|
||||
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:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -8,8 +8,8 @@ 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.package import Package
|
||||
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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ def pacman_database(configuration: Configuration, pacman: Pacman) -> PacmanDatab
|
||||
pacman(Pacman): pacman test instance
|
||||
|
||||
Returns:
|
||||
DatabaseSync: database sync test instance
|
||||
PacmanDatabase: pacman database test instance
|
||||
"""
|
||||
database = next(iter(pacman.handle.get_syncdbs()))
|
||||
return PacmanDatabase(database, 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()
|
||||
|
||||
|
||||
|
||||
@@ -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:
|
||||
@@ -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=[
|
||||
|
||||
@@ -38,3 +38,35 @@ def test_event_insert_get_pagination(database: SQLite) -> None:
|
||||
database.event_insert(Event("1", "1"))
|
||||
database.event_insert(Event("2", "2"))
|
||||
assert all(event.event == "1" for event in database.event_get(limit=1, offset=1))
|
||||
|
||||
|
||||
def test_events_rotate(database: SQLite) -> None:
|
||||
"""
|
||||
must keep last events for each object in repository
|
||||
"""
|
||||
repository_id = RepositoryId("i686", database._repository_id.name)
|
||||
events = [
|
||||
Event("event 1", "object 1", created=1),
|
||||
Event("event 2", "object 1", created=2),
|
||||
Event("event 3", "object 2", created=3),
|
||||
Event("event 4", "object 2", created=4),
|
||||
]
|
||||
for event in events[:2]:
|
||||
database.event_insert(event)
|
||||
for event in events[2:]:
|
||||
database.event_insert(event, repository_id)
|
||||
|
||||
database.events_rotate(1)
|
||||
assert database.event_get() == [events[1]]
|
||||
assert database.event_get(repository_id=repository_id) == events[2:]
|
||||
|
||||
|
||||
def test_events_rotate_remove_all(database: SQLite) -> None:
|
||||
"""
|
||||
must remove all events when keeping zero records
|
||||
"""
|
||||
database.event_insert(Event("event 1", "object 1"))
|
||||
database.event_insert(Event("event 2", "object 2"))
|
||||
|
||||
database.events_rotate(0)
|
||||
assert database.event_get() == []
|
||||
@@ -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
|
||||
"""
|
||||
|
||||
@@ -69,7 +69,7 @@ def test_properties() -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
"""
|
||||
assert Printer().properties() == []
|
||||
assert not Printer().properties()
|
||||
|
||||
|
||||
def test_title() -> None:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.housekeeping import ArchiveRotationTrigger, LogsRotationTrigger
|
||||
from ahriman.core.housekeeping import ArchiveRotationTrigger, EventsRotationTrigger, LogsRotationTrigger
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -19,6 +19,22 @@ def archive_rotation_trigger(configuration: Configuration) -> ArchiveRotationTri
|
||||
return ArchiveRotationTrigger(repository_id, configuration)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def events_rotation_trigger(configuration: Configuration) -> EventsRotationTrigger:
|
||||
"""
|
||||
events rotation trigger fixture
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration fixture
|
||||
|
||||
Returns:
|
||||
EventsRotationTrigger: events rotation trigger test instance
|
||||
"""
|
||||
configuration.set_option("events-rotation", "keep_last_events", "1000")
|
||||
_, repository_id = configuration.check_loaded()
|
||||
return EventsRotationTrigger(repository_id, configuration)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logs_rotation_trigger(configuration: Configuration) -> LogsRotationTrigger:
|
||||
"""
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.housekeeping import EventsRotationTrigger
|
||||
from ahriman.core.status import Client
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
def test_configuration_sections(configuration: Configuration) -> None:
|
||||
"""
|
||||
must correctly parse target list
|
||||
"""
|
||||
assert EventsRotationTrigger.configuration_sections(configuration) == ["events-rotation"]
|
||||
|
||||
|
||||
def test_on_result(events_rotation_trigger: EventsRotationTrigger, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate events
|
||||
"""
|
||||
client_mock = MagicMock()
|
||||
context_mock = mocker.patch("ahriman.core._Context.get", return_value=client_mock)
|
||||
|
||||
events_rotation_trigger.on_result(Result(), [])
|
||||
context_mock.assert_called_once_with(Client)
|
||||
client_mock.events_rotate.assert_called_once_with(events_rotation_trigger.keep_last_records)
|
||||
@@ -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:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import smtplib
|
||||
|
||||
import pytest
|
||||
import smtplib
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
@@ -120,6 +120,14 @@ def test_event_get(client: Client) -> None:
|
||||
client.event_get(None, None)
|
||||
|
||||
|
||||
def test_events_rotate(client: Client) -> None:
|
||||
"""
|
||||
must raise not implemented on events rotation call
|
||||
"""
|
||||
with pytest.raises(NotImplementedError):
|
||||
client.events_rotate(1)
|
||||
|
||||
|
||||
def test_logs_rotate(client: Client) -> None:
|
||||
"""
|
||||
must do not raise exception on logs rotation call
|
||||
|
||||
@@ -78,7 +78,7 @@ async def test_shutdown_queue_full(event_bus: EventBus, package_ahriman: Package
|
||||
must handle shutdown when queue is full
|
||||
"""
|
||||
event_bus.max_size = 1
|
||||
_, queue = await event_bus.subscribe()
|
||||
await event_bus.subscribe()
|
||||
|
||||
await event_bus.broadcast(EventType.PACKAGE_UPDATED, package_ahriman.base)
|
||||
await event_bus.shutdown()
|
||||
|
||||
@@ -35,6 +35,15 @@ def test_event_get(local_client: LocalClient, package_ahriman: Package, mocker:
|
||||
local_client.repository_id)
|
||||
|
||||
|
||||
def test_events_rotate(local_client: LocalClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate events
|
||||
"""
|
||||
rotate_mock = mocker.patch("ahriman.core.database.SQLite.events_rotate")
|
||||
local_client.events_rotate(42)
|
||||
rotate_mock.assert_called_once_with(42, local_client.repository_id)
|
||||
|
||||
|
||||
def test_logs_rotate(local_client: LocalClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate logs
|
||||
|
||||
@@ -64,6 +64,15 @@ async def test_load_known(watcher: Watcher, package_ahriman: Package, mocker: Mo
|
||||
assert status.status == BuildStatusEnum.SUCCESS
|
||||
|
||||
|
||||
async def test_events_rotate(watcher: Watcher, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate events
|
||||
"""
|
||||
cache_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.events_rotate")
|
||||
await watcher.events_rotate(42)
|
||||
cache_mock.assert_called_once_with(42)
|
||||
|
||||
|
||||
async def test_logs_rotate(watcher: Watcher, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate logs
|
||||
|
||||
@@ -307,6 +307,37 @@ def test_event_get_failed_http_error_suppress(web_client: WebClient, mocker: Moc
|
||||
logging_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_events_rotate(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate events
|
||||
"""
|
||||
requests_mock = mocker.patch("ahriman.core.status.web_client.WebClient.make_request")
|
||||
|
||||
web_client.events_rotate(42)
|
||||
requests_mock.assert_called_once_with("DELETE", pytest.helpers.anyvar(str, True),
|
||||
params=web_client.repository_id.query() + [("keep_last_records", "42")])
|
||||
|
||||
|
||||
def test_events_rotate_failed(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must suppress any exception happened during events rotation
|
||||
"""
|
||||
mocker.patch("requests.Session.request", side_effect=Exception)
|
||||
web_client.events_rotate(42)
|
||||
|
||||
|
||||
def test_events_rotate_failed_suppress(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must suppress any exception happened during events rotation and don't log
|
||||
"""
|
||||
web_client.suppress_errors = True
|
||||
mocker.patch("requests.Session.request", side_effect=Exception)
|
||||
logging_mock = mocker.patch("logging.exception")
|
||||
|
||||
web_client.events_rotate(42)
|
||||
logging_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_logs_rotate(web_client: WebClient, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must rotate logs
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import ahriman.web.views
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import ahriman.web.views
|
||||
|
||||
from ahriman.core.module_loader import _modules, implementations, optional_module
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ from unittest.mock import MagicMock, call as MockCall
|
||||
from ahriman.core.exceptions import BuildError, CalledProcessError, OptionError, UnsafeRunError
|
||||
from ahriman.core.utils import *
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_configuration_schema_no_section(configuration: Configuration) -> None:
|
||||
"""
|
||||
section = "abracadabra"
|
||||
configuration.set_option("report", "target", section)
|
||||
assert ReportTrigger.configuration_schema(configuration) == {}
|
||||
assert not ReportTrigger.configuration_schema(configuration)
|
||||
|
||||
|
||||
def test_configuration_schema_no_schema(configuration: Configuration) -> None:
|
||||
@@ -55,7 +55,7 @@ def test_configuration_schema_no_schema(configuration: Configuration) -> None:
|
||||
configuration.set_option("report", "target", section)
|
||||
configuration.set_option(section, "key", "value")
|
||||
|
||||
assert ReportTrigger.configuration_schema(configuration) == {}
|
||||
assert not ReportTrigger.configuration_schema(configuration)
|
||||
|
||||
|
||||
def test_configuration_schema_empty() -> None:
|
||||
@@ -69,14 +69,14 @@ def test_configuration_schema_variables() -> None:
|
||||
"""
|
||||
must return empty schema
|
||||
"""
|
||||
assert Trigger.CONFIGURATION_SCHEMA == {}
|
||||
assert not Trigger.CONFIGURATION_SCHEMA
|
||||
|
||||
|
||||
def test_configuration_sections(configuration: Configuration) -> None:
|
||||
"""
|
||||
must return empty section list
|
||||
"""
|
||||
assert Trigger.configuration_sections(configuration) == []
|
||||
assert not Trigger.configuration_sections(configuration)
|
||||
|
||||
|
||||
def test_on_result(trigger: Trigger) -> None:
|
||||
|
||||
@@ -33,4 +33,4 @@ def test_get_hashes_empty() -> None:
|
||||
"""
|
||||
must read empty body
|
||||
"""
|
||||
assert HttpUpload.get_hashes("") == {}
|
||||
assert not HttpUpload.get_hashes("")
|
||||
@@ -8,7 +8,7 @@ from ahriman.core.upload.s3 import S3
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
|
||||
|
||||
_chunk_size = 8 * 1024 * 1024
|
||||
_CHUNK_SIZE = 8 * 1024 * 1024
|
||||
|
||||
|
||||
def test_object_path(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@@ -34,7 +34,7 @@ def test_calculate_etag_big(resource_path_root: Path) -> None:
|
||||
must calculate checksum for path which is more than one chunk
|
||||
"""
|
||||
path = resource_path_root / "models" / "big_file_checksum"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "3b15154eaeed22ae19ae4667d4b98d28-2"
|
||||
assert S3.calculate_etag(path, _CHUNK_SIZE) == "3b15154eaeed22ae19ae4667d4b98d28-2"
|
||||
|
||||
|
||||
def test_calculate_etag_empty(resource_path_root: Path) -> None:
|
||||
@@ -42,7 +42,7 @@ def test_calculate_etag_empty(resource_path_root: Path) -> None:
|
||||
must calculate checksum for empty file correctly
|
||||
"""
|
||||
path = resource_path_root / "models" / "empty_file_checksum"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "d41d8cd98f00b204e9800998ecf8427e"
|
||||
assert S3.calculate_etag(path, _CHUNK_SIZE) == "d41d8cd98f00b204e9800998ecf8427e"
|
||||
|
||||
|
||||
def test_calculate_etag_small(resource_path_root: Path) -> None:
|
||||
@@ -50,7 +50,7 @@ def test_calculate_etag_small(resource_path_root: Path) -> None:
|
||||
must calculate checksum for path which is single chunk
|
||||
"""
|
||||
path = resource_path_root / "models" / "package_ahriman_pkgbuild"
|
||||
assert S3.calculate_etag(path, _chunk_size) == "7136fc388980dc043f9f869d57c5ce0c"
|
||||
assert S3.calculate_etag(path, _CHUNK_SIZE) == "7136fc388980dc043f9f869d57c5ce0c"
|
||||
|
||||
|
||||
def test_files_remove(s3_remote_objects: list[Any]) -> None:
|
||||
@@ -78,7 +78,6 @@ def test_files_upload(s3: S3, s3_remote_objects: list[Any], mocker: MockerFixtur
|
||||
Path(item.key[:-1] + item.key[-1].replace("a", "d")): item.e_tag.replace("b", "d").replace("\"", "")
|
||||
for item in s3_remote_objects
|
||||
}
|
||||
print(local_files)
|
||||
remote_objects = {Path(item.key): item for item in s3_remote_objects}
|
||||
|
||||
mocker.patch("mimetypes.guess_type", side_effect=mimetype)
|
||||
|
||||
@@ -27,6 +27,20 @@ def test_add_preserves_first_reason(package_ahriman: Package) -> None:
|
||||
assert plan.item(package_ahriman.base) == BuildPlanItem(updated, BuildPlanReason.REGULAR_UPDATE, "requester1")
|
||||
|
||||
|
||||
def test_remove(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must remove a package while preserving the remaining plan items
|
||||
"""
|
||||
plan = BuildPlan().update([package_ahriman, package_python_schedule], BuildPlanReason.REGULAR_UPDATE)
|
||||
|
||||
plan.remove(package_ahriman.base)
|
||||
assert package_ahriman not in plan
|
||||
assert package_python_schedule in plan
|
||||
|
||||
plan.remove(package_python_schedule.base)
|
||||
assert not plan
|
||||
|
||||
|
||||
def test_update(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must update instance with new packages
|
||||
@@ -40,10 +54,12 @@ def test_eq(package_ahriman: Package) -> None:
|
||||
must compare two plans
|
||||
"""
|
||||
plan1 = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
assert plan1 == plan1
|
||||
|
||||
plan2 = BuildPlan().update([package_ahriman], BuildPlanReason.MANUAL_REQUEST)
|
||||
assert plan1 != plan2
|
||||
plan2 = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
|
||||
assert plan1 == plan2
|
||||
|
||||
plan3 = BuildPlan().update([package_ahriman], BuildPlanReason.MANUAL_REQUEST)
|
||||
assert plan1 != plan3
|
||||
|
||||
|
||||
def test_eq_other() -> None:
|
||||
|
||||
@@ -44,10 +44,12 @@ def test_eq() -> None:
|
||||
must compare two events
|
||||
"""
|
||||
event1 = Event("1", "1", "1", 1, key="value")
|
||||
assert event1 == event1
|
||||
|
||||
event2 = Event("2", "2", "2", 2, key="value")
|
||||
assert event1 != event2
|
||||
event2 = Event("1", "1", "1", 1, key="value")
|
||||
assert event1 == event2
|
||||
|
||||
event3 = Event("2", "2", "2", 2, key="value")
|
||||
assert event1 != event3
|
||||
|
||||
|
||||
def test_eq_other() -> None:
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
# 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 itertools
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
@@ -117,7 +119,7 @@ class KeyringGenerator(PkgbuildGenerator):
|
||||
source_path(Path): destination of the file content
|
||||
"""
|
||||
with source_path.open("w", encoding="utf8") as source_file:
|
||||
for key in sorted(set(self.trusted + self.packagers + self.revoked)):
|
||||
for key in sorted(set(itertools.chain(self.trusted, self.packagers, self.revoked))):
|
||||
public_key = self.sign.key_export(key)
|
||||
source_file.write(public_key)
|
||||
source_file.write("\n")
|
||||
|
||||
@@ -147,7 +147,7 @@ def test_symlinks_fix_foreign_repository(archive_tree: ArchiveTree, mocker: Mock
|
||||
])
|
||||
remove_mock = mocker.patch("ahriman.core.alpm.repo.Repo.remove")
|
||||
|
||||
assert list(archive_tree.symlinks_fix()) == []
|
||||
assert not list(archive_tree.symlinks_fix())
|
||||
remove_mock.assert_not_called()
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def package_creator(configuration: Configuration, mirrorlist_generator: Mirrorli
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration fixture
|
||||
mirrorlist_generator(MirrorlistGenerator):
|
||||
mirrorlist_generator(MirrorlistGenerator): mirrorlist pkgbuild generator fixture
|
||||
|
||||
Returns:
|
||||
PackageCreator: package creator test instance
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
# 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 __future__ import annotations
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.database import SQLite
|
||||
from ahriman.core.log import LazyLogging
|
||||
|
||||
@@ -39,8 +39,8 @@ def _response_schema(response: Schema | type[Schema] | None, response_code: type
|
||||
response(Schema | type[Schema] | None): response schema type, set ``None`` for empty responses
|
||||
response_code(type[HTTPException] | None, optional): code for the success response. If none set it will be
|
||||
defined automatically (Default value = None)
|
||||
error_400_enabled(bool, optional): include response for 404 codes (Default value = False)
|
||||
error_403_enabled(bool, optional): include response for 403 codes (Default value = False)
|
||||
error_400_enabled(bool, optional): include response for 400 codes (Default value = False)
|
||||
error_403_enabled(bool, optional): include response for 403 codes (Default value = True)
|
||||
error_404_description(str | None, optional): description for 404 codes if available (Default value = None)
|
||||
|
||||
Returns:
|
||||
@@ -98,7 +98,7 @@ def apidocs(*,
|
||||
permission(UserAccess): permission to access endpoint
|
||||
response_code(type[HTTPException] | None, optional): code for the success response. If none set it will be
|
||||
defined automatically (Default value = None)
|
||||
error_400_enabled(bool, optional): include response for 404 codes (Default value = False)
|
||||
error_400_enabled(bool, optional): include response for 400 codes (Default value = False)
|
||||
error_404_description(str | None, optional): description for 404 codes if available (Default value = None)
|
||||
schema(Schema | type[Schema] | None): response schema type, set ``None`` for empty responses
|
||||
(Default value = None)
|
||||
|
||||
@@ -88,7 +88,7 @@ def _auth_handler(allow_read_only: bool) -> Middleware:
|
||||
authorization and authentication middleware
|
||||
|
||||
Args:
|
||||
allow_read_only: allow
|
||||
allow_read_only(bool): allow read-only requests without authentication
|
||||
|
||||
Returns:
|
||||
Middleware: built middleware
|
||||
|
||||
@@ -31,6 +31,7 @@ from ahriman.web.schemas.error_schema import ErrorSchema
|
||||
from ahriman.web.schemas.event_bus_filter_schema import EventBusFilterSchema
|
||||
from ahriman.web.schemas.event_schema import EventSchema
|
||||
from ahriman.web.schemas.event_search_schema import EventSearchSchema
|
||||
from ahriman.web.schemas.events_rotate_schema import EventsRotateSchema
|
||||
from ahriman.web.schemas.file_schema import FileSchema
|
||||
from ahriman.web.schemas.hold_schema import HoldSchema
|
||||
from ahriman.web.schemas.info_schema import InfoSchema
|
||||
|
||||
Loaded 100 of 134 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user