mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
use repostory id instead
This commit is contained in:
parent
1b5bfe5088
commit
e514740032
8
.github/workflows/setup.sh
vendored
8
.github/workflows/setup.sh
vendored
@ -38,13 +38,13 @@ systemd-machine-id-setup
|
||||
[[ -z $MINIMAL_INSTALL ]] && WEB_ARGS=("--web-port" "8080")
|
||||
ahriman -a x86_64 -r "github" service-setup --packager "ahriman bot <ahriman@example.com>" "${WEB_ARGS[@]}"
|
||||
# validate configuration
|
||||
ahriman -a x86_64 -r "github" service-config-validate --exit-code
|
||||
ahriman service-config-validate --exit-code
|
||||
# enable services
|
||||
systemctl enable ahriman-web@x86_64
|
||||
systemctl enable ahriman@x86_64.timer
|
||||
systemctl enable ahriman-web@x86_64-github
|
||||
systemctl enable ahriman@x86_64-github.timer
|
||||
if [[ -z $MINIMAL_INSTALL ]]; then
|
||||
# run web service (detached)
|
||||
sudo -u ahriman -- ahriman -a x86_64 web &
|
||||
sudo -u ahriman -- ahriman web &
|
||||
WEB_PID=$!
|
||||
fi
|
||||
# add the first package
|
||||
|
@ -36,10 +36,10 @@ ahriman.core.log.lazy\_logging module
|
||||
:no-undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
ahriman.core.log.log module
|
||||
---------------------------
|
||||
ahriman.core.log.log\_loader module
|
||||
-----------------------------------
|
||||
|
||||
.. automodule:: ahriman.core.log.log
|
||||
.. automodule:: ahriman.core.log.log_loader
|
||||
:members:
|
||||
:no-undoc-members:
|
||||
:show-inheritance:
|
||||
|
@ -51,9 +51,6 @@ steps = [
|
||||
alter table build_queue add column repository text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table build_queue add column architecture text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table build_queue rename to build_queue_
|
||||
""",
|
||||
"""
|
||||
@ -61,8 +58,7 @@ steps = [
|
||||
package_base text not null,
|
||||
properties json not null,
|
||||
repository text not null,
|
||||
architecture text not null,
|
||||
unique (package_base, architecture, repository)
|
||||
unique (package_base, repository)
|
||||
)
|
||||
""",
|
||||
"""
|
||||
@ -76,9 +72,6 @@ steps = [
|
||||
alter table package_bases add column repository text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table package_bases add column architecture text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table package_bases rename to package_bases_
|
||||
""",
|
||||
"""
|
||||
@ -92,8 +85,7 @@ steps = [
|
||||
source text,
|
||||
packager text,
|
||||
repository text not null,
|
||||
architecture text not null,
|
||||
unique (package_base, architecture, repository)
|
||||
unique (package_base, repository)
|
||||
)
|
||||
""",
|
||||
"""
|
||||
@ -107,9 +99,6 @@ steps = [
|
||||
alter table package_statuses add column repository text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table package_statuses add column architecture text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table package_statuses rename to package_statuses_
|
||||
""",
|
||||
"""
|
||||
@ -118,8 +107,7 @@ steps = [
|
||||
status text not null,
|
||||
last_updated integer,
|
||||
repository text not null,
|
||||
architecture text not null,
|
||||
unique (package_base, architecture, repository)
|
||||
unique (package_base, repository)
|
||||
)
|
||||
""",
|
||||
"""
|
||||
@ -168,9 +156,6 @@ steps = [
|
||||
alter table logs add column repository text not null default ''
|
||||
""",
|
||||
"""
|
||||
alter table logs add column architecture text not null default ''
|
||||
""",
|
||||
"""
|
||||
drop index logs_package_base_version
|
||||
""",
|
||||
"""
|
||||
@ -182,16 +167,15 @@ steps = [
|
||||
created real not null,
|
||||
record text,
|
||||
version text not null,
|
||||
repository text not null,
|
||||
architecture text not null
|
||||
repository text not null
|
||||
)
|
||||
""",
|
||||
"""
|
||||
insert into logs select * from logs_
|
||||
""",
|
||||
"""
|
||||
create index logs_package_base_version_architecture_repository
|
||||
on logs (package_base, version, architecture, repository)
|
||||
create index logs_package_base_version_repository
|
||||
on logs (package_base, version, repository)
|
||||
""",
|
||||
"""
|
||||
drop table logs_
|
||||
@ -220,13 +204,8 @@ def migrate_package_repository(connection: Connection, configuration: Configurat
|
||||
"""
|
||||
_, repository_id = configuration.check_loaded()
|
||||
|
||||
connection.execute("""update build_queue set repository = :repository, architecture = :architecture""",
|
||||
{"repository": repository_id.name, "architecture": repository_id.architecture})
|
||||
connection.execute("""update package_bases set repository = :repository, architecture = :architecture""",
|
||||
{"repository": repository_id.name, "architecture": repository_id.architecture})
|
||||
connection.execute("""update package_statuses set repository = :repository, architecture = :architecture""",
|
||||
{"repository": repository_id.name, "architecture": repository_id.architecture})
|
||||
connection.execute("""update packages set repository = :repository""",
|
||||
{"repository": repository_id.name})
|
||||
connection.execute("""update logs set repository = :repository, architecture = :architecture""",
|
||||
{"repository": repository_id.name, "architecture": repository_id.architecture})
|
||||
connection.execute("""update build_queue set repository = :repository""", {"repository": repository_id.id})
|
||||
connection.execute("""update package_bases set repository = :repository""", {"repository": repository_id.id})
|
||||
connection.execute("""update package_statuses set repository = :repository""", {"repository": repository_id.id})
|
||||
connection.execute("""update packages set repository = :repository""", {"repository": repository_id.id})
|
||||
connection.execute("""update logs set repository = :repository""", {"repository": repository_id.id})
|
||||
|
@ -39,13 +39,11 @@ class BuildOperations(Operations):
|
||||
connection.execute(
|
||||
"""
|
||||
delete from build_queue
|
||||
where (:package_base is null or package_base = :package_base)
|
||||
and repository = :repository and architecture = :architecture
|
||||
where (:package_base is null or package_base = :package_base) and repository = :repository
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
})
|
||||
|
||||
return self.with_connection(run, commit=True)
|
||||
@ -61,11 +59,8 @@ class BuildOperations(Operations):
|
||||
return [
|
||||
Package.from_json(row["properties"])
|
||||
for row in connection.execute(
|
||||
"""
|
||||
select properties from build_queue
|
||||
where repository = :repository and architecture = :architecture
|
||||
""",
|
||||
{"repository": self.repository_id.name, "architecture": self.repository_id.architecture}
|
||||
"""select properties from build_queue where repository = :repository""",
|
||||
{"repository": self.repository_id.id}
|
||||
)
|
||||
]
|
||||
|
||||
@ -82,17 +77,16 @@ class BuildOperations(Operations):
|
||||
connection.execute(
|
||||
"""
|
||||
insert into build_queue
|
||||
(package_base, properties, repository, architecture)
|
||||
(package_base, properties, repository)
|
||||
values
|
||||
(:package_base, :properties, :repository, :architecture)
|
||||
on conflict (package_base, architecture, repository) do update set
|
||||
(:package_base, :properties, :repository)
|
||||
on conflict (package_base, repository) do update set
|
||||
properties = :properties
|
||||
""",
|
||||
{
|
||||
"package_base": package.base,
|
||||
"properties": package.view(),
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
})
|
||||
|
||||
return self.with_connection(run, commit=True)
|
||||
|
@ -46,13 +46,12 @@ class LogsOperations(Operations):
|
||||
for row in connection.execute(
|
||||
"""
|
||||
select created, record from logs
|
||||
where package_base = :package_base and repository = :repository and architecture = :architecture
|
||||
where package_base = :package_base and repository = :repository
|
||||
order by created limit :limit offset :offset
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
})
|
||||
@ -73,17 +72,16 @@ class LogsOperations(Operations):
|
||||
connection.execute(
|
||||
"""
|
||||
insert into logs
|
||||
(package_base, version, created, record, repository, architecture)
|
||||
(package_base, version, created, record, repository)
|
||||
values
|
||||
(:package_base, :version, :created, :record, :repository, :architecture)
|
||||
(:package_base, :version, :created, :record, :repository)
|
||||
""",
|
||||
{
|
||||
"package_base": log_record_id.package_base,
|
||||
"version": log_record_id.version,
|
||||
"created": created,
|
||||
"record": record,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
@ -102,14 +100,14 @@ class LogsOperations(Operations):
|
||||
connection.execute(
|
||||
"""
|
||||
delete from logs
|
||||
where package_base = :package_base and repository = :repository and architecture = :architecture
|
||||
where package_base = :package_base
|
||||
and repository = :repository
|
||||
and (:version is null or version <> :version)
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"version": version,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -41,25 +41,11 @@ class PackageOperations(Operations):
|
||||
package_base(str): package base name
|
||||
"""
|
||||
connection.execute(
|
||||
"""
|
||||
delete from package_statuses
|
||||
where package_base = :package_base and repository = :repository and architecture = :architecture
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
})
|
||||
"""delete from package_statuses where package_base = :package_base and repository = :repository""",
|
||||
{"package_base": package_base, "repository": self.repository_id.id})
|
||||
connection.execute(
|
||||
"""
|
||||
delete from package_bases
|
||||
where package_base = :package_base and repository = :repository and architecture = :architecture
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
})
|
||||
"""delete from package_bases where package_base = :package_base and repository = :repository""",
|
||||
{"package_base": package_base, "repository": self.repository_id.id})
|
||||
|
||||
def _package_remove_packages(self, connection: Connection, package_base: str,
|
||||
current_packages: Iterable[str]) -> None:
|
||||
@ -75,20 +61,13 @@ class PackageOperations(Operations):
|
||||
package
|
||||
for package in connection.execute(
|
||||
"""
|
||||
select package, repository, architecture from packages
|
||||
where package_base = :package_base and repository = :repository and architecture = :architecture""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
})
|
||||
select package, repository from packages
|
||||
where package_base = :package_base and repository = :repository""",
|
||||
{"package_base": package_base, "repository": self.repository_id.id})
|
||||
if package["package"] not in current_packages
|
||||
]
|
||||
connection.executemany(
|
||||
"""
|
||||
delete from packages
|
||||
where package = :package and repository = :repository and architecture = :architecture
|
||||
""",
|
||||
"""delete from packages where package = :package and repository = :repository""",
|
||||
packages)
|
||||
|
||||
def _package_update_insert_base(self, connection: Connection, package: Package) -> None:
|
||||
@ -102,12 +81,10 @@ class PackageOperations(Operations):
|
||||
connection.execute(
|
||||
"""
|
||||
insert into package_bases
|
||||
(package_base, version, source, branch, git_url, path, web_url, packager,
|
||||
repository, architecture)
|
||||
(package_base, version, source, branch, git_url, path, web_url, packager, repository)
|
||||
values
|
||||
(:package_base, :version, :source, :branch, :git_url, :path, :web_url, :packager,
|
||||
:repository, :architecture)
|
||||
on conflict (package_base, architecture, repository) do update set
|
||||
(:package_base, :version, :source, :branch, :git_url, :path, :web_url, :packager, :repository)
|
||||
on conflict (package_base, repository) do update set
|
||||
version = :version, branch = :branch, git_url = :git_url, path = :path, web_url = :web_url,
|
||||
source = :source, packager = :packager
|
||||
""",
|
||||
@ -120,8 +97,7 @@ class PackageOperations(Operations):
|
||||
"web_url": package.remote.web_url,
|
||||
"source": package.remote.source.value,
|
||||
"packager": package.packager,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
@ -140,7 +116,7 @@ class PackageOperations(Operations):
|
||||
package_list.append({
|
||||
"package": name,
|
||||
"package_base": package.base,
|
||||
"repository": self.repository_id.name,
|
||||
"repository": self.repository_id.id,
|
||||
**description.view(),
|
||||
})
|
||||
connection.executemany(
|
||||
@ -177,18 +153,17 @@ class PackageOperations(Operations):
|
||||
connection.execute(
|
||||
"""
|
||||
insert into package_statuses
|
||||
(package_base, status, last_updated, repository, architecture)
|
||||
(package_base, status, last_updated, repository)
|
||||
values
|
||||
(:package_base, :status, :last_updated, :repository, :architecture)
|
||||
on conflict (package_base, architecture, repository) do update set
|
||||
(:package_base, :status, :last_updated, :repository)
|
||||
on conflict (package_base, repository) do update set
|
||||
status = :status, last_updated = :last_updated
|
||||
""",
|
||||
{
|
||||
"package_base": package_base,
|
||||
"status": status.status.value,
|
||||
"last_updated": status.timestamp,
|
||||
"repository": self.repository_id.name,
|
||||
"architecture": self.repository_id.architecture,
|
||||
"repository": self.repository_id.id,
|
||||
})
|
||||
|
||||
def _packages_get_select_package_bases(self, connection: Connection) -> dict[str, Package]:
|
||||
@ -209,8 +184,8 @@ class PackageOperations(Operations):
|
||||
packages={},
|
||||
packager=row["packager"] or None,
|
||||
) for row in connection.execute(
|
||||
"""select * from package_bases where repository = :repository and architecture = :architecture""",
|
||||
{"repository": self.repository_id.name, "architecture": self.repository_id.architecture}
|
||||
"""select * from package_bases where repository = :repository""",
|
||||
{"repository": self.repository_id.id}
|
||||
)
|
||||
}
|
||||
|
||||
@ -226,8 +201,8 @@ class PackageOperations(Operations):
|
||||
dict[str, Package]: map of the package base to its descriptor including individual packages
|
||||
"""
|
||||
for row in connection.execute(
|
||||
"""select * from packages where repository = :repository and architecture = :architecture""",
|
||||
{"repository": self.repository_id.name, "architecture": self.repository_id.architecture}
|
||||
"""select * from packages where repository = :repository""",
|
||||
{"repository": self.repository_id.id}
|
||||
):
|
||||
if row["package_base"] not in packages:
|
||||
continue # normally must never happen though
|
||||
@ -247,8 +222,8 @@ class PackageOperations(Operations):
|
||||
return {
|
||||
row["package_base"]: BuildStatus.from_json({"status": row["status"], "timestamp": row["last_updated"]})
|
||||
for row in connection.execute(
|
||||
"""select * from package_statuses where repository = :repository and architecture = :architecture""",
|
||||
{"repository": self.repository_id.name, "architecture": self.repository_id.architecture}
|
||||
"""select * from package_statuses where repository = :repository""",
|
||||
{"repository": self.repository_id.id}
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,16 @@ class RepositoryId:
|
||||
"""
|
||||
return not self.architecture or not self.name
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
"""
|
||||
get repository id to be used for databases
|
||||
|
||||
Returns:
|
||||
str: unique id for this repository
|
||||
"""
|
||||
return f"{self.architecture}-{self.name}" # basically the same as used for command line
|
||||
|
||||
def __lt__(self, other: Any) -> bool:
|
||||
"""
|
||||
comparison operator for sorting
|
||||
|
@ -31,13 +31,9 @@ def test_migrate_package_repository(connection: Connection, configuration: Confi
|
||||
migrate_package_repository(connection, configuration)
|
||||
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True),
|
||||
{"repository": configuration.repository_name, "architecture": configuration.architecture}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True),
|
||||
{"repository": configuration.repository_name, "architecture": configuration.architecture}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True),
|
||||
{"repository": configuration.repository_name, "architecture": configuration.architecture}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), {"repository": configuration.repository_name}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True),
|
||||
{"repository": configuration.repository_name, "architecture": configuration.architecture}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), {"repository": configuration.repository_id.id}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), {"repository": configuration.repository_id.id}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), {"repository": configuration.repository_id.id}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), {"repository": configuration.repository_id.id}),
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), {"repository": configuration.repository_id.id}),
|
||||
])
|
||||
|
@ -18,8 +18,7 @@ def test_package_remove_package_base(database: SQLite, connection: Connection) -
|
||||
database._package_remove_package_base(connection, "package")
|
||||
args = {
|
||||
"package_base": "package",
|
||||
"repository": database.repository_id.name,
|
||||
"architecture": database.repository_id.architecture,
|
||||
"repository": database.repository_id.id,
|
||||
}
|
||||
connection.execute.assert_has_calls([
|
||||
MockCall(pytest.helpers.anyvar(str, strict=True), args),
|
||||
@ -35,8 +34,7 @@ def test_package_remove_packages(database: SQLite, connection: Connection, packa
|
||||
connection.execute.assert_called_once_with(
|
||||
pytest.helpers.anyvar(str, strict=True), {
|
||||
"package_base": package_ahriman.base,
|
||||
"repository": database.repository_id.name,
|
||||
"architecture": database.repository_id.architecture,
|
||||
"repository": database.repository_id.id,
|
||||
})
|
||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [])
|
||||
|
||||
|
@ -13,6 +13,14 @@ def test_is_empty() -> None:
|
||||
assert not RepositoryId("arch", "repo").is_empty
|
||||
|
||||
|
||||
def test_id() -> None:
|
||||
"""
|
||||
must correctly generate id
|
||||
"""
|
||||
assert RepositoryId("", "").id == "-"
|
||||
assert RepositoryId("arch", "repo").id == "arch-repo"
|
||||
|
||||
|
||||
def test_lt() -> None:
|
||||
"""
|
||||
must correctly compare instances
|
||||
|
Loading…
Reference in New Issue
Block a user