mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-03-13 21:43:38 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d99b61d8c0 | |||
| 34d0b8cf73 | |||
| cc082dbd6f |
@@ -12,14 +12,6 @@ ahriman.application.handlers.add module
|
|||||||
:no-undoc-members:
|
:no-undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
ahriman.application.handlers.archives module
|
|
||||||
--------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: ahriman.application.handlers.archives
|
|
||||||
:members:
|
|
||||||
:no-undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
ahriman.application.handlers.backup module
|
ahriman.application.handlers.backup module
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
|
|
||||||
@@ -100,14 +92,6 @@ ahriman.application.handlers.patch module
|
|||||||
:no-undoc-members:
|
:no-undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
ahriman.application.handlers.pkgbuild module
|
|
||||||
--------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: ahriman.application.handlers.pkgbuild
|
|
||||||
:members:
|
|
||||||
:no-undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
ahriman.application.handlers.rebuild module
|
ahriman.application.handlers.rebuild module
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -28,14 +28,6 @@ ahriman.core.alpm.pacman\_database module
|
|||||||
:no-undoc-members:
|
:no-undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
ahriman.core.alpm.pacman\_handle module
|
|
||||||
---------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: ahriman.core.alpm.pacman_handle
|
|
||||||
:members:
|
|
||||||
:no-undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
ahriman.core.alpm.pkgbuild\_parser module
|
ahriman.core.alpm.pkgbuild\_parser module
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -140,14 +140,6 @@ ahriman.core.database.migrations.m016\_archive module
|
|||||||
:no-undoc-members:
|
:no-undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
ahriman.core.database.migrations.m017\_pkgbuild module
|
|
||||||
------------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: ahriman.core.database.migrations.m017_pkgbuild
|
|
||||||
:members:
|
|
||||||
:no-undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Module contents
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@@ -76,14 +76,6 @@ ahriman.core.formatters.patch\_printer module
|
|||||||
:no-undoc-members:
|
:no-undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
ahriman.core.formatters.pkgbuild\_printer module
|
|
||||||
------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: ahriman.core.formatters.pkgbuild_printer
|
|
||||||
:members:
|
|
||||||
:no-undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
ahriman.core.formatters.printer module
|
ahriman.core.formatters.printer module
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,6 @@ ahriman.web.views.v1.packages package
|
|||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
ahriman.web.views.v1.packages.archives module
|
|
||||||
---------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: ahriman.web.views.v1.packages.archives
|
|
||||||
:members:
|
|
||||||
:no-undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
ahriman.web.views.v1.packages.changes module
|
ahriman.web.views.v1.packages.changes module
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "ahriman-frontend",
|
"name": "ahriman-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.20.0",
|
"version": "2.20.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -17,57 +17,47 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import "components/common/syntaxLanguages";
|
import { Box } from "@mui/material";
|
||||||
|
|
||||||
import { Box, useTheme } from "@mui/material";
|
|
||||||
import CopyButton from "components/common/CopyButton";
|
import CopyButton from "components/common/CopyButton";
|
||||||
import { useThemeMode } from "hooks/useThemeMode";
|
|
||||||
import React, { type RefObject } from "react";
|
import React, { type RefObject } from "react";
|
||||||
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
||||||
import { githubGist, vs2015 } from "react-syntax-highlighter/dist/esm/styles/hljs";
|
|
||||||
|
|
||||||
interface CodeBlockProps {
|
interface CodeBlockProps {
|
||||||
content: string;
|
|
||||||
height?: number | string;
|
|
||||||
language?: string;
|
|
||||||
onScroll?: () => void;
|
|
||||||
preRef?: RefObject<HTMLElement | null>;
|
preRef?: RefObject<HTMLElement | null>;
|
||||||
|
getText: () => string;
|
||||||
|
height?: number | string;
|
||||||
|
onScroll?: () => void;
|
||||||
|
wordBreak?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CodeBlock({
|
export default function CodeBlock({
|
||||||
content,
|
|
||||||
height,
|
|
||||||
language = "text",
|
|
||||||
onScroll,
|
|
||||||
preRef,
|
preRef,
|
||||||
|
getText,
|
||||||
|
height,
|
||||||
|
onScroll,
|
||||||
|
wordBreak,
|
||||||
}: CodeBlockProps): React.JSX.Element {
|
}: CodeBlockProps): React.JSX.Element {
|
||||||
const { mode } = useThemeMode();
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return <Box sx={{ position: "relative" }}>
|
return <Box sx={{ position: "relative" }}>
|
||||||
<Box
|
<Box
|
||||||
ref={preRef}
|
ref={preRef}
|
||||||
|
component="pre"
|
||||||
onScroll={onScroll}
|
onScroll={onScroll}
|
||||||
sx={{ overflow: "auto", height }}
|
sx={{
|
||||||
|
backgroundColor: "action.hover",
|
||||||
|
p: 2,
|
||||||
|
borderRadius: 1,
|
||||||
|
overflow: "auto",
|
||||||
|
height,
|
||||||
|
fontSize: "0.8rem",
|
||||||
|
fontFamily: "monospace",
|
||||||
|
...wordBreak ? { whiteSpace: "pre-wrap", wordBreak: "break-all" } : {},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<SyntaxHighlighter
|
<code>
|
||||||
language={language}
|
{getText()}
|
||||||
style={mode === "dark" ? vs2015 : githubGist}
|
</code>
|
||||||
wrapLongLines
|
</Box>
|
||||||
customStyle={{
|
<Box sx={{ position: "absolute", top: 8, right: 8 }}>
|
||||||
padding: theme.spacing(2),
|
<CopyButton getText={getText} />
|
||||||
borderRadius: `${theme.shape.borderRadius}px`,
|
|
||||||
fontSize: "0.8rem",
|
|
||||||
fontFamily: "monospace",
|
|
||||||
margin: 0,
|
|
||||||
minHeight: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</SyntaxHighlighter>
|
|
||||||
</Box>
|
</Box>
|
||||||
{content && <Box sx={{ position: "absolute", top: 8, right: 8 }}>
|
|
||||||
<CopyButton text={content} />
|
|
||||||
</Box>}
|
|
||||||
</Box>;
|
</Box>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ import { IconButton, Tooltip } from "@mui/material";
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
interface CopyButtonProps {
|
interface CopyButtonProps {
|
||||||
text: string;
|
getText: () => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CopyButton({ text }: CopyButtonProps): React.JSX.Element {
|
export default function CopyButton({ getText }: CopyButtonProps): React.JSX.Element {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
const timer = useRef<ReturnType<typeof setTimeout>>(undefined);
|
const timer = useRef<ReturnType<typeof setTimeout>>(undefined);
|
||||||
|
|
||||||
useEffect(() => () => clearTimeout(timer.current), []);
|
useEffect(() => () => clearTimeout(timer.current), []);
|
||||||
|
|
||||||
const handleCopy: () => Promise<void> = async () => {
|
const handleCopy: () => Promise<void> = async () => {
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(getText());
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
clearTimeout(timer.current);
|
clearTimeout(timer.current);
|
||||||
timer.current = setTimeout(() => setCopied(false), 2000);
|
timer.current = setTimeout(() => setCopied(false), 2000);
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ import type React from "react";
|
|||||||
export default function RepositorySelect({
|
export default function RepositorySelect({
|
||||||
repositorySelect,
|
repositorySelect,
|
||||||
}: { repositorySelect: SelectedRepositoryResult }): React.JSX.Element {
|
}: { repositorySelect: SelectedRepositoryResult }): React.JSX.Element {
|
||||||
const { repositories, currentRepository } = useRepository();
|
const { repositories, current } = useRepository();
|
||||||
|
|
||||||
return <FormControl fullWidth margin="normal">
|
return <FormControl fullWidth margin="normal">
|
||||||
<InputLabel>repository</InputLabel>
|
<InputLabel>repository</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
value={repositorySelect.selectedKey || (currentRepository?.key ?? "")}
|
value={repositorySelect.selectedKey || (current?.key ?? "")}
|
||||||
label="repository"
|
label="repository"
|
||||||
onChange={event => repositorySelect.setSelectedKey(event.target.value)}
|
onChange={event => repositorySelect.setSelectedKey(event.target.value)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021-2026 ahriman team.
|
|
||||||
*
|
|
||||||
* This file is part of ahriman
|
|
||||||
* (see https://github.com/arcan1s/ahriman).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
||||||
import bash from "react-syntax-highlighter/dist/esm/languages/hljs/bash";
|
|
||||||
import diff from "react-syntax-highlighter/dist/esm/languages/hljs/diff";
|
|
||||||
import plaintext from "react-syntax-highlighter/dist/esm/languages/hljs/plaintext";
|
|
||||||
|
|
||||||
SyntaxHighlighter.registerLanguage("bash", bash);
|
|
||||||
SyntaxHighlighter.registerLanguage("diff", diff);
|
|
||||||
SyntaxHighlighter.registerLanguage("text", plaintext);
|
|
||||||
@@ -36,11 +36,11 @@ interface DashboardDialogProps {
|
|||||||
|
|
||||||
export default function DashboardDialog({ open, onClose }: DashboardDialogProps): React.JSX.Element {
|
export default function DashboardDialog({ open, onClose }: DashboardDialogProps): React.JSX.Element {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const { currentRepository } = useRepository();
|
const { current } = useRepository();
|
||||||
|
|
||||||
const { data: status } = useQuery<InternalStatus>({
|
const { data: status } = useQuery<InternalStatus>({
|
||||||
queryKey: currentRepository ? QueryKeys.status(currentRepository) : ["status"],
|
queryKey: current ? QueryKeys.status(current) : ["status"],
|
||||||
queryFn: currentRepository ? () => client.fetch.fetchServerStatus(currentRepository) : skipToken,
|
queryFn: current ? () => client.fetch.fetchServerStatus(current) : skipToken,
|
||||||
enabled: open,
|
enabled: open,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export default function KeyImportDialog({ open, onClose }: KeyImportDialogProps)
|
|||||||
/>
|
/>
|
||||||
{keyBody &&
|
{keyBody &&
|
||||||
<Box sx={{ mt: 2 }}>
|
<Box sx={{ mt: 2 }}>
|
||||||
<CodeBlock content={keyBody} height={300} />
|
<CodeBlock getText={() => keyBody} height={300} />
|
||||||
</Box>
|
</Box>
|
||||||
}
|
}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ import EventsTab from "components/package/EventsTab";
|
|||||||
import PackageDetailsGrid from "components/package/PackageDetailsGrid";
|
import PackageDetailsGrid from "components/package/PackageDetailsGrid";
|
||||||
import PackageInfoActions from "components/package/PackageInfoActions";
|
import PackageInfoActions from "components/package/PackageInfoActions";
|
||||||
import PackagePatchesList from "components/package/PackagePatchesList";
|
import PackagePatchesList from "components/package/PackagePatchesList";
|
||||||
import PkgbuildTab from "components/package/PkgbuildTab";
|
|
||||||
import { type TabKey, tabs } from "components/package/TabKey";
|
|
||||||
import { QueryKeys } from "hooks/QueryKeys";
|
import { QueryKeys } from "hooks/QueryKeys";
|
||||||
import { useAuth } from "hooks/useAuth";
|
import { useAuth } from "hooks/useAuth";
|
||||||
import { useAutoRefresh } from "hooks/useAutoRefresh";
|
import { useAutoRefresh } from "hooks/useAutoRefresh";
|
||||||
@@ -57,7 +55,7 @@ export default function PackageInfoDialog({
|
|||||||
autoRefreshIntervals,
|
autoRefreshIntervals,
|
||||||
}: PackageInfoDialogProps): React.JSX.Element {
|
}: PackageInfoDialogProps): React.JSX.Element {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const { currentRepository } = useRepository();
|
const { current } = useRepository();
|
||||||
const { isAuthorized } = useAuth();
|
const { isAuthorized } = useAuth();
|
||||||
const { showSuccess, showError } = useNotification();
|
const { showSuccess, showError } = useNotification();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@@ -67,11 +65,11 @@ export default function PackageInfoDialog({
|
|||||||
setLocalPackageBase(packageBase);
|
setLocalPackageBase(packageBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState<TabKey>("logs");
|
const [tabIndex, setTabIndex] = useState(0);
|
||||||
const [refreshDatabase, setRefreshDatabase] = useState(true);
|
const [refreshDatabase, setRefreshDatabase] = useState(true);
|
||||||
|
|
||||||
const handleClose = (): void => {
|
const handleClose = (): void => {
|
||||||
setActiveTab("logs");
|
setTabIndex(0);
|
||||||
setRefreshDatabase(true);
|
setRefreshDatabase(true);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
@@ -79,17 +77,16 @@ export default function PackageInfoDialog({
|
|||||||
const autoRefresh = useAutoRefresh("package-info-autoreload-button", defaultInterval(autoRefreshIntervals));
|
const autoRefresh = useAutoRefresh("package-info-autoreload-button", defaultInterval(autoRefreshIntervals));
|
||||||
|
|
||||||
const { data: packageData } = useQuery<PackageStatus[]>({
|
const { data: packageData } = useQuery<PackageStatus[]>({
|
||||||
queryKey: localPackageBase && currentRepository ? QueryKeys.package(localPackageBase, currentRepository) : ["packages"],
|
queryKey: localPackageBase && current ? QueryKeys.package(localPackageBase, current) : ["packages"],
|
||||||
queryFn: localPackageBase && currentRepository ?
|
queryFn: localPackageBase && current ? () => client.fetch.fetchPackage(localPackageBase, current) : skipToken,
|
||||||
() => client.fetch.fetchPackage(localPackageBase, currentRepository) : skipToken,
|
|
||||||
enabled: open,
|
enabled: open,
|
||||||
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: dependencies } = useQuery<Dependencies>({
|
const { data: dependencies } = useQuery<Dependencies>({
|
||||||
queryKey: localPackageBase && currentRepository ? QueryKeys.dependencies(localPackageBase, currentRepository) : ["dependencies"],
|
queryKey: localPackageBase && current ? QueryKeys.dependencies(localPackageBase, current) : ["dependencies"],
|
||||||
queryFn: localPackageBase && currentRepository ?
|
queryFn: localPackageBase && current
|
||||||
() => client.fetch.fetchPackageDependencies(localPackageBase, currentRepository) : skipToken,
|
? () => client.fetch.fetchPackageDependencies(localPackageBase, current) : skipToken,
|
||||||
enabled: open,
|
enabled: open,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -105,12 +102,11 @@ export default function PackageInfoDialog({
|
|||||||
const headerStyle = status ? StatusHeaderStyles[status.status] : {};
|
const headerStyle = status ? StatusHeaderStyles[status.status] : {};
|
||||||
|
|
||||||
const handleUpdate: () => Promise<void> = async () => {
|
const handleUpdate: () => Promise<void> = async () => {
|
||||||
if (!localPackageBase || !currentRepository) {
|
if (!localPackageBase || !current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await client.service.servicePackageAdd(
|
await client.service.servicePackageAdd(current, { packages: [localPackageBase], refresh: refreshDatabase });
|
||||||
currentRepository, { packages: [localPackageBase], refresh: refreshDatabase });
|
|
||||||
showSuccess("Success", `Run update for packages ${localPackageBase}`);
|
showSuccess("Success", `Run update for packages ${localPackageBase}`);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
showError("Action failed", `Package update failed: ${ApiError.errorDetail(exception)}`);
|
showError("Action failed", `Package update failed: ${ApiError.errorDetail(exception)}`);
|
||||||
@@ -118,11 +114,11 @@ export default function PackageInfoDialog({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove: () => Promise<void> = async () => {
|
const handleRemove: () => Promise<void> = async () => {
|
||||||
if (!localPackageBase || !currentRepository) {
|
if (!localPackageBase || !current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await client.service.servicePackageRemove(currentRepository, [localPackageBase]);
|
await client.service.servicePackageRemove(current, [localPackageBase]);
|
||||||
showSuccess("Success", `Packages ${localPackageBase} have been removed`);
|
showSuccess("Success", `Packages ${localPackageBase} have been removed`);
|
||||||
onClose();
|
onClose();
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
@@ -160,26 +156,25 @@ export default function PackageInfoDialog({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Box sx={{ borderBottom: 1, borderColor: "divider", mt: 2 }}>
|
<Box sx={{ borderBottom: 1, borderColor: "divider", mt: 2 }}>
|
||||||
<Tabs value={activeTab} onChange={(_, tab: TabKey) => setActiveTab(tab)}>
|
<Tabs value={tabIndex} onChange={(_, index: number) => setTabIndex(index)}>
|
||||||
{tabs.map(({ key, label }) => <Tab key={key} value={key} label={label} />)}
|
<Tab label="Build logs" />
|
||||||
|
<Tab label="Changes" />
|
||||||
|
<Tab label="Events" />
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{activeTab === "logs" && localPackageBase && currentRepository &&
|
{tabIndex === 0 && localPackageBase && current &&
|
||||||
<BuildLogsTab
|
<BuildLogsTab
|
||||||
packageBase={localPackageBase}
|
packageBase={localPackageBase}
|
||||||
repository={currentRepository}
|
repository={current}
|
||||||
refreshInterval={autoRefresh.interval}
|
refreshInterval={autoRefresh.interval}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{activeTab === "changes" && localPackageBase && currentRepository &&
|
{tabIndex === 1 && localPackageBase && current &&
|
||||||
<ChangesTab packageBase={localPackageBase} repository={currentRepository} />
|
<ChangesTab packageBase={localPackageBase} repository={current} />
|
||||||
}
|
}
|
||||||
{activeTab === "pkgbuild" && localPackageBase && currentRepository &&
|
{tabIndex === 2 && localPackageBase && current &&
|
||||||
<PkgbuildTab packageBase={localPackageBase} repository={currentRepository} />
|
<EventsTab packageBase={localPackageBase} repository={current} />
|
||||||
}
|
|
||||||
{activeTab === "events" && localPackageBase && currentRepository &&
|
|
||||||
<EventsTab packageBase={localPackageBase} repository={currentRepository} />
|
|
||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,14 @@ import { useRepository } from "hooks/useRepository";
|
|||||||
import type React from "react";
|
import type React from "react";
|
||||||
|
|
||||||
export default function Navbar(): React.JSX.Element | null {
|
export default function Navbar(): React.JSX.Element | null {
|
||||||
const { repositories, currentRepository, setCurrentRepository } = useRepository();
|
const { repositories, current, setCurrent } = useRepository();
|
||||||
|
|
||||||
if (repositories.length === 0 || !currentRepository) {
|
if (repositories.length === 0 || !current) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentIndex = repositories.findIndex(repository =>
|
const currentIndex = repositories.findIndex(repository =>
|
||||||
repository.architecture === currentRepository.architecture &&
|
repository.architecture === current.architecture && repository.repository === current.repository,
|
||||||
repository.repository === currentRepository.repository,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
|
return <Box sx={{ borderBottom: 1, borderColor: "divider" }}>
|
||||||
@@ -39,7 +38,7 @@ export default function Navbar(): React.JSX.Element | null {
|
|||||||
onChange={(_, newValue: number) => {
|
onChange={(_, newValue: number) => {
|
||||||
const repository = repositories[newValue];
|
const repository = repositories[newValue];
|
||||||
if (repository) {
|
if (repository) {
|
||||||
setCurrentRepository(repository);
|
setCurrent(repository);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
variant="scrollable"
|
variant="scrollable"
|
||||||
|
|||||||
@@ -175,9 +175,10 @@ export default function BuildLogsTab({
|
|||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
preRef={preRef}
|
preRef={preRef}
|
||||||
content={displayedLogs}
|
getText={() => displayedLogs}
|
||||||
height={400}
|
height={400}
|
||||||
onScroll={handleScroll}
|
onScroll={handleScroll}
|
||||||
|
wordBreak
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>;
|
</Box>;
|
||||||
|
|||||||
@@ -17,10 +17,20 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import CodeBlock from "components/common/CodeBlock";
|
import { Box } from "@mui/material";
|
||||||
import { usePackageChanges } from "hooks/usePackageChanges";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import CopyButton from "components/common/CopyButton";
|
||||||
|
import { QueryKeys } from "hooks/QueryKeys";
|
||||||
|
import { useClient } from "hooks/useClient";
|
||||||
|
import { useThemeMode } from "hooks/useThemeMode";
|
||||||
|
import type { Changes } from "models/Changes";
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
import type { RepositoryId } from "models/RepositoryId";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
|
||||||
|
import diff from "react-syntax-highlighter/dist/esm/languages/hljs/diff";
|
||||||
|
import { githubGist, vs2015 } from "react-syntax-highlighter/dist/esm/styles/hljs";
|
||||||
|
|
||||||
|
SyntaxHighlighter.registerLanguage("diff", diff);
|
||||||
|
|
||||||
interface ChangesTabProps {
|
interface ChangesTabProps {
|
||||||
packageBase: string;
|
packageBase: string;
|
||||||
@@ -28,7 +38,35 @@ interface ChangesTabProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ChangesTab({ packageBase, repository }: ChangesTabProps): React.JSX.Element {
|
export default function ChangesTab({ packageBase, repository }: ChangesTabProps): React.JSX.Element {
|
||||||
const data = usePackageChanges(packageBase, repository);
|
const client = useClient();
|
||||||
|
const { mode } = useThemeMode();
|
||||||
|
|
||||||
return <CodeBlock language="diff" content={data?.changes ?? ""} height={400} />;
|
const { data } = useQuery<Changes>({
|
||||||
|
queryKey: QueryKeys.changes(packageBase, repository),
|
||||||
|
queryFn: () => client.fetch.fetchPackageChanges(packageBase, repository),
|
||||||
|
enabled: !!packageBase,
|
||||||
|
});
|
||||||
|
|
||||||
|
const changesText = data?.changes ?? "";
|
||||||
|
|
||||||
|
return <Box sx={{ position: "relative", mt: 1 }}>
|
||||||
|
<SyntaxHighlighter
|
||||||
|
language="diff"
|
||||||
|
style={mode === "dark" ? vs2015 : githubGist}
|
||||||
|
customStyle={{
|
||||||
|
padding: "16px",
|
||||||
|
borderRadius: "4px",
|
||||||
|
overflow: "auto",
|
||||||
|
height: 400,
|
||||||
|
fontSize: "0.8rem",
|
||||||
|
fontFamily: "monospace",
|
||||||
|
margin: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{changesText}
|
||||||
|
</SyntaxHighlighter>
|
||||||
|
<Box sx={{ position: "absolute", top: 8, right: 8 }}>
|
||||||
|
<CopyButton getText={() => changesText} />
|
||||||
|
</Box>
|
||||||
|
</Box>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021-2026 ahriman team.
|
|
||||||
*
|
|
||||||
* This file is part of ahriman
|
|
||||||
* (see https://github.com/arcan1s/ahriman).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import CodeBlock from "components/common/CodeBlock";
|
|
||||||
import { usePackageChanges } from "hooks/usePackageChanges";
|
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
|
||||||
import React from "react";
|
|
||||||
|
|
||||||
interface PkgbuildTabProps {
|
|
||||||
packageBase: string;
|
|
||||||
repository: RepositoryId;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function PkgbuildTab({ packageBase, repository }: PkgbuildTabProps): React.JSX.Element {
|
|
||||||
const data = usePackageChanges(packageBase, repository);
|
|
||||||
|
|
||||||
return <CodeBlock language="bash" content={data?.pkgbuild ?? ""} height={400} />;
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
export type TabKey = "logs" | "changes" | "pkgbuild" | "events";
|
|
||||||
|
|
||||||
export const tabs: { key: TabKey; label: string }[] = [
|
|
||||||
{ key: "logs", label: "Build logs" },
|
|
||||||
{ key: "changes", label: "Changes" },
|
|
||||||
{ key: "pkgbuild", label: "PKGBUILD" },
|
|
||||||
{ key: "events", label: "Events" },
|
|
||||||
];
|
|
||||||
@@ -22,9 +22,9 @@ import { createContext } from "react";
|
|||||||
|
|
||||||
export interface RepositoryContextValue {
|
export interface RepositoryContextValue {
|
||||||
repositories: RepositoryId[];
|
repositories: RepositoryId[];
|
||||||
currentRepository: RepositoryId | null;
|
current: RepositoryId | null;
|
||||||
setRepositories: (repositories: RepositoryId[]) => void;
|
setRepositories: (repositories: RepositoryId[]) => void;
|
||||||
setCurrentRepository: (repository: RepositoryId) => void;
|
setCurrent: (repository: RepositoryId) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RepositoryContext = createContext<RepositoryContextValue | null>(null);
|
export const RepositoryContext = createContext<RepositoryContextValue | null>(null);
|
||||||
|
|||||||
@@ -34,20 +34,20 @@ export function RepositoryProvider({ children }: { children: ReactNode }): React
|
|||||||
const [repositories, setRepositories] = useState<RepositoryId[]>([]);
|
const [repositories, setRepositories] = useState<RepositoryId[]>([]);
|
||||||
const hash = useSyncExternalStore(subscribeToHash, getHashSnapshot);
|
const hash = useSyncExternalStore(subscribeToHash, getHashSnapshot);
|
||||||
|
|
||||||
const currentRepository = useMemo(() => {
|
const current = useMemo(() => {
|
||||||
if (repositories.length === 0) {
|
if (repositories.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return repositories.find(repository => repository.key === hash) ?? repositories[0] ?? null;
|
return repositories.find(repository => repository.key === hash) ?? repositories[0] ?? null;
|
||||||
}, [repositories, hash]);
|
}, [repositories, hash]);
|
||||||
|
|
||||||
const setCurrentRepository = useCallback((repository: RepositoryId) => {
|
const setCurrent = useCallback((repository: RepositoryId) => {
|
||||||
window.location.hash = repository.key;
|
window.location.hash = repository.key;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const value = useMemo(() => ({
|
const value = useMemo(() => ({
|
||||||
repositories, currentRepository, setRepositories, setCurrentRepository,
|
repositories, current, setRepositories, setCurrent,
|
||||||
}), [repositories, currentRepository, setCurrentRepository]);
|
}), [repositories, current, setCurrent]);
|
||||||
|
|
||||||
return <RepositoryContext.Provider value={value}>{children}</RepositoryContext.Provider>;
|
return <RepositoryContext.Provider value={value}>{children}</RepositoryContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export function usePackageActions(
|
|||||||
setSelectionModel: (model: string[]) => void,
|
setSelectionModel: (model: string[]) => void,
|
||||||
): UsePackageActionsResult {
|
): UsePackageActionsResult {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const { currentRepository } = useRepository();
|
const { current } = useRepository();
|
||||||
const { showSuccess, showError } = useNotification();
|
const { showSuccess, showError } = useNotification();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -50,13 +50,13 @@ export function usePackageActions(
|
|||||||
action: (repository: RepositoryId) => Promise<string>,
|
action: (repository: RepositoryId) => Promise<string>,
|
||||||
errorMessage: string,
|
errorMessage: string,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
if (!currentRepository) {
|
if (!current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const successMessage = await action(currentRepository);
|
const successMessage = await action(current);
|
||||||
showSuccess("Success", successMessage);
|
showSuccess("Success", successMessage);
|
||||||
invalidate(currentRepository);
|
invalidate(current);
|
||||||
setSelectionModel([]);
|
setSelectionModel([]);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
showError("Action failed", `${errorMessage}: ${ApiError.errorDetail(exception)}`);
|
showError("Action failed", `${errorMessage}: ${ApiError.errorDetail(exception)}`);
|
||||||
@@ -64,8 +64,8 @@ export function usePackageActions(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleReload: () => void = () => {
|
const handleReload: () => void = () => {
|
||||||
if (currentRepository !== null) {
|
if (current !== null) {
|
||||||
invalidate(currentRepository);
|
invalidate(current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021-2026 ahriman team.
|
|
||||||
*
|
|
||||||
* This file is part of ahriman
|
|
||||||
* (see https://github.com/arcan1s/ahriman).
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import { useQuery } from "@tanstack/react-query";
|
|
||||||
import { QueryKeys } from "hooks/QueryKeys";
|
|
||||||
import { useClient } from "hooks/useClient";
|
|
||||||
import type { Changes } from "models/Changes";
|
|
||||||
import type { RepositoryId } from "models/RepositoryId";
|
|
||||||
|
|
||||||
export function usePackageChanges(packageBase: string, repository: RepositoryId): Changes | undefined {
|
|
||||||
const client = useClient();
|
|
||||||
|
|
||||||
const { data } = useQuery<Changes>({
|
|
||||||
queryKey: QueryKeys.changes(packageBase, repository),
|
|
||||||
queryFn: () => client.fetch.fetchPackageChanges(packageBase, repository),
|
|
||||||
enabled: !!packageBase,
|
|
||||||
});
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
@@ -39,20 +39,20 @@ export interface UsePackageDataResult {
|
|||||||
|
|
||||||
export function usePackageData(autoRefreshIntervals: AutoRefreshInterval[]): UsePackageDataResult {
|
export function usePackageData(autoRefreshIntervals: AutoRefreshInterval[]): UsePackageDataResult {
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
const { currentRepository } = useRepository();
|
const { current } = useRepository();
|
||||||
const { isAuthorized } = useAuth();
|
const { isAuthorized } = useAuth();
|
||||||
|
|
||||||
const autoRefresh = useAutoRefresh("table-autoreload-button", defaultInterval(autoRefreshIntervals));
|
const autoRefresh = useAutoRefresh("table-autoreload-button", defaultInterval(autoRefreshIntervals));
|
||||||
|
|
||||||
const { data: packages = [], isLoading } = useQuery({
|
const { data: packages = [], isLoading } = useQuery({
|
||||||
queryKey: currentRepository ? QueryKeys.packages(currentRepository) : ["packages"],
|
queryKey: current ? QueryKeys.packages(current) : ["packages"],
|
||||||
queryFn: currentRepository ? () => client.fetch.fetchPackages(currentRepository) : skipToken,
|
queryFn: current ? () => client.fetch.fetchPackages(current) : skipToken,
|
||||||
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: status } = useQuery({
|
const { data: status } = useQuery({
|
||||||
queryKey: currentRepository ? QueryKeys.status(currentRepository) : ["status"],
|
queryKey: current ? QueryKeys.status(current) : ["status"],
|
||||||
queryFn: currentRepository ? () => client.fetch.fetchServerStatus(currentRepository) : skipToken,
|
queryFn: current ? () => client.fetch.fetchServerStatus(current) : skipToken,
|
||||||
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
refetchInterval: autoRefresh.interval > 0 ? autoRefresh.interval : false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ export interface SelectedRepositoryResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useSelectedRepository(): SelectedRepositoryResult {
|
export function useSelectedRepository(): SelectedRepositoryResult {
|
||||||
const { repositories, currentRepository } = useRepository();
|
const { repositories, current } = useRepository();
|
||||||
const [selectedKey, setSelectedKey] = useState("");
|
const [selectedKey, setSelectedKey] = useState("");
|
||||||
|
|
||||||
let selectedRepository: RepositoryId | null = currentRepository;
|
let selectedRepository: RepositoryId | null = current;
|
||||||
if (selectedKey) {
|
if (selectedKey) {
|
||||||
const repository = repositories.find(repository => repository.key === selectedKey);
|
const repository = repositories.find(repository => repository.key === selectedKey);
|
||||||
if (repository) {
|
if (repository) {
|
||||||
|
|||||||
@@ -20,5 +20,4 @@
|
|||||||
export interface Changes {
|
export interface Changes {
|
||||||
changes?: string;
|
changes?: string;
|
||||||
last_commit_sha?: string;
|
last_commit_sha?: string;
|
||||||
pkgbuild?: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
pkgbase='ahriman'
|
pkgbase='ahriman'
|
||||||
pkgname=('ahriman' 'ahriman-core' 'ahriman-triggers' 'ahriman-web')
|
pkgname=('ahriman' 'ahriman-core' 'ahriman-triggers' 'ahriman-web')
|
||||||
pkgver=2.20.0
|
pkgver=2.20.1
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="ArcH linux ReposItory MANager"
|
pkgdesc="ArcH linux ReposItory MANager"
|
||||||
arch=('any')
|
arch=('any')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.TH AHRIMAN "1" "2026\-03\-08" "ahriman 2.20.0" "ArcH linux ReposItory MANager"
|
.TH AHRIMAN "1" "2026\-03\-13" "ahriman 2.20.1" "ArcH linux ReposItory MANager"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
ahriman \- ArcH linux ReposItory MANager
|
ahriman \- ArcH linux ReposItory MANager
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
|||||||
@@ -17,4 +17,4 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
__version__ = "2.20.0"
|
__version__ = "2.20.1"
|
||||||
|
|||||||
@@ -154,13 +154,13 @@ class Application(ApplicationPackages, ApplicationRepository):
|
|||||||
for package_name, packager in missing.items():
|
for package_name, packager in missing.items():
|
||||||
if (source_dir := self.repository.paths.cache_for(package_name)).is_dir():
|
if (source_dir := self.repository.paths.cache_for(package_name)).is_dir():
|
||||||
# there is local cache, load package from it
|
# there is local cache, load package from it
|
||||||
leaf = Package.from_build(source_dir, self.repository.repository_id.architecture, packager)
|
leaf = Package.from_build(source_dir, self.repository.architecture, packager)
|
||||||
else:
|
else:
|
||||||
leaf = Package.from_aur(package_name, packager, include_provides=True)
|
leaf = Package.from_aur(package_name, packager, include_provides=True)
|
||||||
portion[leaf.base] = leaf
|
portion[leaf.base] = leaf
|
||||||
|
|
||||||
# register package in the database
|
# register package in the database
|
||||||
self.reporter.set_unknown(leaf)
|
self.repository.reporter.set_unknown(leaf)
|
||||||
|
|
||||||
return portion
|
return portion
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ class ApplicationRepository(ApplicationProperties):
|
|||||||
if last_commit_sha is None:
|
if last_commit_sha is None:
|
||||||
continue # skip check in case if we can't calculate diff
|
continue # skip check in case if we can't calculate diff
|
||||||
|
|
||||||
if (changes := self.repository.package_changes(package, last_commit_sha)) is not None:
|
changes = self.repository.package_changes(package, last_commit_sha)
|
||||||
self.reporter.package_changes_update(package.base, changes)
|
self.repository.reporter.package_changes_update(package.base, changes)
|
||||||
|
|
||||||
def clean(self, *, cache: bool, chroot: bool, manual: bool, packages: bool, pacman: bool) -> None:
|
def clean(self, *, cache: bool, chroot: bool, manual: bool, packages: bool, pacman: bool) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 2021-2026 ahriman team.
|
|
||||||
#
|
|
||||||
# This file is part of ahriman
|
|
||||||
# (see https://github.com/arcan1s/ahriman).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
from ahriman.application.application import Application
|
|
||||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
|
||||||
from ahriman.core.configuration import Configuration
|
|
||||||
from ahriman.core.formatters import PackagePrinter
|
|
||||||
from ahriman.models.action import Action
|
|
||||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
|
||||||
from ahriman.models.repository_id import RepositoryId
|
|
||||||
|
|
||||||
|
|
||||||
class Archives(Handler):
|
|
||||||
"""
|
|
||||||
package archives handler
|
|
||||||
"""
|
|
||||||
|
|
||||||
ALLOW_MULTI_ARCHITECTURE_RUN = False # conflicting io
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def run(cls, args: argparse.Namespace, repository_id: RepositoryId, configuration: Configuration, *,
|
|
||||||
report: bool) -> None:
|
|
||||||
"""
|
|
||||||
callback for command line
|
|
||||||
|
|
||||||
Args:
|
|
||||||
args(argparse.Namespace): command line args
|
|
||||||
repository_id(RepositoryId): repository unique identifier
|
|
||||||
configuration(Configuration): configuration instance
|
|
||||||
report(bool): force enable or disable reporting
|
|
||||||
"""
|
|
||||||
application = Application(repository_id, configuration, report=True)
|
|
||||||
|
|
||||||
match args.action:
|
|
||||||
case Action.List:
|
|
||||||
archives = application.repository.package_archives(args.package)
|
|
||||||
for package in archives:
|
|
||||||
PackagePrinter(package, BuildStatus(BuildStatusEnum.Success))(verbose=args.info)
|
|
||||||
|
|
||||||
Archives.check_status(args.exit_code, bool(archives))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _set_package_archives_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
|
||||||
"""
|
|
||||||
add parser for package archives subcommand
|
|
||||||
|
|
||||||
Args:
|
|
||||||
root(SubParserAction): subparsers for the commands
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
argparse.ArgumentParser: created argument parser
|
|
||||||
"""
|
|
||||||
parser = root.add_parser("package-archives", help="list package archive versions",
|
|
||||||
description="list available archive versions for the package")
|
|
||||||
parser.add_argument("package", help="package base")
|
|
||||||
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
|
|
||||||
action="store_true")
|
|
||||||
parser.add_argument("--info", help="show additional package information",
|
|
||||||
action=argparse.BooleanOptionalAction, default=False)
|
|
||||||
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True)
|
|
||||||
return parser
|
|
||||||
|
|
||||||
arguments = [_set_package_archives_parser]
|
|
||||||
@@ -47,13 +47,14 @@ class Change(Handler):
|
|||||||
configuration(Configuration): configuration instance
|
configuration(Configuration): configuration instance
|
||||||
report(bool): force enable or disable reporting
|
report(bool): force enable or disable reporting
|
||||||
"""
|
"""
|
||||||
client = Application(repository_id, configuration, report=True).reporter
|
application = Application(repository_id, configuration, report=True)
|
||||||
|
client = application.repository.reporter
|
||||||
|
|
||||||
match args.action:
|
match args.action:
|
||||||
case Action.List:
|
case Action.List:
|
||||||
changes = client.package_changes_get(args.package)
|
changes = client.package_changes_get(args.package)
|
||||||
ChangesPrinter(changes)(verbose=True, separator="")
|
ChangesPrinter(changes)(verbose=True, separator="")
|
||||||
Change.check_status(args.exit_code, changes.changes is not None)
|
Change.check_status(args.exit_code, not changes.is_empty)
|
||||||
case Action.Remove:
|
case Action.Remove:
|
||||||
client.package_changes_update(args.package, Changes())
|
client.package_changes_update(args.package, Changes())
|
||||||
|
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 2021-2026 ahriman team.
|
|
||||||
#
|
|
||||||
# This file is part of ahriman
|
|
||||||
# (see https://github.com/arcan1s/ahriman).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
from dataclasses import replace
|
|
||||||
|
|
||||||
from ahriman.application.application import Application
|
|
||||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
|
||||||
from ahriman.core.configuration import Configuration
|
|
||||||
from ahriman.core.formatters import PkgbuildPrinter
|
|
||||||
from ahriman.models.action import Action
|
|
||||||
from ahriman.models.repository_id import RepositoryId
|
|
||||||
|
|
||||||
|
|
||||||
class Pkgbuild(Handler):
|
|
||||||
"""
|
|
||||||
package pkgbuild handler
|
|
||||||
"""
|
|
||||||
|
|
||||||
ALLOW_MULTI_ARCHITECTURE_RUN = False # conflicting io
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def run(cls, args: argparse.Namespace, repository_id: RepositoryId, configuration: Configuration, *,
|
|
||||||
report: bool) -> None:
|
|
||||||
"""
|
|
||||||
callback for command line
|
|
||||||
|
|
||||||
Args:
|
|
||||||
args(argparse.Namespace): command line args
|
|
||||||
repository_id(RepositoryId): repository unique identifier
|
|
||||||
configuration(Configuration): configuration instance
|
|
||||||
report(bool): force enable or disable reporting
|
|
||||||
"""
|
|
||||||
client = Application(repository_id, configuration, report=True).reporter
|
|
||||||
|
|
||||||
match args.action:
|
|
||||||
case Action.List:
|
|
||||||
changes = client.package_changes_get(args.package)
|
|
||||||
PkgbuildPrinter(changes)(verbose=True, separator="")
|
|
||||||
Pkgbuild.check_status(args.exit_code, changes.pkgbuild is not None)
|
|
||||||
case Action.Remove:
|
|
||||||
changes = client.package_changes_get(args.package)
|
|
||||||
client.package_changes_update(args.package, replace(changes, pkgbuild=None))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _set_package_pkgbuild_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
|
||||||
"""
|
|
||||||
add parser for package pkgbuild subcommand
|
|
||||||
|
|
||||||
Args:
|
|
||||||
root(SubParserAction): subparsers for the commands
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
argparse.ArgumentParser: created argument parser
|
|
||||||
"""
|
|
||||||
parser = root.add_parser("package-pkgbuild", help="get package pkgbuild",
|
|
||||||
description="retrieve package PKGBUILD stored in database",
|
|
||||||
epilog="This command requests package status from the web interface "
|
|
||||||
"if it is available.")
|
|
||||||
parser.add_argument("package", help="package base")
|
|
||||||
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
|
|
||||||
action="store_true")
|
|
||||||
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True)
|
|
||||||
return parser
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _set_package_pkgbuild_remove_parser(root: SubParserAction) -> argparse.ArgumentParser:
|
|
||||||
"""
|
|
||||||
add parser for package pkgbuild remove subcommand
|
|
||||||
|
|
||||||
Args:
|
|
||||||
root(SubParserAction): subparsers for the commands
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
argparse.ArgumentParser: created argument parser
|
|
||||||
"""
|
|
||||||
parser = root.add_parser("package-pkgbuild-remove", help="remove package pkgbuild",
|
|
||||||
description="remove the package PKGBUILD stored remotely")
|
|
||||||
parser.add_argument("package", help="package base")
|
|
||||||
parser.set_defaults(action=Action.Remove, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
|
|
||||||
return parser
|
|
||||||
|
|
||||||
arguments = [_set_package_pkgbuild_parser, _set_package_pkgbuild_remove_parser]
|
|
||||||
@@ -44,7 +44,8 @@ class Reload(Handler):
|
|||||||
configuration(Configuration): configuration instance
|
configuration(Configuration): configuration instance
|
||||||
report(bool): force enable or disable reporting
|
report(bool): force enable or disable reporting
|
||||||
"""
|
"""
|
||||||
client = Application(repository_id, configuration, report=True).reporter
|
application = Application(repository_id, configuration, report=True)
|
||||||
|
client = application.repository.reporter
|
||||||
client.configuration_reload()
|
client.configuration_reload()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Status(Handler):
|
|||||||
report(bool): force enable or disable reporting
|
report(bool): force enable or disable reporting
|
||||||
"""
|
"""
|
||||||
# we are using reporter here
|
# we are using reporter here
|
||||||
client = Application(repository_id, configuration, report=True).reporter
|
client = Application(repository_id, configuration, report=True).repository.reporter
|
||||||
if args.ahriman:
|
if args.ahriman:
|
||||||
service_status = client.status_get()
|
service_status = client.status_get()
|
||||||
StatusPrinter(service_status.status)(verbose=args.info)
|
StatusPrinter(service_status.status)(verbose=args.info)
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class StatusUpdate(Handler):
|
|||||||
configuration(Configuration): configuration instance
|
configuration(Configuration): configuration instance
|
||||||
report(bool): force enable or disable reporting
|
report(bool): force enable or disable reporting
|
||||||
"""
|
"""
|
||||||
client = Application(repository_id, configuration, report=True).reporter
|
application = Application(repository_id, configuration, report=True)
|
||||||
|
client = application.repository.reporter
|
||||||
|
|
||||||
match args.action:
|
match args.action:
|
||||||
case Action.Update if args.package:
|
case Action.Update if args.package:
|
||||||
|
|||||||
@@ -24,11 +24,10 @@ import tarfile
|
|||||||
from collections.abc import Iterable, Iterator
|
from collections.abc import Iterable, Iterator
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pyalpm import DB, Package, SIG_DATABASE_OPTIONAL, SIG_PACKAGE_OPTIONAL # type: ignore[import-not-found]
|
from pyalpm import DB, Handle, Package, SIG_DATABASE_OPTIONAL, SIG_PACKAGE_OPTIONAL # type: ignore[import-not-found]
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|
||||||
from ahriman.core.alpm.pacman_database import PacmanDatabase
|
from ahriman.core.alpm.pacman_database import PacmanDatabase
|
||||||
from ahriman.core.alpm.pacman_handle import PacmanHandle
|
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.log import LazyLogging
|
from ahriman.core.log import LazyLogging
|
||||||
from ahriman.core.utils import trim_package
|
from ahriman.core.utils import trim_package
|
||||||
@@ -62,16 +61,16 @@ class Pacman(LazyLogging):
|
|||||||
self.refresh_database = refresh_database
|
self.refresh_database = refresh_database
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def handle(self) -> PacmanHandle:
|
def handle(self) -> Handle:
|
||||||
"""
|
"""
|
||||||
pyalpm handle
|
pyalpm handle
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
PacmanHandle: generated pyalpm handle instance
|
Handle: generated pyalpm handle instance
|
||||||
"""
|
"""
|
||||||
return self.__create_handle(refresh_database=self.refresh_database)
|
return self.__create_handle(refresh_database=self.refresh_database)
|
||||||
|
|
||||||
def __create_handle(self, *, refresh_database: PacmanSynchronization) -> PacmanHandle:
|
def __create_handle(self, *, refresh_database: PacmanSynchronization) -> Handle:
|
||||||
"""
|
"""
|
||||||
create lazy handle function
|
create lazy handle function
|
||||||
|
|
||||||
@@ -79,14 +78,14 @@ class Pacman(LazyLogging):
|
|||||||
refresh_database(PacmanSynchronization): synchronize local cache to remote
|
refresh_database(PacmanSynchronization): synchronize local cache to remote
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
PacmanHandle: fully initialized pacman handle
|
Handle: fully initialized pacman handle
|
||||||
"""
|
"""
|
||||||
pacman_root = self.configuration.getpath("alpm", "database")
|
pacman_root = self.configuration.getpath("alpm", "database")
|
||||||
use_ahriman_cache = self.configuration.getboolean("alpm", "use_ahriman_cache")
|
use_ahriman_cache = self.configuration.getboolean("alpm", "use_ahriman_cache")
|
||||||
|
|
||||||
database_path = self.repository_paths.pacman if use_ahriman_cache else pacman_root
|
database_path = self.repository_paths.pacman if use_ahriman_cache else pacman_root
|
||||||
root = self.configuration.getpath("alpm", "root")
|
root = self.configuration.getpath("alpm", "root")
|
||||||
handle = PacmanHandle(str(root), str(database_path))
|
handle = Handle(str(root), str(database_path))
|
||||||
|
|
||||||
for repository in self.configuration.getlist("alpm", "repositories"):
|
for repository in self.configuration.getlist("alpm", "repositories"):
|
||||||
database = self.database_init(handle, repository, self.repository_id.architecture)
|
database = self.database_init(handle, repository, self.repository_id.architecture)
|
||||||
@@ -100,12 +99,12 @@ class Pacman(LazyLogging):
|
|||||||
|
|
||||||
return handle
|
return handle
|
||||||
|
|
||||||
def database_copy(self, handle: PacmanHandle, database: DB, pacman_root: Path, *, use_ahriman_cache: bool) -> None:
|
def database_copy(self, handle: Handle, database: DB, pacman_root: Path, *, use_ahriman_cache: bool) -> None:
|
||||||
"""
|
"""
|
||||||
copy database from the operating system root to the ahriman local home
|
copy database from the operating system root to the ahriman local home
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
handle(PacmanHandle): pacman handle which will be used for database copying
|
handle(Handle): pacman handle which will be used for database copying
|
||||||
database(DB): pacman database instance to be copied
|
database(DB): pacman database instance to be copied
|
||||||
pacman_root(Path): operating system pacman root
|
pacman_root(Path): operating system pacman root
|
||||||
use_ahriman_cache(bool): use local ahriman cache instead of system one
|
use_ahriman_cache(bool): use local ahriman cache instead of system one
|
||||||
@@ -134,12 +133,12 @@ class Pacman(LazyLogging):
|
|||||||
with self.repository_paths.preserve_owner():
|
with self.repository_paths.preserve_owner():
|
||||||
shutil.copy(src, dst)
|
shutil.copy(src, dst)
|
||||||
|
|
||||||
def database_init(self, handle: PacmanHandle, repository: str, architecture: str) -> DB:
|
def database_init(self, handle: Handle, repository: str, architecture: str) -> DB:
|
||||||
"""
|
"""
|
||||||
create database instance from pacman handler and set its properties
|
create database instance from pacman handler and set its properties
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
handle(PacmanHandle): pacman handle which will be used for database initializing
|
handle(Handle): pacman handle which will be used for database initializing
|
||||||
repository(str): pacman repository name (e.g. core)
|
repository(str): pacman repository name (e.g. core)
|
||||||
architecture(str): repository architecture
|
architecture(str): repository architecture
|
||||||
|
|
||||||
@@ -165,12 +164,12 @@ class Pacman(LazyLogging):
|
|||||||
|
|
||||||
return database
|
return database
|
||||||
|
|
||||||
def database_sync(self, handle: PacmanHandle, *, force: bool) -> None:
|
def database_sync(self, handle: Handle, *, force: bool) -> None:
|
||||||
"""
|
"""
|
||||||
sync local database
|
sync local database
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
handle(PacmanHandle): pacman handle which will be used for database sync
|
handle(Handle): pacman handle which will be used for database sync
|
||||||
force(bool): force database synchronization (same as ``pacman -Syy``)
|
force(bool): force database synchronization (same as ``pacman -Syy``)
|
||||||
"""
|
"""
|
||||||
self.logger.info("refresh ahriman's home pacman database (force refresh %s)", force)
|
self.logger.info("refresh ahriman's home pacman database (force refresh %s)", force)
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
#
|
|
||||||
# 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 pathlib import Path
|
|
||||||
from pyalpm import Handle, Package # type: ignore[import-not-found]
|
|
||||||
from tempfile import TemporaryDirectory
|
|
||||||
from typing import Any, ClassVar, Self
|
|
||||||
|
|
||||||
|
|
||||||
class PacmanHandle:
|
|
||||||
"""
|
|
||||||
lightweight wrapper for pacman handle to be used for direct alpm operations (e.g. package load)
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
handle(Handle): pyalpm handle instance
|
|
||||||
"""
|
|
||||||
|
|
||||||
_ephemeral: ClassVar[Self | None] = None
|
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
||||||
"""
|
|
||||||
Args:
|
|
||||||
*args(Any): positional arguments for :class:`pyalpm.Handle`
|
|
||||||
**kwargs(Any): keyword arguments for :class:`pyalpm.Handle`
|
|
||||||
"""
|
|
||||||
self.handle = Handle(*args, **kwargs)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def ephemeral(cls) -> Self:
|
|
||||||
"""
|
|
||||||
create temporary instance with no access to real databases
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Self: loaded class
|
|
||||||
"""
|
|
||||||
if cls._ephemeral is None:
|
|
||||||
# handle creates alpm version file, but we don't use it
|
|
||||||
# so it is ok to just remove it
|
|
||||||
with TemporaryDirectory(ignore_cleanup_errors=True) as dir_name:
|
|
||||||
cls._ephemeral = cls("/", dir_name)
|
|
||||||
return cls._ephemeral
|
|
||||||
|
|
||||||
def package_load(self, path: Path) -> Package:
|
|
||||||
"""
|
|
||||||
load package from path to the archive
|
|
||||||
|
|
||||||
Args:
|
|
||||||
path(Path): path to package archive
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Package: package instance
|
|
||||||
"""
|
|
||||||
return self.handle.load_pkg(str(path))
|
|
||||||
|
|
||||||
def __getattr__(self, item: str) -> Any:
|
|
||||||
"""
|
|
||||||
proxy methods for :class:`pyalpm.Handle`, because it doesn't allow subclassing
|
|
||||||
|
|
||||||
Args:
|
|
||||||
item(str): property name
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Any: attribute by its name
|
|
||||||
"""
|
|
||||||
return self.handle.__getattribute__(item)
|
|
||||||
@@ -26,7 +26,6 @@ from typing import ClassVar
|
|||||||
from ahriman.core.exceptions import CalledProcessError
|
from ahriman.core.exceptions import CalledProcessError
|
||||||
from ahriman.core.log import LazyLogging
|
from ahriman.core.log import LazyLogging
|
||||||
from ahriman.core.utils import check_output, utcnow, walk
|
from ahriman.core.utils import check_output, utcnow, walk
|
||||||
from ahriman.models.changes import Changes
|
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.pkgbuild import Pkgbuild
|
from ahriman.models.pkgbuild import Pkgbuild
|
||||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||||
@@ -52,25 +51,24 @@ class Sources(LazyLogging):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def changes(source_dir: Path, last_commit_sha: str) -> Changes:
|
def changes(source_dir: Path, last_commit_sha: str | None) -> str | None:
|
||||||
"""
|
"""
|
||||||
extract changes from the last known commit if available
|
extract changes from the last known commit if available
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
source_dir(Path): local path to directory with source files
|
source_dir(Path): local path to directory with source files
|
||||||
last_commit_sha(str): last known commit hash
|
last_commit_sha(str | None): last known commit hash
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Changes: changes from the last commit if available
|
str | None: changes from the last commit if available or ``None`` otherwise
|
||||||
"""
|
"""
|
||||||
|
if last_commit_sha is None:
|
||||||
|
return None # no previous reference found
|
||||||
|
|
||||||
instance = Sources()
|
instance = Sources()
|
||||||
|
|
||||||
diff = None
|
|
||||||
if instance.fetch_until(source_dir, commit_sha=last_commit_sha) is not None:
|
if instance.fetch_until(source_dir, commit_sha=last_commit_sha) is not None:
|
||||||
diff = instance.diff(source_dir, last_commit_sha)
|
return instance.diff(source_dir, last_commit_sha)
|
||||||
pkgbuild = instance.read(source_dir, "HEAD", Path("PKGBUILD"))
|
return None
|
||||||
|
|
||||||
return Changes(last_commit_sha, diff, pkgbuild)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extend_architectures(sources_dir: Path, architecture: str) -> list[PkgbuildPatch]:
|
def extend_architectures(sources_dir: Path, architecture: str) -> list[PkgbuildPatch]:
|
||||||
@@ -415,17 +413,3 @@ class Sources(LazyLogging):
|
|||||||
cwd=sources_dir, input_data=patch.serialize(), logger=self.logger)
|
cwd=sources_dir, input_data=patch.serialize(), logger=self.logger)
|
||||||
else:
|
else:
|
||||||
patch.write(sources_dir / "PKGBUILD")
|
patch.write(sources_dir / "PKGBUILD")
|
||||||
|
|
||||||
def read(self, sources_dir: Path, commit_sha: str, path: Path) -> str:
|
|
||||||
"""
|
|
||||||
read file content from the specified commit
|
|
||||||
|
|
||||||
Args:
|
|
||||||
sources_dir(Path): local path to git repository
|
|
||||||
commit_sha(str): commit hash to read from
|
|
||||||
path(Path): path to file inside the repository
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: file content at specified commit
|
|
||||||
"""
|
|
||||||
return check_output(*self.git(), "show", f"{commit_sha}:{path}", cwd=sources_dir, logger=self.logger)
|
|
||||||
|
|||||||
@@ -19,9 +19,11 @@
|
|||||||
#
|
#
|
||||||
from sqlite3 import Connection
|
from sqlite3 import Connection
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.utils import package_like
|
from ahriman.core.utils import package_like
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["migrate_data", "steps"]
|
__all__ = ["migrate_data", "steps"]
|
||||||
@@ -59,9 +61,12 @@ def migrate_package_depends(connection: Connection, configuration: Configuration
|
|||||||
if not configuration.repository_paths.repository.is_dir():
|
if not configuration.repository_paths.repository.is_dir():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
_, repository_id = configuration.check_loaded()
|
||||||
|
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
package_list = []
|
package_list = []
|
||||||
for full_path in filter(package_like, configuration.repository_paths.repository.iterdir()):
|
for full_path in filter(package_like, configuration.repository_paths.repository.iterdir()):
|
||||||
base = Package.from_archive(full_path)
|
base = Package.from_archive(full_path, pacman)
|
||||||
for package, description in base.packages.items():
|
for package, description in base.packages.items():
|
||||||
package_list.append({
|
package_list.append({
|
||||||
"make_depends": description.make_depends,
|
"make_depends": description.make_depends,
|
||||||
|
|||||||
@@ -19,9 +19,11 @@
|
|||||||
#
|
#
|
||||||
from sqlite3 import Connection
|
from sqlite3 import Connection
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.utils import package_like
|
from ahriman.core.utils import package_like
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["migrate_data", "steps"]
|
__all__ = ["migrate_data", "steps"]
|
||||||
@@ -56,9 +58,12 @@ def migrate_package_check_depends(connection: Connection, configuration: Configu
|
|||||||
if not configuration.repository_paths.repository.is_dir():
|
if not configuration.repository_paths.repository.is_dir():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
_, repository_id = configuration.check_loaded()
|
||||||
|
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
package_list = []
|
package_list = []
|
||||||
for full_path in filter(package_like, configuration.repository_paths.repository.iterdir()):
|
for full_path in filter(package_like, configuration.repository_paths.repository.iterdir()):
|
||||||
base = Package.from_archive(full_path)
|
base = Package.from_archive(full_path, pacman)
|
||||||
for package, description in base.packages.items():
|
for package, description in base.packages.items():
|
||||||
package_list.append({
|
package_list.append({
|
||||||
"check_depends": description.check_depends,
|
"check_depends": description.check_depends,
|
||||||
|
|||||||
@@ -19,9 +19,11 @@
|
|||||||
#
|
#
|
||||||
from sqlite3 import Connection
|
from sqlite3 import Connection
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.utils import package_like
|
from ahriman.core.utils import package_like
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["migrate_data", "steps"]
|
__all__ = ["migrate_data", "steps"]
|
||||||
@@ -62,9 +64,12 @@ def migrate_package_base_packager(connection: Connection, configuration: Configu
|
|||||||
if not configuration.repository_paths.repository.is_dir():
|
if not configuration.repository_paths.repository.is_dir():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
_, repository_id = configuration.check_loaded()
|
||||||
|
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
package_list = []
|
package_list = []
|
||||||
for full_path in filter(package_like, configuration.repository_paths.repository.iterdir()):
|
for full_path in filter(package_like, configuration.repository_paths.repository.iterdir()):
|
||||||
package = Package.from_archive(full_path)
|
package = Package.from_archive(full_path, pacman)
|
||||||
package_list.append({
|
package_list.append({
|
||||||
"package_base": package.base,
|
"package_base": package.base,
|
||||||
"packager": package.packager,
|
"packager": package.packager,
|
||||||
|
|||||||
@@ -20,11 +20,13 @@
|
|||||||
from dataclasses import replace
|
from dataclasses import replace
|
||||||
from sqlite3 import Connection
|
from sqlite3 import Connection
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.repository import Explorer
|
from ahriman.core.repository import Explorer
|
||||||
from ahriman.core.sign.gpg import GPG
|
from ahriman.core.sign.gpg import GPG
|
||||||
from ahriman.core.utils import atomic_move, package_like, symlink_relative
|
from ahriman.core.utils import atomic_move, package_like, symlink_relative
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||||
from ahriman.models.repository_paths import RepositoryPaths
|
from ahriman.models.repository_paths import RepositoryPaths
|
||||||
|
|
||||||
|
|
||||||
@@ -43,27 +45,29 @@ def migrate_data(connection: Connection, configuration: Configuration) -> None:
|
|||||||
|
|
||||||
for repository_id in Explorer.repositories_extract(configuration):
|
for repository_id in Explorer.repositories_extract(configuration):
|
||||||
paths = replace(configuration.repository_paths, repository_id=repository_id)
|
paths = replace(configuration.repository_paths, repository_id=repository_id)
|
||||||
|
pacman = Pacman(repository_id, configuration, refresh_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
# create archive directory if required
|
# create archive directory if required
|
||||||
if not paths.archive.is_dir():
|
if not paths.archive.is_dir():
|
||||||
with paths.preserve_owner():
|
with paths.preserve_owner():
|
||||||
paths.archive.mkdir(mode=0o755, parents=True)
|
paths.archive.mkdir(mode=0o755, parents=True)
|
||||||
|
|
||||||
move_packages(paths)
|
move_packages(paths, pacman)
|
||||||
|
|
||||||
|
|
||||||
def move_packages(repository_paths: RepositoryPaths) -> None:
|
def move_packages(repository_paths: RepositoryPaths, pacman: Pacman) -> None:
|
||||||
"""
|
"""
|
||||||
move packages from repository to archive and create symbolic links
|
move packages from repository to archive and create symbolic links
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
repository_paths(RepositoryPaths): repository paths instance
|
repository_paths(RepositoryPaths): repository paths instance
|
||||||
|
pacman(Pacman): alpm wrapper instance
|
||||||
"""
|
"""
|
||||||
for archive in filter(package_like, repository_paths.repository.iterdir()):
|
for archive in filter(package_like, repository_paths.repository.iterdir()):
|
||||||
if not archive.is_file(follow_symlinks=False):
|
if not archive.is_file(follow_symlinks=False):
|
||||||
continue # skip symbolic links if any
|
continue # skip symbolic links if any
|
||||||
|
|
||||||
package = Package.from_archive(archive)
|
package = Package.from_archive(archive, pacman)
|
||||||
artifacts = [archive]
|
artifacts = [archive]
|
||||||
# check if there are signatures for this package and append it here too
|
# check if there are signatures for this package and append it here too
|
||||||
if (signature := GPG.signature(archive)).exists():
|
if (signature := GPG.signature(archive)).exists():
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
#
|
|
||||||
# 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/>.
|
|
||||||
#
|
|
||||||
__all__ = ["steps"]
|
|
||||||
|
|
||||||
|
|
||||||
steps = [
|
|
||||||
"""alter table package_changes add column pkgbuild text""",
|
|
||||||
]
|
|
||||||
@@ -45,10 +45,10 @@ class ChangesOperations(Operations):
|
|||||||
def run(connection: Connection) -> Changes:
|
def run(connection: Connection) -> Changes:
|
||||||
return next(
|
return next(
|
||||||
(
|
(
|
||||||
Changes(row["last_commit_sha"], row["changes"] or None, row["pkgbuild"] or None)
|
Changes(row["last_commit_sha"], row["changes"] or None)
|
||||||
for row in connection.execute(
|
for row in connection.execute(
|
||||||
"""
|
"""
|
||||||
select last_commit_sha, changes, pkgbuild from package_changes
|
select last_commit_sha, changes from package_changes
|
||||||
where package_base = :package_base and repository = :repository
|
where package_base = :package_base and repository = :repository
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
@@ -77,17 +77,16 @@ class ChangesOperations(Operations):
|
|||||||
connection.execute(
|
connection.execute(
|
||||||
"""
|
"""
|
||||||
insert into package_changes
|
insert into package_changes
|
||||||
(package_base, last_commit_sha, changes, pkgbuild, repository)
|
(package_base, last_commit_sha, changes, repository)
|
||||||
values
|
values
|
||||||
(:package_base, :last_commit_sha, :changes, :pkgbuild, :repository)
|
(:package_base, :last_commit_sha, :changes ,:repository)
|
||||||
on conflict (package_base, repository) do update set
|
on conflict (package_base, repository) do update set
|
||||||
last_commit_sha = :last_commit_sha, changes = :changes, pkgbuild = :pkgbuild
|
last_commit_sha = :last_commit_sha, changes = :changes
|
||||||
""",
|
""",
|
||||||
{
|
{
|
||||||
"package_base": package_base,
|
"package_base": package_base,
|
||||||
"last_commit_sha": changes.last_commit_sha,
|
"last_commit_sha": changes.last_commit_sha,
|
||||||
"changes": changes.changes,
|
"changes": changes.changes,
|
||||||
"pkgbuild": changes.pkgbuild,
|
|
||||||
"repository": repository_id.id,
|
"repository": repository_id.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ from ahriman.core.formatters.event_stats_printer import EventStatsPrinter
|
|||||||
from ahriman.core.formatters.package_printer import PackagePrinter
|
from ahriman.core.formatters.package_printer import PackagePrinter
|
||||||
from ahriman.core.formatters.package_stats_printer import PackageStatsPrinter
|
from ahriman.core.formatters.package_stats_printer import PackageStatsPrinter
|
||||||
from ahriman.core.formatters.patch_printer import PatchPrinter
|
from ahriman.core.formatters.patch_printer import PatchPrinter
|
||||||
from ahriman.core.formatters.pkgbuild_printer import PkgbuildPrinter
|
|
||||||
from ahriman.core.formatters.printer import Printer
|
from ahriman.core.formatters.printer import Printer
|
||||||
from ahriman.core.formatters.repository_printer import RepositoryPrinter
|
from ahriman.core.formatters.repository_printer import RepositoryPrinter
|
||||||
from ahriman.core.formatters.repository_stats_printer import RepositoryStatsPrinter
|
from ahriman.core.formatters.repository_stats_printer import RepositoryStatsPrinter
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class ChangesPrinter(Printer):
|
|||||||
Returns:
|
Returns:
|
||||||
list[Property]: list of content properties
|
list[Property]: list of content properties
|
||||||
"""
|
"""
|
||||||
if self.changes.changes is None:
|
if self.changes.is_empty:
|
||||||
return []
|
return []
|
||||||
return [Property("", self.changes.changes, is_required=True, indent=0)]
|
return [Property("", self.changes.changes, is_required=True, indent=0)]
|
||||||
|
|
||||||
@@ -57,6 +57,6 @@ class ChangesPrinter(Printer):
|
|||||||
Returns:
|
Returns:
|
||||||
str | None: content title if it can be generated and ``None`` otherwise
|
str | None: content title if it can be generated and ``None`` otherwise
|
||||||
"""
|
"""
|
||||||
if self.changes.changes is None:
|
if self.changes.is_empty:
|
||||||
return None
|
return None
|
||||||
return self.changes.last_commit_sha
|
return self.changes.last_commit_sha
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
#
|
|
||||||
# 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.formatters.printer import Printer
|
|
||||||
from ahriman.models.changes import Changes
|
|
||||||
from ahriman.models.property import Property
|
|
||||||
|
|
||||||
|
|
||||||
class PkgbuildPrinter(Printer):
|
|
||||||
"""
|
|
||||||
print content of the pkgbuild stored in changes
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
changes(Changes): package changes
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, changes: Changes) -> None:
|
|
||||||
"""
|
|
||||||
Args:
|
|
||||||
changes(Changes): package changes
|
|
||||||
"""
|
|
||||||
Printer.__init__(self)
|
|
||||||
self.changes = changes
|
|
||||||
|
|
||||||
def properties(self) -> list[Property]:
|
|
||||||
"""
|
|
||||||
convert content into printable data
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[Property]: list of content properties
|
|
||||||
"""
|
|
||||||
if self.changes.pkgbuild is None:
|
|
||||||
return []
|
|
||||||
return [Property("", self.changes.pkgbuild, is_required=True, indent=0)]
|
|
||||||
|
|
||||||
# pylint: disable=redundant-returns-doc
|
|
||||||
def title(self) -> str | None:
|
|
||||||
"""
|
|
||||||
generate entry title from content
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str | None: content title if it can be generated and ``None`` otherwise
|
|
||||||
"""
|
|
||||||
if self.changes.pkgbuild is None:
|
|
||||||
return None
|
|
||||||
return self.changes.last_commit_sha
|
|
||||||
@@ -17,10 +17,14 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
from collections.abc import Callable
|
||||||
|
from functools import cmp_to_key
|
||||||
|
|
||||||
from ahriman.core import context
|
from ahriman.core import context
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.repository import Repository
|
|
||||||
from ahriman.core.triggers import Trigger
|
from ahriman.core.triggers import Trigger
|
||||||
|
from ahriman.core.utils import package_like
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.repository_id import RepositoryId
|
from ahriman.models.repository_id import RepositoryId
|
||||||
from ahriman.models.result import Result
|
from ahriman.models.result import Result
|
||||||
@@ -74,20 +78,27 @@ class ArchiveRotationTrigger(Trigger):
|
|||||||
"""
|
"""
|
||||||
return list(cls.CONFIGURATION_SCHEMA.keys())
|
return list(cls.CONFIGURATION_SCHEMA.keys())
|
||||||
|
|
||||||
def archives_remove(self, package: Package, repository: Repository) -> None:
|
def archives_remove(self, package: Package, pacman: Pacman) -> None:
|
||||||
"""
|
"""
|
||||||
remove older versions of the specified package
|
remove older versions of the specified package
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package(Package): package which has been updated to check for older versions
|
package(Package): package which has been updated to check for older versions
|
||||||
repository(Repository): repository instance
|
pacman(Pacman): alpm wrapper instance
|
||||||
"""
|
"""
|
||||||
# explicit guard to skip process in case if rotation is disabled
|
# explicit guard to skip process in case if rotation is disabled
|
||||||
# this guard is supposed to speedup process
|
# this guard is supposed to speedup process
|
||||||
if self.keep_built_packages == 0:
|
if self.keep_built_packages == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
to_remove = repository.package_archives(package.base)
|
packages: dict[tuple[str, str], Package] = {}
|
||||||
|
# we can't use here load_archives, because it ignores versions
|
||||||
|
for full_path in filter(package_like, self.paths.archive_for(package.base).iterdir()):
|
||||||
|
local = Package.from_archive(full_path, pacman)
|
||||||
|
packages.setdefault((local.base, local.version), local).packages.update(local.packages)
|
||||||
|
|
||||||
|
comparator: Callable[[Package, Package], int] = lambda left, right: left.vercmp(right.version)
|
||||||
|
to_remove = sorted(packages.values(), key=cmp_to_key(comparator))
|
||||||
|
|
||||||
for single in to_remove[:-self.keep_built_packages]:
|
for single in to_remove[:-self.keep_built_packages]:
|
||||||
self.logger.info("removing version %s of package %s", single.version, single.base)
|
self.logger.info("removing version %s of package %s", single.version, single.base)
|
||||||
@@ -104,7 +115,7 @@ class ArchiveRotationTrigger(Trigger):
|
|||||||
packages(list[Package]): list of all available packages
|
packages(list[Package]): list of all available packages
|
||||||
"""
|
"""
|
||||||
ctx = context.get()
|
ctx = context.get()
|
||||||
repository = ctx.get(Repository)
|
pacman = ctx.get(Pacman)
|
||||||
|
|
||||||
for package in result.success:
|
for package in result.success:
|
||||||
self.archives_remove(package, repository)
|
self.archives_remove(package, pacman)
|
||||||
|
|||||||
@@ -57,15 +57,16 @@ class Executor(PackageInfo, Cleaner):
|
|||||||
|
|
||||||
for path in filter(package_like, archive.iterdir()):
|
for path in filter(package_like, archive.iterdir()):
|
||||||
# check if package version is the same
|
# check if package version is the same
|
||||||
built = Package.from_archive(path)
|
built = Package.from_archive(path, self.pacman)
|
||||||
if built.version != package.version:
|
if built.version != package.version:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
packages = built.packages.values()
|
||||||
# all packages must be either any or same architecture
|
# all packages must be either any or same architecture
|
||||||
if not built.supports_architecture(self.repository_id.architecture):
|
if not all(single.architecture in ("any", self.architecture) for single in packages):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return list_flatmap(built.packages.values(), lambda single: archive.glob(f"{single.filename}*"))
|
return list_flatmap(packages, lambda single: archive.glob(f"{single.filename}*"))
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -101,11 +102,11 @@ class Executor(PackageInfo, Cleaner):
|
|||||||
"""
|
"""
|
||||||
self.reporter.set_building(package.base)
|
self.reporter.set_building(package.base)
|
||||||
|
|
||||||
task = Task(package, self.configuration, self.repository_id.architecture, self.paths)
|
task = Task(package, self.configuration, self.architecture, self.paths)
|
||||||
patches = self.reporter.package_patches_get(package.base, None)
|
patches = self.reporter.package_patches_get(package.base, None)
|
||||||
commit_sha = task.init(path, patches, local_version)
|
commit_sha = task.init(path, patches, local_version)
|
||||||
|
|
||||||
loaded_package = Package.from_build(path, self.repository_id.architecture, None)
|
loaded_package = Package.from_build(path, self.architecture, None)
|
||||||
if prebuilt := list(self._archive_lookup(loaded_package)):
|
if prebuilt := list(self._archive_lookup(loaded_package)):
|
||||||
self.logger.info("using prebuilt packages for %s-%s", loaded_package.base, loaded_package.version)
|
self.logger.info("using prebuilt packages for %s-%s", loaded_package.base, loaded_package.version)
|
||||||
built = []
|
built = []
|
||||||
@@ -116,7 +117,7 @@ class Executor(PackageInfo, Cleaner):
|
|||||||
else:
|
else:
|
||||||
built = task.build(path, PACKAGER=packager)
|
built = task.build(path, PACKAGER=packager)
|
||||||
|
|
||||||
package.with_packages(built)
|
package.with_packages(built, self.pacman)
|
||||||
for src in built:
|
for src in built:
|
||||||
dst = self.paths.packages / src.name
|
dst = self.paths.packages / src.name
|
||||||
atomic_move(src, dst)
|
atomic_move(src, dst)
|
||||||
@@ -203,8 +204,7 @@ class Executor(PackageInfo, Cleaner):
|
|||||||
|
|
||||||
# update commit hash for changes keeping current diff if there is any
|
# update commit hash for changes keeping current diff if there is any
|
||||||
changes = self.reporter.package_changes_get(single.base)
|
changes = self.reporter.package_changes_get(single.base)
|
||||||
self.reporter.package_changes_update(
|
self.reporter.package_changes_update(single.base, Changes(commit_sha, changes.changes))
|
||||||
single.base, Changes(commit_sha, changes.changes, changes.pkgbuild))
|
|
||||||
|
|
||||||
# update dependencies list
|
# update dependencies list
|
||||||
package_archive = PackageArchive(self.paths.build_root, single, self.pacman, self.scan_paths)
|
package_archive = PackageArchive(self.paths.build_root, single, self.pacman, self.scan_paths)
|
||||||
@@ -217,7 +217,7 @@ class Executor(PackageInfo, Cleaner):
|
|||||||
except Exception:
|
except Exception:
|
||||||
self.reporter.set_failed(single.base)
|
self.reporter.set_failed(single.base)
|
||||||
result.add_failed(single)
|
result.add_failed(single)
|
||||||
self.logger.exception("%s (%s) build exception", single.base, self.repository_id.architecture)
|
self.logger.exception("%s (%s) build exception", single.base, self.architecture)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -19,39 +19,23 @@
|
|||||||
#
|
#
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Iterable
|
||||||
from functools import cmp_to_key
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
from ahriman.core.alpm.pacman import Pacman
|
|
||||||
from ahriman.core.build_tools.package_version import PackageVersion
|
from ahriman.core.build_tools.package_version import PackageVersion
|
||||||
from ahriman.core.build_tools.sources import Sources
|
from ahriman.core.build_tools.sources import Sources
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.repository.repository_properties import RepositoryProperties
|
||||||
from ahriman.core.log import LazyLogging
|
|
||||||
from ahriman.core.status import Client
|
|
||||||
from ahriman.core.utils import package_like
|
from ahriman.core.utils import package_like
|
||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.repository_id import RepositoryId
|
|
||||||
|
|
||||||
|
|
||||||
class PackageInfo(LazyLogging):
|
class PackageInfo(RepositoryProperties):
|
||||||
"""
|
"""
|
||||||
handler for the package information
|
handler for the package information
|
||||||
|
|
||||||
Attributes:
|
|
||||||
configuration(Configuration): configuration instance
|
|
||||||
pacman(Pacman): alpm wrapper instance
|
|
||||||
reporter(Client): build status reporter instance
|
|
||||||
repository_id(RepositoryId): repository unique identifier
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
configuration: Configuration
|
|
||||||
pacman: Pacman
|
|
||||||
reporter: Client
|
|
||||||
repository_id: RepositoryId
|
|
||||||
|
|
||||||
def full_depends(self, package: Package, packages: Iterable[Package]) -> list[str]:
|
def full_depends(self, package: Package, packages: Iterable[Package]) -> list[str]:
|
||||||
"""
|
"""
|
||||||
generate full dependencies list including transitive dependencies
|
generate full dependencies list including transitive dependencies
|
||||||
@@ -102,7 +86,7 @@ class PackageInfo(LazyLogging):
|
|||||||
# we are iterating over bases, not single packages
|
# we are iterating over bases, not single packages
|
||||||
for full_path in packages:
|
for full_path in packages:
|
||||||
try:
|
try:
|
||||||
local = Package.from_archive(full_path)
|
local = Package.from_archive(full_path, self.pacman)
|
||||||
if (source := sources.get(local.base)) is not None: # update source with remote
|
if (source := sources.get(local.base)) is not None: # update source with remote
|
||||||
local.remote = source
|
local.remote = source
|
||||||
|
|
||||||
@@ -118,50 +102,27 @@ class PackageInfo(LazyLogging):
|
|||||||
self.logger.exception("could not load package from %s", full_path)
|
self.logger.exception("could not load package from %s", full_path)
|
||||||
return list(result.values())
|
return list(result.values())
|
||||||
|
|
||||||
def package_archives(self, package_base: str) -> list[Package]:
|
def package_changes(self, package: Package, last_commit_sha: str | None) -> Changes:
|
||||||
"""
|
|
||||||
load list of packages known for this package base. This method unlike
|
|
||||||
:func:`ahriman.core.repository.package_info.PackageInfo.load_archives` scans archive directory and loads all
|
|
||||||
versions available for the ``package_base``
|
|
||||||
|
|
||||||
Args:
|
|
||||||
package_base(str): package base
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[Package]: list of packages belonging to this base, sorted by version by ascension
|
|
||||||
"""
|
|
||||||
paths = self.configuration.repository_paths
|
|
||||||
|
|
||||||
packages: dict[tuple[str, str], Package] = {}
|
|
||||||
# we can't use here load_archives, because it ignores versions
|
|
||||||
for full_path in filter(package_like, paths.archive_for(package_base).iterdir()):
|
|
||||||
local = Package.from_archive(full_path)
|
|
||||||
if not local.supports_architecture(self.repository_id.architecture):
|
|
||||||
continue
|
|
||||||
packages.setdefault((local.base, local.version), local).packages.update(local.packages)
|
|
||||||
|
|
||||||
comparator: Callable[[Package, Package], int] = lambda left, right: left.vercmp(right.version)
|
|
||||||
return sorted(packages.values(), key=cmp_to_key(comparator))
|
|
||||||
|
|
||||||
def package_changes(self, package: Package, last_commit_sha: str) -> Changes | None:
|
|
||||||
"""
|
"""
|
||||||
extract package change for the package since last commit if available
|
extract package change for the package since last commit if available
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
package(Package): package properties
|
package(Package): package properties
|
||||||
last_commit_sha(str): last known commit hash
|
last_commit_sha(str | None): last known commit hash
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Changes | None: changes if available
|
Changes: changes if available
|
||||||
"""
|
"""
|
||||||
with TemporaryDirectory(ignore_cleanup_errors=True) as dir_name:
|
with TemporaryDirectory(ignore_cleanup_errors=True) as dir_name:
|
||||||
dir_path = Path(dir_name)
|
dir_path = Path(dir_name)
|
||||||
patches = self.reporter.package_patches_get(package.base, None)
|
patches = self.reporter.package_patches_get(package.base, None)
|
||||||
current_commit_sha = Sources.load(dir_path, package, patches, self.configuration.repository_paths)
|
current_commit_sha = Sources.load(dir_path, package, patches, self.paths)
|
||||||
|
|
||||||
|
changes: str | None = None
|
||||||
if current_commit_sha != last_commit_sha:
|
if current_commit_sha != last_commit_sha:
|
||||||
return Sources.changes(dir_path, last_commit_sha)
|
changes = Sources.changes(dir_path, last_commit_sha)
|
||||||
return None
|
|
||||||
|
return Changes(last_commit_sha, changes)
|
||||||
|
|
||||||
def packages(self, filter_packages: Iterable[str] | None = None) -> list[Package]:
|
def packages(self, filter_packages: Iterable[str] | None = None) -> list[Package]:
|
||||||
"""
|
"""
|
||||||
@@ -173,7 +134,7 @@ class PackageInfo(LazyLogging):
|
|||||||
Returns:
|
Returns:
|
||||||
list[Package]: list of packages properties
|
list[Package]: list of packages properties
|
||||||
"""
|
"""
|
||||||
packages = self.load_archives(filter(package_like, self.configuration.repository_paths.repository.iterdir()))
|
packages = self.load_archives(filter(package_like, self.paths.repository.iterdir()))
|
||||||
if filter_packages:
|
if filter_packages:
|
||||||
packages = [package for package in packages if package.base in filter_packages]
|
packages = [package for package in packages if package.base in filter_packages]
|
||||||
|
|
||||||
@@ -186,7 +147,7 @@ class PackageInfo(LazyLogging):
|
|||||||
Returns:
|
Returns:
|
||||||
list[Path]: list of filenames from the directory
|
list[Path]: list of filenames from the directory
|
||||||
"""
|
"""
|
||||||
return list(filter(package_like, self.configuration.repository_paths.packages.iterdir()))
|
return list(filter(package_like, self.paths.packages.iterdir()))
|
||||||
|
|
||||||
def packages_depend_on(self, packages: list[Package], depends_on: Iterable[str] | None) -> list[Package]:
|
def packages_depend_on(self, packages: list[Package], depends_on: Iterable[str] | None) -> list[Package]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -72,12 +72,32 @@ class RepositoryProperties(EventLogger, LazyLogging):
|
|||||||
self.ignore_list = configuration.getlist("build", "ignore_packages", fallback=[])
|
self.ignore_list = configuration.getlist("build", "ignore_packages", fallback=[])
|
||||||
self.pacman = Pacman(repository_id, configuration, refresh_database=refresh_pacman_database)
|
self.pacman = Pacman(repository_id, configuration, refresh_database=refresh_pacman_database)
|
||||||
self.sign = GPG(configuration)
|
self.sign = GPG(configuration)
|
||||||
self.repo = Repo(self.repository_id.name, self.paths, self.sign.repository_sign_args)
|
self.repo = Repo(self.name, self.paths, self.sign.repository_sign_args)
|
||||||
self.reporter = Client.load(repository_id, configuration, database, report=report)
|
self.reporter = Client.load(repository_id, configuration, database, report=report)
|
||||||
self.triggers = TriggerLoader.load(repository_id, configuration)
|
self.triggers = TriggerLoader.load(repository_id, configuration)
|
||||||
|
|
||||||
self.scan_paths = ScanPaths(configuration.getlist("build", "scan_paths", fallback=[]))
|
self.scan_paths = ScanPaths(configuration.getlist("build", "scan_paths", fallback=[]))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def architecture(self) -> str:
|
||||||
|
"""
|
||||||
|
repository architecture for backward compatibility
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: repository architecture
|
||||||
|
"""
|
||||||
|
return self.repository_id.architecture
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
"""
|
||||||
|
repository name for backward compatibility
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: repository name
|
||||||
|
"""
|
||||||
|
return self.repository_id.name
|
||||||
|
|
||||||
def packager(self, packagers: Packagers, package_base: str) -> User:
|
def packager(self, packagers: Packagers, package_base: str) -> User:
|
||||||
"""
|
"""
|
||||||
extract packager from configuration having username
|
extract packager from configuration having username
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
|||||||
)
|
)
|
||||||
|
|
||||||
Sources.fetch(cache_dir, source)
|
Sources.fetch(cache_dir, source)
|
||||||
remote = Package.from_build(cache_dir, self.repository_id.architecture, None)
|
remote = Package.from_build(cache_dir, self.architecture, None)
|
||||||
|
|
||||||
local = packages.get(remote.base)
|
local = packages.get(remote.base)
|
||||||
if local is None:
|
if local is None:
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ from typing import Any, Self
|
|||||||
|
|
||||||
from ahriman.core.exceptions import UnknownPackageError
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
from ahriman.core.log import LazyLogging
|
from ahriman.core.log import LazyLogging
|
||||||
from ahriman.core.repository.package_info import PackageInfo
|
|
||||||
from ahriman.core.status import Client
|
from ahriman.core.status import Client
|
||||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
@@ -40,18 +39,15 @@ class Watcher(LazyLogging):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
client(Client): reporter instance
|
client(Client): reporter instance
|
||||||
package_info(PackageInfo): package info instance
|
|
||||||
status(BuildStatus): daemon status
|
status(BuildStatus): daemon status
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, client: Client, package_info: PackageInfo) -> None:
|
def __init__(self, client: Client) -> None:
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
client(Client): reporter instance
|
client(Client): reporter instance
|
||||||
package_info(PackageInfo): package info instance
|
|
||||||
"""
|
"""
|
||||||
self.client = client
|
self.client = client
|
||||||
self.package_info = package_info
|
|
||||||
|
|
||||||
self._lock = Lock()
|
self._lock = Lock()
|
||||||
self._known: dict[str, tuple[Package, BuildStatus]] = {}
|
self._known: dict[str, tuple[Package, BuildStatus]] = {}
|
||||||
@@ -84,18 +80,6 @@ class Watcher(LazyLogging):
|
|||||||
|
|
||||||
logs_rotate: Callable[[int], None]
|
logs_rotate: Callable[[int], None]
|
||||||
|
|
||||||
def package_archives(self, package_base: str) -> list[Package]:
|
|
||||||
"""
|
|
||||||
get known package archives
|
|
||||||
|
|
||||||
Args:
|
|
||||||
package_base(str): package base
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list[Package]: list of built package for this package base
|
|
||||||
"""
|
|
||||||
return self.package_info.package_archives(package_base)
|
|
||||||
|
|
||||||
package_changes_get: Callable[[str], Changes]
|
package_changes_get: Callable[[str], Changes]
|
||||||
|
|
||||||
package_changes_update: Callable[[str, Changes], None]
|
package_changes_update: Callable[[str, Changes], None]
|
||||||
|
|||||||
@@ -31,12 +31,20 @@ class Changes:
|
|||||||
Attributes:
|
Attributes:
|
||||||
last_commit_sha(str | None): last commit hash
|
last_commit_sha(str | None): last commit hash
|
||||||
changes(str | None): package change since the last commit if available
|
changes(str | None): package change since the last commit if available
|
||||||
pkgbuild(str | None): original PKGBUILD content if available
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
last_commit_sha: str | None = None
|
last_commit_sha: str | None = None
|
||||||
changes: str | None = None
|
changes: str | None = None
|
||||||
pkgbuild: str | None = None
|
|
||||||
|
@property
|
||||||
|
def is_empty(self) -> bool:
|
||||||
|
"""
|
||||||
|
validate that changes are not empty
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: ``True`` in case if changes are not set and ``False`` otherwise
|
||||||
|
"""
|
||||||
|
return self.changes is None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, dump: dict[str, Any]) -> Self:
|
def from_json(cls, dump: dict[str, Any]) -> Self:
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ from pyalpm import vercmp # type: ignore[import-not-found]
|
|||||||
from typing import Any, Self
|
from typing import Any, Self
|
||||||
|
|
||||||
from ahriman.core.alpm.pacman import Pacman
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.alpm.pacman_handle import PacmanHandle
|
|
||||||
from ahriman.core.alpm.remote import AUR, Official, OfficialSyncdb
|
from ahriman.core.alpm.remote import AUR, Official, OfficialSyncdb
|
||||||
from ahriman.core.log import LazyLogging
|
from ahriman.core.log import LazyLogging
|
||||||
from ahriman.core.utils import dataclass_view, full_version, list_flatmap, parse_version, srcinfo_property_list
|
from ahriman.core.utils import dataclass_view, full_version, list_flatmap, parse_version, srcinfo_property_list
|
||||||
@@ -137,6 +136,16 @@ class Package(LazyLogging):
|
|||||||
"""
|
"""
|
||||||
return list_flatmap(self.packages.values(), lambda package: package.groups)
|
return list_flatmap(self.packages.values(), lambda package: package.groups)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_single_package(self) -> bool:
|
||||||
|
"""
|
||||||
|
is it possible to transform package base to single package or not
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: true in case if this base has only one package with the same name
|
||||||
|
"""
|
||||||
|
return self.base in self.packages and len(self.packages) == 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_vcs(self) -> bool:
|
def is_vcs(self) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -177,17 +186,18 @@ class Package(LazyLogging):
|
|||||||
return sorted(packages)
|
return sorted(packages)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_archive(cls, path: Path) -> Self:
|
def from_archive(cls, path: Path, pacman: Pacman) -> Self:
|
||||||
"""
|
"""
|
||||||
construct package properties from package archive
|
construct package properties from package archive
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
path(Path): path to package archive
|
path(Path): path to package archive
|
||||||
|
pacman(Pacman): alpm wrapper instance
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Self: package properties
|
Self: package properties
|
||||||
"""
|
"""
|
||||||
package = PacmanHandle.ephemeral().package_load(path)
|
package = pacman.handle.load_pkg(str(path))
|
||||||
description = PackageDescription.from_package(package, path)
|
description = PackageDescription.from_package(package, path)
|
||||||
return cls(
|
return cls(
|
||||||
base=package.base or package.name,
|
base=package.base or package.name,
|
||||||
@@ -365,22 +375,9 @@ class Package(LazyLogging):
|
|||||||
Returns:
|
Returns:
|
||||||
str: print-friendly string
|
str: print-friendly string
|
||||||
"""
|
"""
|
||||||
is_single_package = self.base in self.packages and len(self.packages) == 1
|
details = "" if self.is_single_package else f" ({" ".join(sorted(self.packages.keys()))})"
|
||||||
details = "" if is_single_package else f" ({" ".join(sorted(self.packages.keys()))})"
|
|
||||||
return f"{self.base}{details}"
|
return f"{self.base}{details}"
|
||||||
|
|
||||||
def supports_architecture(self, architecture: str) -> bool:
|
|
||||||
"""
|
|
||||||
helper to check if the package belongs to the specified architecture
|
|
||||||
|
|
||||||
Args:
|
|
||||||
architecture(str): probe repository architecture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: ``True`` if all packages are same architecture or any
|
|
||||||
"""
|
|
||||||
return all(single.architecture in ("any", architecture) for single in self.packages.values())
|
|
||||||
|
|
||||||
def vercmp(self, version: str) -> int:
|
def vercmp(self, version: str) -> int:
|
||||||
"""
|
"""
|
||||||
typed wrapper around :func:`pyalpm.vercmp()`
|
typed wrapper around :func:`pyalpm.vercmp()`
|
||||||
@@ -403,16 +400,17 @@ class Package(LazyLogging):
|
|||||||
"""
|
"""
|
||||||
return dataclass_view(self)
|
return dataclass_view(self)
|
||||||
|
|
||||||
def with_packages(self, packages: Iterable[Path]) -> None:
|
def with_packages(self, packages: Iterable[Path], pacman: Pacman) -> None:
|
||||||
"""
|
"""
|
||||||
replace packages descriptions with ones from archives
|
replace packages descriptions with ones from archives
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
packages(Iterable[Path]): paths to package archives
|
packages(Iterable[Path]): paths to package archives
|
||||||
|
pacman(Pacman): alpm wrapper instance
|
||||||
"""
|
"""
|
||||||
self.packages = {} # reset state
|
self.packages = {} # reset state
|
||||||
for package in packages:
|
for package in packages:
|
||||||
archive = self.from_archive(package)
|
archive = self.from_archive(package, pacman)
|
||||||
if archive.base != self.base:
|
if archive.base != self.base:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,3 @@ class ChangesSchema(Schema):
|
|||||||
"description": "Last recorded commit hash",
|
"description": "Last recorded commit hash",
|
||||||
"example": "f1875edca1eb8fc0e55c41d1cae5fa05b6b7c6",
|
"example": "f1875edca1eb8fc0e55c41d1cae5fa05b6b7c6",
|
||||||
})
|
})
|
||||||
pkgbuild = fields.String(metadata={
|
|
||||||
"description": "Original PKGBUILD content",
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
#
|
|
||||||
# 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 aiohttp.web import Response
|
|
||||||
from typing import ClassVar
|
|
||||||
|
|
||||||
from ahriman.models.user_access import UserAccess
|
|
||||||
from ahriman.web.apispec.decorators import apidocs
|
|
||||||
from ahriman.web.schemas import PackageNameSchema, PackageSchema, RepositoryIdSchema
|
|
||||||
from ahriman.web.views.base import BaseView
|
|
||||||
from ahriman.web.views.status_view_guard import StatusViewGuard
|
|
||||||
|
|
||||||
|
|
||||||
class Archives(StatusViewGuard, BaseView):
|
|
||||||
"""
|
|
||||||
package archives web view
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
GET_PERMISSION(UserAccess): (class attribute) get permissions of self
|
|
||||||
"""
|
|
||||||
|
|
||||||
GET_PERMISSION: ClassVar[UserAccess] = UserAccess.Reporter
|
|
||||||
ROUTES = ["/api/v1/packages/{package}/archives"]
|
|
||||||
|
|
||||||
@apidocs(
|
|
||||||
tags=["Packages"],
|
|
||||||
summary="Get package archives",
|
|
||||||
description="Retrieve built package archives for the base",
|
|
||||||
permission=GET_PERMISSION,
|
|
||||||
error_404_description="Package base and/or repository are unknown",
|
|
||||||
schema=PackageSchema(many=True),
|
|
||||||
match_schema=PackageNameSchema,
|
|
||||||
query_schema=RepositoryIdSchema,
|
|
||||||
)
|
|
||||||
async def get(self) -> Response:
|
|
||||||
"""
|
|
||||||
get package archives
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Response: 200 with package archives on success
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
HTTPNotFound: if no package was found
|
|
||||||
"""
|
|
||||||
package_base = self.request.match_info["package"]
|
|
||||||
|
|
||||||
archives = self.service(package_base=package_base).package_archives(package_base)
|
|
||||||
|
|
||||||
return self.json_response([archive.view() for archive in archives])
|
|
||||||
@@ -92,11 +92,10 @@ class ChangesView(StatusViewGuard, BaseView):
|
|||||||
data = await self.request.json()
|
data = await self.request.json()
|
||||||
last_commit_sha = data.get("last_commit_sha") # empty/null meant removal
|
last_commit_sha = data.get("last_commit_sha") # empty/null meant removal
|
||||||
change = data.get("changes")
|
change = data.get("changes")
|
||||||
pkgbuild = data.get("pkgbuild")
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise HTTPBadRequest(reason=str(ex))
|
raise HTTPBadRequest(reason=str(ex))
|
||||||
|
|
||||||
changes = Changes(last_commit_sha, change, pkgbuild)
|
changes = Changes(last_commit_sha, change)
|
||||||
self.service().package_changes_update(package_base, changes)
|
self.service().package_changes_update(package_base, changes)
|
||||||
|
|
||||||
raise HTTPNoContent
|
raise HTTPNoContent
|
||||||
|
|||||||
@@ -23,14 +23,12 @@ import logging
|
|||||||
import socket
|
import socket
|
||||||
|
|
||||||
from aiohttp.web import Application, normalize_path_middleware, run_app
|
from aiohttp.web import Application, normalize_path_middleware, run_app
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from ahriman.core.auth import Auth
|
from ahriman.core.auth import Auth
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.database import SQLite
|
from ahriman.core.database import SQLite
|
||||||
from ahriman.core.distributed import WorkersCache
|
from ahriman.core.distributed import WorkersCache
|
||||||
from ahriman.core.exceptions import InitializeError
|
from ahriman.core.exceptions import InitializeError
|
||||||
from ahriman.core.repository.package_info import PackageInfo
|
|
||||||
from ahriman.core.spawn import Spawn
|
from ahriman.core.spawn import Spawn
|
||||||
from ahriman.core.status import Client
|
from ahriman.core.status import Client
|
||||||
from ahriman.core.status.watcher import Watcher
|
from ahriman.core.status.watcher import Watcher
|
||||||
@@ -80,34 +78,6 @@ def _create_socket(configuration: Configuration, application: Application) -> so
|
|||||||
return sock
|
return sock
|
||||||
|
|
||||||
|
|
||||||
def _create_watcher(path: Path, repository_id: RepositoryId) -> Watcher:
|
|
||||||
"""
|
|
||||||
build watcher for selected repository
|
|
||||||
|
|
||||||
Args:
|
|
||||||
path(Path): path to configuration file
|
|
||||||
repository_id(RepositoryId): repository unique identifier
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Watcher: watcher instance
|
|
||||||
"""
|
|
||||||
logging.getLogger(__name__).info("load repository %s", repository_id)
|
|
||||||
# load settings explicitly for architecture if any
|
|
||||||
configuration = Configuration.from_path(path, repository_id)
|
|
||||||
|
|
||||||
# load database instance, because it holds identifier
|
|
||||||
database = SQLite.load(configuration)
|
|
||||||
# explicitly load local client
|
|
||||||
client = Client.load(repository_id, configuration, database, report=False)
|
|
||||||
|
|
||||||
# load package info wrapper
|
|
||||||
package_info = PackageInfo()
|
|
||||||
package_info.configuration = configuration
|
|
||||||
package_info.repository_id = repository_id
|
|
||||||
|
|
||||||
return Watcher(client, package_info)
|
|
||||||
|
|
||||||
|
|
||||||
async def _on_shutdown(application: Application) -> None:
|
async def _on_shutdown(application: Application) -> None:
|
||||||
"""
|
"""
|
||||||
web application shutdown handler
|
web application shutdown handler
|
||||||
@@ -198,11 +168,18 @@ def setup_server(configuration: Configuration, spawner: Spawn, repositories: lis
|
|||||||
# package cache
|
# package cache
|
||||||
if not repositories:
|
if not repositories:
|
||||||
raise InitializeError("No repositories configured, exiting")
|
raise InitializeError("No repositories configured, exiting")
|
||||||
|
watchers: dict[RepositoryId, Watcher] = {}
|
||||||
configuration_path, _ = configuration.check_loaded()
|
configuration_path, _ = configuration.check_loaded()
|
||||||
application[WatcherKey] = {
|
for repository_id in repositories:
|
||||||
repository_id: _create_watcher(configuration_path, repository_id)
|
application.logger.info("load repository %s", repository_id)
|
||||||
for repository_id in repositories
|
# load settings explicitly for architecture if any
|
||||||
}
|
repository_configuration = Configuration.from_path(configuration_path, repository_id)
|
||||||
|
# load database instance, because it holds identifier
|
||||||
|
database = SQLite.load(repository_configuration)
|
||||||
|
# explicitly load local client
|
||||||
|
client = Client.load(repository_id, repository_configuration, database, report=False)
|
||||||
|
watchers[repository_id] = Watcher(client)
|
||||||
|
application[WatcherKey] = watchers
|
||||||
# workers cache
|
# workers cache
|
||||||
application[WorkersKey] = WorkersCache(configuration)
|
application[WorkersKey] = WorkersCache(configuration)
|
||||||
# process spawner
|
# process spawner
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ def test_changes(application_repository: ApplicationRepository, package_ahriman:
|
|||||||
"""
|
"""
|
||||||
must generate changes for the packages
|
must generate changes for the packages
|
||||||
"""
|
"""
|
||||||
changes = Changes("sha", "change")
|
changes = Changes("hash", "change")
|
||||||
hashes_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes)
|
hashes_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes)
|
||||||
changes_mock = mocker.patch("ahriman.core.repository.Repository.package_changes", return_value=changes)
|
changes_mock = mocker.patch("ahriman.core.repository.Repository.package_changes", return_value=changes)
|
||||||
report_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
report_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
||||||
@@ -42,20 +42,6 @@ def test_changes_skip(application_repository: ApplicationRepository, package_ahr
|
|||||||
report_mock.assert_not_called()
|
report_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_changes_no_update(application_repository: ApplicationRepository, package_ahriman: Package,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must skip update if package_changes returns None (no new commits)
|
|
||||||
"""
|
|
||||||
changes = Changes("sha", "change")
|
|
||||||
mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes)
|
|
||||||
mocker.patch("ahriman.core.repository.Repository.package_changes", return_value=None)
|
|
||||||
report_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
|
||||||
|
|
||||||
application_repository.changes([package_ahriman])
|
|
||||||
report_mock.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
def test_clean_cache(application_repository: ApplicationRepository, mocker: MockerFixture) -> None:
|
def test_clean_cache(application_repository: ApplicationRepository, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must clean cache directory
|
must clean cache directory
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from pytest_mock import MockerFixture
|
|
||||||
|
|
||||||
from ahriman.application.handlers.archives import Archives
|
|
||||||
from ahriman.core.configuration import Configuration
|
|
||||||
from ahriman.core.database import SQLite
|
|
||||||
from ahriman.core.repository import Repository
|
|
||||||
from ahriman.models.action import Action
|
|
||||||
from ahriman.models.package import Package
|
|
||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
|
||||||
"""
|
|
||||||
default arguments for these test cases
|
|
||||||
|
|
||||||
Args:
|
|
||||||
args(argparse.Namespace): command line arguments fixture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
argparse.Namespace: generated arguments for these test cases
|
|
||||||
"""
|
|
||||||
args.action = Action.List
|
|
||||||
args.exit_code = False
|
|
||||||
args.info = False
|
|
||||||
args.package = "package"
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
def test_run(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
|
||||||
package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must run command
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
|
||||||
application_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives",
|
|
||||||
return_value=[package_ahriman])
|
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
|
||||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Archives.run(args, repository_id, configuration, report=False)
|
|
||||||
application_mock.assert_called_once_with(args.package)
|
|
||||||
check_mock.assert_called_once_with(False, True)
|
|
||||||
print_mock.assert_called_once_with(verbose=False, log_fn=pytest.helpers.anyvar(int), separator=": ")
|
|
||||||
|
|
||||||
|
|
||||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must raise ExitCode exception on empty archives result
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
args.exit_code = True
|
|
||||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
|
||||||
mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives", return_value=[])
|
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Archives.run(args, repository_id, configuration, report=False)
|
|
||||||
check_mock.assert_called_once_with(True, False)
|
|
||||||
|
|
||||||
|
|
||||||
def test_imply_with_report(args: argparse.Namespace, configuration: Configuration, database: SQLite,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must create application object with native reporting
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
|
||||||
load_mock = mocker.patch("ahriman.core.repository.Repository.load")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Archives.run(args, repository_id, configuration, report=False)
|
|
||||||
load_mock.assert_called_once_with(repository_id, configuration, database, report=True, refresh_pacman_database=0)
|
|
||||||
|
|
||||||
|
|
||||||
def test_disallow_multi_architecture_run() -> None:
|
|
||||||
"""
|
|
||||||
must not allow multi architecture run
|
|
||||||
"""
|
|
||||||
assert not Archives.ALLOW_MULTI_ARCHITECTURE_RUN
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from pytest_mock import MockerFixture
|
|
||||||
|
|
||||||
from ahriman.application.handlers.pkgbuild import Pkgbuild
|
|
||||||
from ahriman.core.configuration import Configuration
|
|
||||||
from ahriman.core.database import SQLite
|
|
||||||
from ahriman.core.repository import Repository
|
|
||||||
from ahriman.models.action import Action
|
|
||||||
from ahriman.models.changes import Changes
|
|
||||||
|
|
||||||
|
|
||||||
def _default_args(args: argparse.Namespace) -> argparse.Namespace:
|
|
||||||
"""
|
|
||||||
default arguments for these test cases
|
|
||||||
|
|
||||||
Args:
|
|
||||||
args(argparse.Namespace): command line arguments fixture
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
argparse.Namespace: generated arguments for these test cases
|
|
||||||
"""
|
|
||||||
args.action = Action.List
|
|
||||||
args.exit_code = False
|
|
||||||
args.package = "package"
|
|
||||||
return args
|
|
||||||
|
|
||||||
|
|
||||||
def test_run(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must run command
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
|
||||||
application_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get",
|
|
||||||
return_value=Changes("sha", "change", "pkgbuild content"))
|
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
|
||||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Pkgbuild.run(args, repository_id, configuration, report=False)
|
|
||||||
application_mock.assert_called_once_with(args.package)
|
|
||||||
check_mock.assert_called_once_with(False, True)
|
|
||||||
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator="")
|
|
||||||
|
|
||||||
|
|
||||||
def test_run_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must raise ExitCode exception on empty pkgbuild result
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
args.exit_code = True
|
|
||||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
|
||||||
mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=Changes())
|
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Pkgbuild.run(args, repository_id, configuration, report=False)
|
|
||||||
check_mock.assert_called_once_with(True, False)
|
|
||||||
|
|
||||||
|
|
||||||
def test_run_remove(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must remove package pkgbuild
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
args.action = Action.Remove
|
|
||||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
|
||||||
changes = Changes("sha", "change", "pkgbuild content")
|
|
||||||
mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes)
|
|
||||||
update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Pkgbuild.run(args, repository_id, configuration, report=False)
|
|
||||||
update_mock.assert_called_once_with(args.package, Changes("sha", "change", None))
|
|
||||||
|
|
||||||
|
|
||||||
def test_imply_with_report(args: argparse.Namespace, configuration: Configuration, database: SQLite,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must create application object with native reporting
|
|
||||||
"""
|
|
||||||
args = _default_args(args)
|
|
||||||
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
|
|
||||||
load_mock = mocker.patch("ahriman.core.repository.Repository.load")
|
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
|
||||||
Pkgbuild.run(args, repository_id, configuration, report=False)
|
|
||||||
load_mock.assert_called_once_with(repository_id, configuration, database, report=True, refresh_pacman_database=0)
|
|
||||||
|
|
||||||
|
|
||||||
def test_disallow_multi_architecture_run() -> None:
|
|
||||||
"""
|
|
||||||
must not allow multi architecture run
|
|
||||||
"""
|
|
||||||
assert not Pkgbuild.ALLOW_MULTI_ARCHITECTURE_RUN
|
|
||||||
@@ -271,22 +271,6 @@ def test_subparsers_package_add_option_variable_multiple(parser: argparse.Argume
|
|||||||
assert args.variable == ["var1", "var2"]
|
assert args.variable == ["var1", "var2"]
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_package_archives(parser: argparse.ArgumentParser) -> None:
|
|
||||||
"""
|
|
||||||
package-archives command must imply action, exit code, info, lock, quiet, report and unsafe
|
|
||||||
"""
|
|
||||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-archives", "ahriman"])
|
|
||||||
assert args.action == Action.List
|
|
||||||
assert args.architecture == "x86_64"
|
|
||||||
assert not args.exit_code
|
|
||||||
assert not args.info
|
|
||||||
assert args.lock is None
|
|
||||||
assert args.quiet
|
|
||||||
assert not args.report
|
|
||||||
assert args.repository == "repo"
|
|
||||||
assert args.unsafe
|
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_package_changes(parser: argparse.ArgumentParser) -> None:
|
def test_subparsers_package_changes(parser: argparse.ArgumentParser) -> None:
|
||||||
"""
|
"""
|
||||||
package-changes command must imply action, exit code, lock, quiet, report and unsafe
|
package-changes command must imply action, exit code, lock, quiet, report and unsafe
|
||||||
@@ -325,44 +309,6 @@ def test_subparsers_package_changes_remove_package_changes(parser: argparse.Argu
|
|||||||
assert dir(args) == dir(reference_args)
|
assert dir(args) == dir(reference_args)
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_package_pkgbuild(parser: argparse.ArgumentParser) -> None:
|
|
||||||
"""
|
|
||||||
package-pkgbuild command must imply action, exit code, lock, quiet, report and unsafe
|
|
||||||
"""
|
|
||||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild", "ahriman"])
|
|
||||||
assert args.action == Action.List
|
|
||||||
assert args.architecture == "x86_64"
|
|
||||||
assert not args.exit_code
|
|
||||||
assert args.lock is None
|
|
||||||
assert args.quiet
|
|
||||||
assert not args.report
|
|
||||||
assert args.repository == "repo"
|
|
||||||
assert args.unsafe
|
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_package_pkgbuild_remove(parser: argparse.ArgumentParser) -> None:
|
|
||||||
"""
|
|
||||||
package-pkgbuild-remove command must imply action, lock, quiet, report and unsafe
|
|
||||||
"""
|
|
||||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild-remove", "ahriman"])
|
|
||||||
assert args.action == Action.Remove
|
|
||||||
assert args.architecture == "x86_64"
|
|
||||||
assert args.lock is None
|
|
||||||
assert args.quiet
|
|
||||||
assert not args.report
|
|
||||||
assert args.repository == "repo"
|
|
||||||
assert args.unsafe
|
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_package_pkgbuild_remove_package_pkgbuild(parser: argparse.ArgumentParser) -> None:
|
|
||||||
"""
|
|
||||||
package-pkgbuild-remove must have same keys as package-pkgbuild
|
|
||||||
"""
|
|
||||||
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild-remove", "ahriman"])
|
|
||||||
reference_args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild", "ahriman"])
|
|
||||||
assert dir(args) == dir(reference_args)
|
|
||||||
|
|
||||||
|
|
||||||
def test_subparsers_package_copy_option_architecture(parser: argparse.ArgumentParser) -> None:
|
def test_subparsers_package_copy_option_architecture(parser: argparse.ArgumentParser) -> None:
|
||||||
"""
|
"""
|
||||||
package-copy command must correctly parse architecture list
|
package-copy command must correctly parse architecture list
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from ahriman.core.database import SQLite
|
|||||||
from ahriman.core.database.migrations import Migrations
|
from ahriman.core.database.migrations import Migrations
|
||||||
from ahriman.core.log.log_loader import LogLoader
|
from ahriman.core.log.log_loader import LogLoader
|
||||||
from ahriman.core.repository import Repository
|
from ahriman.core.repository import Repository
|
||||||
from ahriman.core.repository.package_info import PackageInfo
|
|
||||||
from ahriman.core.spawn import Spawn
|
from ahriman.core.spawn import Spawn
|
||||||
from ahriman.core.status import Client
|
from ahriman.core.status import Client
|
||||||
from ahriman.core.status.watcher import Watcher
|
from ahriman.core.status.watcher import Watcher
|
||||||
@@ -689,5 +688,4 @@ def watcher(local_client: Client) -> Watcher:
|
|||||||
Returns:
|
Returns:
|
||||||
Watcher: package status watcher test instance
|
Watcher: package status watcher test instance
|
||||||
"""
|
"""
|
||||||
package_info = PackageInfo()
|
return Watcher(local_client)
|
||||||
return Watcher(local_client, package_info)
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
from ahriman.core.alpm.pacman_handle import PacmanHandle
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_load() -> None:
|
|
||||||
"""
|
|
||||||
must load package from archive path
|
|
||||||
"""
|
|
||||||
local = Path("local")
|
|
||||||
instance = PacmanHandle.ephemeral()
|
|
||||||
handle_mock = instance.handle = MagicMock()
|
|
||||||
|
|
||||||
instance.package_load(local)
|
|
||||||
handle_mock.load_pkg.assert_called_once_with(str(local))
|
|
||||||
|
|
||||||
PacmanHandle._ephemeral = None
|
|
||||||
|
|
||||||
|
|
||||||
def test_getattr() -> None:
|
|
||||||
"""
|
|
||||||
must proxy attribute access to underlying handle
|
|
||||||
"""
|
|
||||||
instance = PacmanHandle.ephemeral()
|
|
||||||
assert instance.dbpath
|
|
||||||
|
|
||||||
|
|
||||||
def test_getattr_not_found() -> None:
|
|
||||||
"""
|
|
||||||
must raise AttributeError for missing handle attributes
|
|
||||||
"""
|
|
||||||
instance = PacmanHandle.ephemeral()
|
|
||||||
with pytest.raises(AttributeError):
|
|
||||||
assert instance.random_attribute
|
|
||||||
@@ -6,7 +6,6 @@ from unittest.mock import call as MockCall
|
|||||||
|
|
||||||
from ahriman.core.build_tools.sources import Sources
|
from ahriman.core.build_tools.sources import Sources
|
||||||
from ahriman.core.exceptions import CalledProcessError
|
from ahriman.core.exceptions import CalledProcessError
|
||||||
from ahriman.models.changes import Changes
|
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.package_source import PackageSource
|
from ahriman.models.package_source import PackageSource
|
||||||
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
from ahriman.models.pkgbuild_patch import PkgbuildPatch
|
||||||
@@ -20,27 +19,35 @@ def test_changes(mocker: MockerFixture) -> None:
|
|||||||
"""
|
"""
|
||||||
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch_until")
|
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch_until")
|
||||||
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff", return_value="diff")
|
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff", return_value="diff")
|
||||||
read_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.read", return_value="pkgbuild")
|
|
||||||
local = Path("local")
|
local = Path("local")
|
||||||
last_commit_sha = "sha"
|
last_commit_sha = "sha"
|
||||||
|
|
||||||
assert Sources.changes(local, last_commit_sha) == Changes(last_commit_sha, "diff", "pkgbuild")
|
assert Sources.changes(local, last_commit_sha) == "diff"
|
||||||
fetch_mock.assert_called_once_with(local, commit_sha=last_commit_sha)
|
fetch_mock.assert_called_once_with(local, commit_sha=last_commit_sha)
|
||||||
diff_mock.assert_called_once_with(local, last_commit_sha)
|
diff_mock.assert_called_once_with(local, last_commit_sha)
|
||||||
read_mock.assert_called_once_with(local, "HEAD", Path("PKGBUILD"))
|
|
||||||
|
|
||||||
|
def test_changes_skip(mocker: MockerFixture) -> None:
|
||||||
|
"""
|
||||||
|
must return none in case if commit sha is not available
|
||||||
|
"""
|
||||||
|
fetch_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.fetch_until")
|
||||||
|
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff")
|
||||||
|
|
||||||
|
assert Sources.changes(Path("local"), None) is None
|
||||||
|
fetch_mock.assert_not_called()
|
||||||
|
diff_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_changes_unknown_commit(mocker: MockerFixture) -> None:
|
def test_changes_unknown_commit(mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must return changes without diff in case if commit sha wasn't found at the required depth
|
must return none in case if commit sha wasn't found at the required depth
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch_until", return_value=None)
|
mocker.patch("ahriman.core.build_tools.sources.Sources.fetch_until", return_value=None)
|
||||||
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff")
|
diff_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.diff")
|
||||||
read_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.read", return_value="pkgbuild")
|
|
||||||
|
|
||||||
assert Sources.changes(Path("local"), "sha") == Changes("sha", None, "pkgbuild")
|
assert Sources.changes(Path("local"), "sha") is None
|
||||||
diff_mock.assert_not_called()
|
diff_mock.assert_not_called()
|
||||||
read_mock.assert_called_once_with(Path("local"), "HEAD", Path("PKGBUILD"))
|
|
||||||
|
|
||||||
|
|
||||||
def test_extend_architectures(mocker: MockerFixture) -> None:
|
def test_extend_architectures(mocker: MockerFixture) -> None:
|
||||||
@@ -596,12 +603,3 @@ def test_patch_apply_function(sources: Sources, mocker: MockerFixture) -> None:
|
|||||||
|
|
||||||
sources.patch_apply(local, patch)
|
sources.patch_apply(local, patch)
|
||||||
write_mock.assert_called_once_with(local / "PKGBUILD")
|
write_mock.assert_called_once_with(local / "PKGBUILD")
|
||||||
|
|
||||||
|
|
||||||
def test_read(sources: Sources, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must read file from commit
|
|
||||||
"""
|
|
||||||
check_output_mock = mocker.patch("ahriman.core.build_tools.sources.check_output", return_value="content")
|
|
||||||
assert sources.read(Path("local"), "sha", Path("PKGBUILD")) == "content"
|
|
||||||
check_output_mock.assert_called_once()
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ def test_migrate_package_depends(connection: Connection, configuration: Configur
|
|||||||
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
||||||
|
|
||||||
migrate_package_depends(connection, configuration)
|
migrate_package_depends(connection, configuration)
|
||||||
package_mock.assert_called_once_with(package_ahriman.packages[package_ahriman.base].filepath)
|
package_mock.assert_called_once_with(
|
||||||
|
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int))
|
||||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||||
"make_depends": package_ahriman.packages[package_ahriman.base].make_depends,
|
"make_depends": package_ahriman.packages[package_ahriman.base].make_depends,
|
||||||
"opt_depends": package_ahriman.packages[package_ahriman.base].opt_depends,
|
"opt_depends": package_ahriman.packages[package_ahriman.base].opt_depends,
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ def test_migrate_package_depends(connection: Connection, configuration: Configur
|
|||||||
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
||||||
|
|
||||||
migrate_package_check_depends(connection, configuration)
|
migrate_package_check_depends(connection, configuration)
|
||||||
package_mock.assert_called_once_with(package_ahriman.packages[package_ahriman.base].filepath)
|
package_mock.assert_called_once_with(
|
||||||
|
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int))
|
||||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||||
"check_depends": package_ahriman.packages[package_ahriman.base].check_depends,
|
"check_depends": package_ahriman.packages[package_ahriman.base].check_depends,
|
||||||
"package": package_ahriman.base,
|
"package": package_ahriman.base,
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ def test_migrate_package_base_packager(connection: Connection, configuration: Co
|
|||||||
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
package_mock = mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
||||||
|
|
||||||
migrate_package_base_packager(connection, configuration)
|
migrate_package_base_packager(connection, configuration)
|
||||||
package_mock.assert_called_once_with(package_ahriman.packages[package_ahriman.base].filepath)
|
package_mock.assert_called_once_with(
|
||||||
|
package_ahriman.packages[package_ahriman.base].filepath, pytest.helpers.anyvar(int))
|
||||||
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
connection.executemany.assert_called_once_with(pytest.helpers.anyvar(str, strict=True), [{
|
||||||
"package_base": package_ahriman.base,
|
"package_base": package_ahriman.base,
|
||||||
"packager": package_ahriman.packager,
|
"packager": package_ahriman.packager,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from sqlite3 import Connection
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import call as MockCall
|
from unittest.mock import call as MockCall
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.database.migrations.m016_archive import migrate_data, move_packages
|
from ahriman.core.database.migrations.m016_archive import migrate_data, move_packages
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
@@ -27,12 +28,12 @@ def test_migrate_data(connection: Connection, configuration: Configuration, mock
|
|||||||
|
|
||||||
migrate_data(connection, configuration)
|
migrate_data(connection, configuration)
|
||||||
migration_mock.assert_has_calls([
|
migration_mock.assert_has_calls([
|
||||||
MockCall(replace(configuration.repository_paths, repository_id=repository))
|
MockCall(replace(configuration.repository_paths, repository_id=repository), pytest.helpers.anyvar(int))
|
||||||
for repository in repositories
|
for repository in repositories
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_move_packages(repository_paths: RepositoryPaths, package_ahriman: Package,
|
def test_move_packages(repository_paths: RepositoryPaths, pacman: Pacman, package_ahriman: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must move packages to the archive directory
|
must move packages to the archive directory
|
||||||
@@ -56,9 +57,9 @@ def test_move_packages(repository_paths: RepositoryPaths, package_ahriman: Packa
|
|||||||
move_mock = mocker.patch("ahriman.core.database.migrations.m016_archive.atomic_move")
|
move_mock = mocker.patch("ahriman.core.database.migrations.m016_archive.atomic_move")
|
||||||
symlink_mock = mocker.patch("pathlib.Path.symlink_to")
|
symlink_mock = mocker.patch("pathlib.Path.symlink_to")
|
||||||
|
|
||||||
move_packages(repository_paths)
|
move_packages(repository_paths, pacman)
|
||||||
archive_mock.assert_has_calls([
|
archive_mock.assert_has_calls([
|
||||||
MockCall(repository_paths.repository / filename)
|
MockCall(repository_paths.repository / filename, pacman)
|
||||||
for filename in ("file.pkg.tar.xz", "file2.pkg.tar.xz")
|
for filename in ("file.pkg.tar.xz", "file2.pkg.tar.xz")
|
||||||
])
|
])
|
||||||
move_mock.assert_has_calls([
|
move_mock.assert_has_calls([
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
from ahriman.core.database.migrations.m017_pkgbuild import steps
|
|
||||||
|
|
||||||
|
|
||||||
def test_migration_pkgbuild() -> None:
|
|
||||||
"""
|
|
||||||
migration must not be empty
|
|
||||||
"""
|
|
||||||
assert steps
|
|
||||||
@@ -8,35 +8,34 @@ def test_changes_insert_get(database: SQLite, package_ahriman: Package) -> None:
|
|||||||
"""
|
"""
|
||||||
must insert and get changes
|
must insert and get changes
|
||||||
"""
|
"""
|
||||||
changes1 = Changes("sha1", "change1", "pkgbuild1")
|
database.changes_insert(package_ahriman.base, Changes("sha1", "change1"))
|
||||||
database.changes_insert(package_ahriman.base, changes1)
|
assert database.changes_get(package_ahriman.base).changes == "change1"
|
||||||
assert database.changes_get(package_ahriman.base) == changes1
|
|
||||||
changes2 = Changes("sha2", "change2", "pkgbuild2")
|
|
||||||
|
|
||||||
database.changes_insert(package_ahriman.base, changes2, RepositoryId("i686", database._repository_id.name))
|
database.changes_insert(package_ahriman.base, Changes("sha2", "change2"),
|
||||||
assert database.changes_get(package_ahriman.base) == changes1
|
RepositoryId("i686", database._repository_id.name))
|
||||||
assert database.changes_get(package_ahriman.base, RepositoryId("i686", database._repository_id.name)) == changes2
|
assert database.changes_get(package_ahriman.base).changes == "change1"
|
||||||
|
assert database.changes_get(
|
||||||
|
package_ahriman.base, RepositoryId("i686", database._repository_id.name)).changes == "change2"
|
||||||
|
|
||||||
|
|
||||||
def test_changes_insert_remove(database: SQLite, package_ahriman: Package, package_python_schedule: Package) -> None:
|
def test_changes_insert_remove(database: SQLite, package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must remove changes for the package
|
must remove changes for the package
|
||||||
"""
|
"""
|
||||||
changes3 = Changes("sha3", "change3", "pkgbuild3")
|
database.changes_insert(package_ahriman.base, Changes("sha1", "change1"))
|
||||||
database.changes_insert(package_ahriman.base, Changes("sha1", "change1", "pkgbuild1"))
|
database.changes_insert(package_python_schedule.base, Changes("sha3", "change3"))
|
||||||
database.changes_insert(package_python_schedule.base, changes3)
|
database.changes_insert(package_ahriman.base, Changes("sha2", "change2"),
|
||||||
database.changes_insert(package_ahriman.base, Changes("sha2", "change2", "pkgbuild2"),
|
|
||||||
RepositoryId("i686", database._repository_id.name))
|
RepositoryId("i686", database._repository_id.name))
|
||||||
|
|
||||||
database.changes_remove(package_ahriman.base)
|
database.changes_remove(package_ahriman.base)
|
||||||
assert database.changes_get(package_ahriman.base).changes is None
|
assert database.changes_get(package_ahriman.base).changes is None
|
||||||
assert database.changes_get(package_python_schedule.base) == changes3
|
assert database.changes_get(package_python_schedule.base).changes == "change3"
|
||||||
|
|
||||||
# insert null
|
# insert null
|
||||||
database.changes_insert(package_ahriman.base, Changes(), RepositoryId("i686", database._repository_id.name))
|
database.changes_insert(package_ahriman.base, Changes(), RepositoryId("i686", database._repository_id.name))
|
||||||
assert database.changes_get(
|
assert database.changes_get(
|
||||||
package_ahriman.base, RepositoryId("i686", database._repository_id.name)).changes is None
|
package_ahriman.base, RepositoryId("i686", database._repository_id.name)).changes is None
|
||||||
assert database.changes_get(package_python_schedule.base) == changes3
|
assert database.changes_get(package_python_schedule.base).changes == "change3"
|
||||||
|
|
||||||
|
|
||||||
def test_changes_insert_remove_full(database: SQLite, package_ahriman: Package,
|
def test_changes_insert_remove_full(database: SQLite, package_ahriman: Package,
|
||||||
@@ -44,12 +43,13 @@ def test_changes_insert_remove_full(database: SQLite, package_ahriman: Package,
|
|||||||
"""
|
"""
|
||||||
must remove all changes for the repository
|
must remove all changes for the repository
|
||||||
"""
|
"""
|
||||||
changes2 = Changes("sha2", "change2", "pkgbuild2")
|
database.changes_insert(package_ahriman.base, Changes("sha1", "change1"))
|
||||||
database.changes_insert(package_ahriman.base, Changes("sha1", "change1", "pkgbuild1"))
|
database.changes_insert(package_python_schedule.base, Changes("sha3", "change3"))
|
||||||
database.changes_insert(package_python_schedule.base, Changes("sha3", "change3", "pkgbuild3"))
|
database.changes_insert(package_ahriman.base, Changes("sha2", "change2"),
|
||||||
database.changes_insert(package_ahriman.base, changes2, RepositoryId("i686", database._repository_id.name))
|
RepositoryId("i686", database._repository_id.name))
|
||||||
|
|
||||||
database.changes_remove(None)
|
database.changes_remove(None)
|
||||||
assert database.changes_get(package_ahriman.base).changes is None
|
assert database.changes_get(package_ahriman.base).changes is None
|
||||||
assert database.changes_get(package_python_schedule.base).changes is None
|
assert database.changes_get(package_python_schedule.base).changes is None
|
||||||
assert database.changes_get(package_ahriman.base, RepositoryId("i686", database._repository_id.name)) == changes2
|
assert database.changes_get(
|
||||||
|
package_ahriman.base, RepositoryId("i686", database._repository_id.name)).changes == "change2"
|
||||||
|
|||||||
@@ -2,26 +2,24 @@ import pytest
|
|||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from ahriman.core.formatters import (
|
from ahriman.core.formatters import \
|
||||||
AurPrinter,
|
AurPrinter, \
|
||||||
ChangesPrinter,
|
ChangesPrinter, \
|
||||||
ConfigurationPathsPrinter,
|
ConfigurationPathsPrinter, \
|
||||||
ConfigurationPrinter,
|
ConfigurationPrinter, \
|
||||||
EventStatsPrinter,
|
EventStatsPrinter, \
|
||||||
PackagePrinter,
|
PackagePrinter, \
|
||||||
PackageStatsPrinter,
|
PackageStatsPrinter, \
|
||||||
PatchPrinter,
|
PatchPrinter, \
|
||||||
PkgbuildPrinter,
|
RepositoryPrinter, \
|
||||||
RepositoryPrinter,
|
RepositoryStatsPrinter, \
|
||||||
RepositoryStatsPrinter,
|
StatusPrinter, \
|
||||||
StatusPrinter,
|
StringPrinter, \
|
||||||
StringPrinter,
|
TreePrinter, \
|
||||||
TreePrinter,
|
UpdatePrinter, \
|
||||||
UpdatePrinter,
|
UserPrinter, \
|
||||||
UserPrinter,
|
ValidationPrinter, \
|
||||||
ValidationPrinter,
|
|
||||||
VersionPrinter
|
VersionPrinter
|
||||||
)
|
|
||||||
from ahriman.models.aur_package import AURPackage
|
from ahriman.models.aur_package import AURPackage
|
||||||
from ahriman.models.build_status import BuildStatus
|
from ahriman.models.build_status import BuildStatus
|
||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
@@ -57,17 +55,6 @@ def changes_printer() -> ChangesPrinter:
|
|||||||
return ChangesPrinter(Changes("sha", "changes"))
|
return ChangesPrinter(Changes("sha", "changes"))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def pkgbuild_printer() -> PkgbuildPrinter:
|
|
||||||
"""
|
|
||||||
fixture for pkgbuild printer
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
PkgbuildPrinter: pkgbuild printer test instance
|
|
||||||
"""
|
|
||||||
return PkgbuildPrinter(Changes("sha", "changes", "pkgbuild content"))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def configuration_paths_printer() -> ConfigurationPathsPrinter:
|
def configuration_paths_printer() -> ConfigurationPathsPrinter:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
from ahriman.core.formatters import PkgbuildPrinter
|
|
||||||
from ahriman.models.changes import Changes
|
|
||||||
|
|
||||||
|
|
||||||
def test_properties(pkgbuild_printer: PkgbuildPrinter) -> None:
|
|
||||||
"""
|
|
||||||
must return non-empty properties list
|
|
||||||
"""
|
|
||||||
assert pkgbuild_printer.properties()
|
|
||||||
|
|
||||||
|
|
||||||
def test_properties_empty() -> None:
|
|
||||||
"""
|
|
||||||
must return empty properties list if pkgbuild is empty
|
|
||||||
"""
|
|
||||||
assert not PkgbuildPrinter(Changes()).properties()
|
|
||||||
assert not PkgbuildPrinter(Changes("sha", "changes")).properties()
|
|
||||||
|
|
||||||
|
|
||||||
def test_title(pkgbuild_printer: PkgbuildPrinter) -> None:
|
|
||||||
"""
|
|
||||||
must return non-empty title
|
|
||||||
"""
|
|
||||||
assert pkgbuild_printer.title()
|
|
||||||
|
|
||||||
|
|
||||||
def test_title_empty() -> None:
|
|
||||||
"""
|
|
||||||
must return empty title if change is empty
|
|
||||||
"""
|
|
||||||
assert not PkgbuildPrinter(Changes()).title()
|
|
||||||
assert not PkgbuildPrinter(Changes("sha")).title()
|
|
||||||
@@ -3,11 +3,12 @@ import pytest
|
|||||||
from dataclasses import replace
|
from dataclasses import replace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import call as MockCall
|
from unittest.mock import call as MockCall
|
||||||
|
|
||||||
|
from ahriman.core.alpm.pacman import Pacman
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.housekeeping import ArchiveRotationTrigger
|
from ahriman.core.housekeeping import ArchiveRotationTrigger
|
||||||
from ahriman.core.repository import Repository
|
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.result import Result
|
from ahriman.models.result import Result
|
||||||
|
|
||||||
@@ -20,24 +21,26 @@ def test_configuration_sections(configuration: Configuration) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_archives_remove(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package,
|
def test_archives_remove(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package,
|
||||||
repository: Repository, mocker: MockerFixture) -> None:
|
pacman: Pacman, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must remove older packages
|
must remove older packages
|
||||||
"""
|
"""
|
||||||
packages = []
|
def package(version: Any, *args: Any, **kwargs: Any) -> Package:
|
||||||
for i in range(5):
|
generated = replace(package_ahriman, version=str(version))
|
||||||
generated = replace(package_ahriman, version=str(i))
|
|
||||||
generated.packages = {
|
generated.packages = {
|
||||||
key: replace(value, filename=str(i))
|
key: replace(value, filename=str(version))
|
||||||
for key, value in generated.packages.items()
|
for key, value in generated.packages.items()
|
||||||
}
|
}
|
||||||
packages.append(generated)
|
return generated
|
||||||
|
|
||||||
mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives", return_value=packages)
|
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||||
|
mocker.patch("ahriman.core.housekeeping.archive_rotation_trigger.package_like", return_value=True)
|
||||||
mocker.patch("pathlib.Path.glob", return_value=[Path(str(i)) for i in range(5)])
|
mocker.patch("pathlib.Path.glob", return_value=[Path(str(i)) for i in range(5)])
|
||||||
|
mocker.patch("pathlib.Path.iterdir", return_value=[Path(str(i)) for i in range(5)])
|
||||||
|
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=package)
|
||||||
unlink_mock = mocker.patch("pathlib.Path.unlink", autospec=True)
|
unlink_mock = mocker.patch("pathlib.Path.unlink", autospec=True)
|
||||||
|
|
||||||
archive_rotation_trigger.archives_remove(package_ahriman, repository)
|
archive_rotation_trigger.archives_remove(package_ahriman, pacman)
|
||||||
unlink_mock.assert_has_calls([
|
unlink_mock.assert_has_calls([
|
||||||
MockCall(Path("0")),
|
MockCall(Path("0")),
|
||||||
MockCall(Path("1")),
|
MockCall(Path("1")),
|
||||||
@@ -45,15 +48,28 @@ def test_archives_remove(archive_rotation_trigger: ArchiveRotationTrigger, packa
|
|||||||
|
|
||||||
|
|
||||||
def test_archives_remove_keep(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package,
|
def test_archives_remove_keep(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package,
|
||||||
repository: Repository, mocker: MockerFixture) -> None:
|
pacman: Pacman, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must keep all packages if set to
|
must keep all packages if set to
|
||||||
"""
|
"""
|
||||||
archives_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives")
|
def package(version: Any, *args: Any, **kwargs: Any) -> Package:
|
||||||
|
generated = replace(package_ahriman, version=str(version))
|
||||||
|
generated.packages = {
|
||||||
|
key: replace(value, filename=str(version))
|
||||||
|
for key, value in generated.packages.items()
|
||||||
|
}
|
||||||
|
return generated
|
||||||
|
|
||||||
|
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||||
|
mocker.patch("ahriman.core.housekeeping.archive_rotation_trigger.package_like", return_value=True)
|
||||||
|
mocker.patch("pathlib.Path.glob", return_value=[Path(str(i)) for i in range(5)])
|
||||||
|
mocker.patch("pathlib.Path.iterdir", return_value=[Path(str(i)) for i in range(5)])
|
||||||
|
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=package)
|
||||||
|
unlink_mock = mocker.patch("pathlib.Path.unlink", autospec=True)
|
||||||
|
|
||||||
archive_rotation_trigger.keep_built_packages = 0
|
archive_rotation_trigger.keep_built_packages = 0
|
||||||
archive_rotation_trigger.archives_remove(package_ahriman, repository)
|
archive_rotation_trigger.archives_remove(package_ahriman, pacman)
|
||||||
archives_mock.assert_not_called()
|
unlink_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_on_result(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package,
|
def test_on_result(archive_rotation_trigger: ArchiveRotationTrigger, package_ahriman: Package,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from ahriman.core.configuration import Configuration
|
|||||||
from ahriman.core.database import SQLite
|
from ahriman.core.database import SQLite
|
||||||
from ahriman.core.repository.cleaner import Cleaner
|
from ahriman.core.repository.cleaner import Cleaner
|
||||||
from ahriman.core.repository.executor import Executor
|
from ahriman.core.repository.executor import Executor
|
||||||
|
from ahriman.core.repository.package_info import PackageInfo
|
||||||
from ahriman.core.repository.update_handler import UpdateHandler
|
from ahriman.core.repository.update_handler import UpdateHandler
|
||||||
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
from ahriman.models.pacman_synchronization import PacmanSynchronization
|
||||||
|
|
||||||
@@ -49,6 +50,23 @@ def executor(configuration: Configuration, database: SQLite, mocker: MockerFixtu
|
|||||||
refresh_pacman_database=PacmanSynchronization.Disabled)
|
refresh_pacman_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def package_info(configuration: Configuration, database: SQLite) -> PackageInfo:
|
||||||
|
"""
|
||||||
|
fixture for package info
|
||||||
|
|
||||||
|
Args:
|
||||||
|
configuration(Configuration): configuration fixture
|
||||||
|
database(SQLite): database fixture
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
PackageInfo: package info test instance
|
||||||
|
"""
|
||||||
|
_, repository_id = configuration.check_loaded()
|
||||||
|
return PackageInfo(repository_id, configuration, database, report=False,
|
||||||
|
refresh_pacman_database=PacmanSynchronization.Disabled)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def update_handler(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> UpdateHandler:
|
def update_handler(configuration: Configuration, database: SQLite, mocker: MockerFixture) -> UpdateHandler:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from ahriman.models.changes import Changes
|
|||||||
from ahriman.models.dependencies import Dependencies
|
from ahriman.models.dependencies import Dependencies
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.packagers import Packagers
|
from ahriman.models.packagers import Packagers
|
||||||
from ahriman.models.repository_id import RepositoryId
|
|
||||||
from ahriman.models.user import User
|
from ahriman.models.user import User
|
||||||
|
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ def test_archive_lookup_architecture_mismatch(executor: Executor, package_ahrima
|
|||||||
"""
|
"""
|
||||||
package_ahriman.packages[package_ahriman.base].architecture = "x86_64"
|
package_ahriman.packages[package_ahriman.base].architecture = "x86_64"
|
||||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||||
executor.repository_id = RepositoryId("i686", executor.repository_id.name)
|
mocker.patch("ahriman.core.repository.executor.Executor.architecture", return_value="i686")
|
||||||
mocker.patch("pathlib.Path.iterdir", return_value=[
|
mocker.patch("pathlib.Path.iterdir", return_value=[
|
||||||
Path("1.pkg.tar.zst"),
|
Path("1.pkg.tar.zst"),
|
||||||
])
|
])
|
||||||
@@ -117,9 +116,9 @@ def test_package_build(executor: Executor, package_ahriman: Package, mocker: Moc
|
|||||||
assert executor._package_build(package_ahriman, Path("local"), "packager", None) == "sha"
|
assert executor._package_build(package_ahriman, Path("local"), "packager", None) == "sha"
|
||||||
status_client_mock.assert_called_once_with(package_ahriman.base)
|
status_client_mock.assert_called_once_with(package_ahriman.base)
|
||||||
init_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), None)
|
init_mock.assert_called_once_with(pytest.helpers.anyvar(int), pytest.helpers.anyvar(int), None)
|
||||||
package_mock.assert_called_once_with(Path("local"), executor.repository_id.architecture, None)
|
package_mock.assert_called_once_with(Path("local"), executor.architecture, None)
|
||||||
lookup_mock.assert_called_once_with(package_ahriman)
|
lookup_mock.assert_called_once_with(package_ahriman)
|
||||||
with_packages_mock.assert_called_once_with([Path(package_ahriman.base)])
|
with_packages_mock.assert_called_once_with([Path(package_ahriman.base)], executor.pacman)
|
||||||
rename_mock.assert_called_once_with(Path(package_ahriman.base), executor.paths.packages / package_ahriman.base)
|
rename_mock.assert_called_once_with(Path(package_ahriman.base), executor.paths.packages / package_ahriman.base)
|
||||||
|
|
||||||
|
|
||||||
@@ -220,7 +219,7 @@ def test_process_build(executor: Executor, package_ahriman: Package, passwd: Any
|
|||||||
mocker.patch("ahriman.models.repository_paths.getpwuid", return_value=passwd)
|
mocker.patch("ahriman.models.repository_paths.getpwuid", return_value=passwd)
|
||||||
mocker.patch("ahriman.core.repository.executor.Executor.packages", return_value=[package_ahriman])
|
mocker.patch("ahriman.core.repository.executor.Executor.packages", return_value=[package_ahriman])
|
||||||
changes_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get",
|
changes_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get",
|
||||||
return_value=Changes("commit", "change", "pkgbuild"))
|
return_value=Changes("commit", "change"))
|
||||||
commit_sha_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
commit_sha_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
|
||||||
depends_on_mock = mocker.patch("ahriman.core.build_tools.package_archive.PackageArchive.depends_on",
|
depends_on_mock = mocker.patch("ahriman.core.build_tools.package_archive.PackageArchive.depends_on",
|
||||||
return_value=Dependencies())
|
return_value=Dependencies())
|
||||||
@@ -232,7 +231,7 @@ def test_process_build(executor: Executor, package_ahriman: Package, passwd: Any
|
|||||||
build_mock.assert_called_once_with(package_ahriman, pytest.helpers.anyvar(Path, strict=True), None, None)
|
build_mock.assert_called_once_with(package_ahriman, pytest.helpers.anyvar(Path, strict=True), None, None)
|
||||||
depends_on_mock.assert_called_once_with()
|
depends_on_mock.assert_called_once_with()
|
||||||
dependencies_mock.assert_called_once_with(package_ahriman.base, Dependencies())
|
dependencies_mock.assert_called_once_with(package_ahriman.base, Dependencies())
|
||||||
commit_sha_mock.assert_called_once_with(package_ahriman.base, Changes("sha", "change", "pkgbuild"))
|
commit_sha_mock.assert_called_once_with(package_ahriman.base, Changes("sha", "change"))
|
||||||
|
|
||||||
|
|
||||||
def test_process_build_bump_pkgrel(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_process_build_bump_pkgrel(executor: Executor, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from dataclasses import replace
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from ahriman.core.repository import Repository
|
from ahriman.core.repository.package_info import PackageInfo
|
||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
|
||||||
|
|
||||||
def test_full_depends(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
def test_full_depends(package_info: PackageInfo, package_ahriman: Package, package_python_schedule: Package,
|
||||||
pyalpm_package_ahriman: MagicMock) -> None:
|
pyalpm_package_ahriman: MagicMock) -> None:
|
||||||
"""
|
"""
|
||||||
must extract all dependencies from the package
|
must extract all dependencies from the package
|
||||||
@@ -19,18 +18,18 @@ def test_full_depends(repository: Repository, package_ahriman: Package, package_
|
|||||||
|
|
||||||
database_mock = MagicMock()
|
database_mock = MagicMock()
|
||||||
database_mock.pkgcache = [pyalpm_package_ahriman]
|
database_mock.pkgcache = [pyalpm_package_ahriman]
|
||||||
repository.pacman = MagicMock()
|
package_info.pacman = MagicMock()
|
||||||
repository.pacman.handle.get_syncdbs.return_value = [database_mock]
|
package_info.pacman.handle.get_syncdbs.return_value = [database_mock]
|
||||||
|
|
||||||
assert repository.full_depends(package_ahriman, [package_python_schedule]) == package_ahriman.depends
|
assert package_info.full_depends(package_ahriman, [package_python_schedule]) == package_ahriman.depends
|
||||||
|
|
||||||
package_python_schedule.packages[package_python_schedule.base].depends = [package_ahriman.base]
|
package_python_schedule.packages[package_python_schedule.base].depends = [package_ahriman.base]
|
||||||
expected = sorted(set(package_python_schedule.depends + package_ahriman.depends))
|
expected = sorted(set(package_python_schedule.depends + package_ahriman.depends))
|
||||||
assert repository.full_depends(package_python_schedule, [package_python_schedule]) == expected
|
assert package_info.full_depends(package_python_schedule, [package_python_schedule]) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_load_archives(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
def test_load_archives(package_ahriman: Package, package_python_schedule: Package,
|
||||||
mocker: MockerFixture) -> None:
|
package_info: PackageInfo, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must return all packages grouped by package base
|
must return all packages grouped by package base
|
||||||
"""
|
"""
|
||||||
@@ -46,7 +45,7 @@ def test_load_archives(repository: Repository, package_ahriman: Package, package
|
|||||||
(package_ahriman, None),
|
(package_ahriman, None),
|
||||||
])
|
])
|
||||||
|
|
||||||
packages = repository.load_archives([Path("a.pkg.tar.xz"), Path("b.pkg.tar.xz"), Path("c.pkg.tar.xz")])
|
packages = package_info.load_archives([Path("a.pkg.tar.xz"), Path("b.pkg.tar.xz"), Path("c.pkg.tar.xz")])
|
||||||
assert len(packages) == 2
|
assert len(packages) == 2
|
||||||
assert {package.base for package in packages} == {package_ahriman.base, package_python_schedule.base}
|
assert {package.base for package in packages} == {package_ahriman.base, package_python_schedule.base}
|
||||||
|
|
||||||
@@ -57,22 +56,22 @@ def test_load_archives(repository: Repository, package_ahriman: Package, package
|
|||||||
assert set(archives) == expected
|
assert set(archives) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_load_archives_failed(repository: Repository, mocker: MockerFixture) -> None:
|
def test_load_archives_failed(package_info: PackageInfo, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must skip packages which cannot be loaded
|
must skip packages which cannot be loaded
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=Exception)
|
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=Exception)
|
||||||
assert not repository.load_archives([Path("a.pkg.tar.xz")])
|
assert not package_info.load_archives([Path("a.pkg.tar.xz")])
|
||||||
|
|
||||||
|
|
||||||
def test_load_archives_not_package(repository: Repository) -> None:
|
def test_load_archives_not_package(package_info: PackageInfo) -> None:
|
||||||
"""
|
"""
|
||||||
must skip not packages from iteration
|
must skip not packages from iteration
|
||||||
"""
|
"""
|
||||||
assert not repository.load_archives([Path("a.tar.xz")])
|
assert not package_info.load_archives([Path("a.tar.xz")])
|
||||||
|
|
||||||
|
|
||||||
def test_load_archives_different_version(repository: Repository, package_python_schedule: Package,
|
def test_load_archives_different_version(package_info: PackageInfo, package_python_schedule: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must load packages with different versions choosing maximal
|
must load packages with different versions choosing maximal
|
||||||
@@ -87,65 +86,37 @@ def test_load_archives_different_version(repository: Repository, package_python_
|
|||||||
single_packages[0].version = "0.0.1-1"
|
single_packages[0].version = "0.0.1-1"
|
||||||
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=single_packages)
|
mocker.patch("ahriman.models.package.Package.from_archive", side_effect=single_packages)
|
||||||
|
|
||||||
packages = repository.load_archives([Path("a.pkg.tar.xz"), Path("b.pkg.tar.xz")])
|
packages = package_info.load_archives([Path("a.pkg.tar.xz"), Path("b.pkg.tar.xz")])
|
||||||
assert len(packages) == 1
|
assert len(packages) == 1
|
||||||
assert packages[0].version == package_python_schedule.version
|
assert packages[0].version == package_python_schedule.version
|
||||||
|
|
||||||
|
|
||||||
def test_package_archives(repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_changes(package_info: PackageInfo, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
|
||||||
must load package archives sorted by version
|
|
||||||
"""
|
|
||||||
mocker.patch("ahriman.core.repository.package_info.package_like", return_value=True)
|
|
||||||
mocker.patch("pathlib.Path.iterdir", return_value=[str(i) for i in range(5)])
|
|
||||||
mocker.patch("ahriman.models.package.Package.from_archive",
|
|
||||||
side_effect=lambda version: replace(package_ahriman, version=version))
|
|
||||||
|
|
||||||
result = repository.package_archives(package_ahriman.base)
|
|
||||||
assert len(result) == 5
|
|
||||||
assert [p.version for p in result] == [str(i) for i in range(5)]
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_archives_architecture_mismatch(repository: Repository, package_ahriman: Package,
|
|
||||||
mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must skip packages with mismatched architecture
|
|
||||||
"""
|
|
||||||
package_ahriman.packages[package_ahriman.base].architecture = "i686"
|
|
||||||
|
|
||||||
mocker.patch("pathlib.Path.iterdir", return_value=[package_ahriman.packages[package_ahriman.base].filepath])
|
|
||||||
mocker.patch("ahriman.models.package.Package.from_archive", return_value=package_ahriman)
|
|
||||||
|
|
||||||
result = repository.package_archives(package_ahriman.base)
|
|
||||||
assert len(result) == 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_changes(repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
"""
|
||||||
must load package changes
|
must load package changes
|
||||||
"""
|
"""
|
||||||
changes = Changes("sha", "change")
|
changes = Changes("sha", "change")
|
||||||
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load", return_value="sha2")
|
load_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.load", return_value="sha2")
|
||||||
changes_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.changes", return_value=changes)
|
changes_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.changes", return_value=changes.changes)
|
||||||
|
|
||||||
assert repository.package_changes(package_ahriman, changes.last_commit_sha) == changes
|
assert package_info.package_changes(package_ahriman, changes.last_commit_sha) == changes
|
||||||
load_mock.assert_called_once_with(
|
load_mock.assert_called_once_with(pytest.helpers.anyvar(int), package_ahriman, [], package_info.paths)
|
||||||
pytest.helpers.anyvar(int), package_ahriman, [], repository.configuration.repository_paths)
|
|
||||||
changes_mock.assert_called_once_with(pytest.helpers.anyvar(int), changes.last_commit_sha)
|
changes_mock.assert_called_once_with(pytest.helpers.anyvar(int), changes.last_commit_sha)
|
||||||
|
|
||||||
|
|
||||||
def test_package_changes_skip(repository: Repository, package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_package_changes_skip(package_info: PackageInfo, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must skip loading package changes if no new commits
|
must skip loading package changes if no new commits
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.core.build_tools.sources.Sources.load", return_value="sha")
|
changes = Changes("sha")
|
||||||
|
mocker.patch("ahriman.core.build_tools.sources.Sources.load", return_value=changes.last_commit_sha)
|
||||||
changes_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.changes")
|
changes_mock = mocker.patch("ahriman.core.build_tools.sources.Sources.changes")
|
||||||
|
|
||||||
assert repository.package_changes(package_ahriman, "sha") is None
|
assert package_info.package_changes(package_ahriman, changes.last_commit_sha) == changes
|
||||||
changes_mock.assert_not_called()
|
changes_mock.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_packages(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
def test_packages(package_info: PackageInfo, package_ahriman: Package, package_python_schedule: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must return repository packages
|
must return repository packages
|
||||||
@@ -153,12 +124,12 @@ def test_packages(repository: Repository, package_ahriman: Package, package_pyth
|
|||||||
mocker.patch("pathlib.Path.iterdir")
|
mocker.patch("pathlib.Path.iterdir")
|
||||||
load_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives",
|
load_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives",
|
||||||
return_value=[package_ahriman, package_python_schedule])
|
return_value=[package_ahriman, package_python_schedule])
|
||||||
assert repository.packages() == [package_ahriman, package_python_schedule]
|
assert package_info.packages() == [package_ahriman, package_python_schedule]
|
||||||
# it uses filter object, so we cannot verify argument list =/
|
# it uses filter object, so we cannot verify argument list =/
|
||||||
load_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
load_mock.assert_called_once_with(pytest.helpers.anyvar(int))
|
||||||
|
|
||||||
|
|
||||||
def test_packages_filter(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
def test_packages_filter(package_info: PackageInfo, package_ahriman: Package, package_python_schedule: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must filter result by bases
|
must filter result by bases
|
||||||
@@ -166,33 +137,33 @@ def test_packages_filter(repository: Repository, package_ahriman: Package, packa
|
|||||||
mocker.patch("pathlib.Path.iterdir")
|
mocker.patch("pathlib.Path.iterdir")
|
||||||
mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives",
|
mocker.patch("ahriman.core.repository.package_info.PackageInfo.load_archives",
|
||||||
return_value=[package_ahriman, package_python_schedule])
|
return_value=[package_ahriman, package_python_schedule])
|
||||||
assert repository.packages([package_ahriman.base]) == [package_ahriman]
|
assert package_info.packages([package_ahriman.base]) == [package_ahriman]
|
||||||
|
|
||||||
|
|
||||||
def test_packages_built(repository: Repository, mocker: MockerFixture) -> None:
|
def test_packages_built(package_info: PackageInfo, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must return build packages
|
must return build packages
|
||||||
"""
|
"""
|
||||||
mocker.patch("pathlib.Path.iterdir", return_value=[Path("a.tar.xz"), Path("b.pkg.tar.xz")])
|
mocker.patch("pathlib.Path.iterdir", return_value=[Path("a.tar.xz"), Path("b.pkg.tar.xz")])
|
||||||
assert repository.packages_built() == [Path("b.pkg.tar.xz")]
|
assert package_info.packages_built() == [Path("b.pkg.tar.xz")]
|
||||||
|
|
||||||
|
|
||||||
def test_packages_depend_on(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
def test_packages_depend_on(package_info: PackageInfo, package_ahriman: Package, package_python_schedule: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must filter packages by depends list
|
must filter packages by depends list
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
||||||
return_value=[package_ahriman, package_python_schedule])
|
return_value=[package_ahriman, package_python_schedule])
|
||||||
assert repository.packages_depend_on([package_ahriman], {"python-srcinfo"}) == [package_ahriman]
|
assert package_info.packages_depend_on([package_ahriman], {"python-srcinfo"}) == [package_ahriman]
|
||||||
|
|
||||||
|
|
||||||
def test_packages_depend_on_empty(repository: Repository, package_ahriman: Package, package_python_schedule: Package,
|
def test_packages_depend_on_empty(package_info: PackageInfo, package_ahriman: Package, package_python_schedule: Package,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must return all packages in case if no filter is provided
|
must return all packages in case if no filter is provided
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
mocker.patch("ahriman.core.repository.repository.Repository.packages",
|
||||||
return_value=[package_ahriman, package_python_schedule])
|
return_value=[package_ahriman, package_python_schedule])
|
||||||
assert repository.packages_depend_on([package_ahriman, package_python_schedule], None) == \
|
assert package_info.packages_depend_on([package_ahriman, package_python_schedule], None) == \
|
||||||
[package_ahriman, package_python_schedule]
|
[package_ahriman, package_python_schedule]
|
||||||
|
|||||||
@@ -6,6 +6,20 @@ from ahriman.models.user import User
|
|||||||
from ahriman.models.user_access import UserAccess
|
from ahriman.models.user_access import UserAccess
|
||||||
|
|
||||||
|
|
||||||
|
def test_architecture(repository: RepositoryProperties) -> None:
|
||||||
|
"""
|
||||||
|
must provide repository architecture for backward compatibility
|
||||||
|
"""
|
||||||
|
assert repository.architecture == repository.repository_id.architecture
|
||||||
|
|
||||||
|
|
||||||
|
def test_name(repository: RepositoryProperties) -> None:
|
||||||
|
"""
|
||||||
|
must provide repository name for backward compatibility
|
||||||
|
"""
|
||||||
|
assert repository.name == repository.repository_id.name
|
||||||
|
|
||||||
|
|
||||||
def test_packager(repository: RepositoryProperties, mocker: MockerFixture) -> None:
|
def test_packager(repository: RepositoryProperties, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must extract packager
|
must extract packager
|
||||||
|
|||||||
@@ -45,18 +45,6 @@ def test_load_known(watcher: Watcher, package_ahriman: Package, mocker: MockerFi
|
|||||||
assert status.status == BuildStatusEnum.Success
|
assert status.status == BuildStatusEnum.Success
|
||||||
|
|
||||||
|
|
||||||
def test_package_archives(watcher: Watcher, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must return package archives from package info
|
|
||||||
"""
|
|
||||||
archives_mock = mocker.patch("ahriman.core.repository.package_info.PackageInfo.package_archives",
|
|
||||||
return_value=[package_ahriman])
|
|
||||||
|
|
||||||
result = watcher.package_archives(package_ahriman.base)
|
|
||||||
assert result == [package_ahriman]
|
|
||||||
archives_mock.assert_called_once_with(package_ahriman.base)
|
|
||||||
|
|
||||||
|
|
||||||
def test_package_get(watcher: Watcher, package_ahriman: Package) -> None:
|
def test_package_get(watcher: Watcher, package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
must return package status
|
must return package status
|
||||||
|
|||||||
@@ -89,6 +89,22 @@ def pkgbuild_ahriman(resource_path_root: Path) -> Pkgbuild:
|
|||||||
return Pkgbuild.from_file(pkgbuild)
|
return Pkgbuild.from_file(pkgbuild)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pyalpm_handle(pyalpm_package_ahriman: MagicMock) -> MagicMock:
|
||||||
|
"""
|
||||||
|
mock object for pyalpm
|
||||||
|
|
||||||
|
Args:
|
||||||
|
pyalpm_package_ahriman(MagicMock): mock object for pyalpm package
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
MagicMock: pyalpm mock
|
||||||
|
"""
|
||||||
|
mock = MagicMock()
|
||||||
|
mock.handle.load_pkg.return_value = pyalpm_package_ahriman
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescription) -> MagicMock:
|
def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescription) -> MagicMock:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_empty() -> None:
|
||||||
|
"""
|
||||||
|
must check if changes are empty
|
||||||
|
"""
|
||||||
|
assert Changes().is_empty
|
||||||
|
assert Changes("sha").is_empty
|
||||||
|
|
||||||
|
assert not Changes("sha", "change").is_empty
|
||||||
|
assert not Changes(None, "change").is_empty # well, ok
|
||||||
|
|
||||||
|
|
||||||
def test_changes_from_json_view() -> None:
|
def test_changes_from_json_view() -> None:
|
||||||
"""
|
"""
|
||||||
must construct same object from json
|
must construct same object from json
|
||||||
|
|||||||
@@ -101,6 +101,20 @@ def test_groups(package_ahriman: Package) -> None:
|
|||||||
assert sorted(package_ahriman.groups) == package_ahriman.groups
|
assert sorted(package_ahriman.groups) == package_ahriman.groups
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_single_package_false(package_python_schedule: Package) -> None:
|
||||||
|
"""
|
||||||
|
python-schedule must not be single package
|
||||||
|
"""
|
||||||
|
assert not package_python_schedule.is_single_package
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_single_package_true(package_ahriman: Package) -> None:
|
||||||
|
"""
|
||||||
|
ahriman must be single package
|
||||||
|
"""
|
||||||
|
assert package_ahriman.is_single_package
|
||||||
|
|
||||||
|
|
||||||
def test_is_vcs_false(package_ahriman: Package) -> None:
|
def test_is_vcs_false(package_ahriman: Package) -> None:
|
||||||
"""
|
"""
|
||||||
ahriman must not be VCS package
|
ahriman must not be VCS package
|
||||||
@@ -134,14 +148,13 @@ def test_packages_full(package_ahriman: Package) -> None:
|
|||||||
assert package_ahriman.packages_full == [package_ahriman.base, f"{package_ahriman.base}-git"]
|
assert package_ahriman.packages_full == [package_ahriman.base, f"{package_ahriman.base}-git"]
|
||||||
|
|
||||||
|
|
||||||
def test_from_archive(package_ahriman: Package, pyalpm_package_ahriman: MagicMock, mocker: MockerFixture) -> None:
|
def test_from_archive(package_ahriman: Package, pyalpm_handle: MagicMock, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must construct package from alpm library
|
must construct package from alpm library
|
||||||
"""
|
"""
|
||||||
mocker.patch("ahriman.core.alpm.pacman_handle.PacmanHandle.package_load", return_value=pyalpm_package_ahriman)
|
|
||||||
mocker.patch("ahriman.models.package_description.PackageDescription.from_package",
|
mocker.patch("ahriman.models.package_description.PackageDescription.from_package",
|
||||||
return_value=package_ahriman.packages[package_ahriman.base])
|
return_value=package_ahriman.packages[package_ahriman.base])
|
||||||
generated = Package.from_archive(Path("path"))
|
generated = Package.from_archive(Path("path"), pyalpm_handle)
|
||||||
generated.remote = package_ahriman.remote
|
generated.remote = package_ahriman.remote
|
||||||
|
|
||||||
assert generated == package_ahriman
|
assert generated == package_ahriman
|
||||||
@@ -152,12 +165,13 @@ def test_from_archive_empty_base(package_ahriman: Package, pyalpm_package_ahrima
|
|||||||
"""
|
"""
|
||||||
must construct package with empty base from alpm library
|
must construct package with empty base from alpm library
|
||||||
"""
|
"""
|
||||||
|
pyalpm_handle = MagicMock()
|
||||||
type(pyalpm_package_ahriman).base = PropertyMock(return_value=None)
|
type(pyalpm_package_ahriman).base = PropertyMock(return_value=None)
|
||||||
mocker.patch("ahriman.core.alpm.pacman_handle.PacmanHandle.package_load", return_value=pyalpm_package_ahriman)
|
pyalpm_handle.handle.load_pkg.return_value = pyalpm_package_ahriman
|
||||||
|
|
||||||
mocker.patch("ahriman.models.package_description.PackageDescription.from_package",
|
mocker.patch("ahriman.models.package_description.PackageDescription.from_package",
|
||||||
return_value=package_ahriman.packages[package_ahriman.base])
|
return_value=package_ahriman.packages[package_ahriman.base])
|
||||||
generated = Package.from_archive(Path("path"))
|
generated = Package.from_archive(Path("path"), pyalpm_handle)
|
||||||
generated.remote = package_ahriman.remote
|
generated.remote = package_ahriman.remote
|
||||||
|
|
||||||
assert generated == package_ahriman
|
assert generated == package_ahriman
|
||||||
@@ -339,30 +353,6 @@ def test_build_status_pretty_print(package_ahriman: Package) -> None:
|
|||||||
assert isinstance(package_ahriman.pretty_print(), str)
|
assert isinstance(package_ahriman.pretty_print(), str)
|
||||||
|
|
||||||
|
|
||||||
def test_supports_architecture(package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must check if package supports architecture
|
|
||||||
"""
|
|
||||||
package_ahriman.packages[package_ahriman.base].architecture = "x86_64"
|
|
||||||
assert package_ahriman.supports_architecture("x86_64")
|
|
||||||
|
|
||||||
|
|
||||||
def test_supports_architecture_any(package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must support any architecture
|
|
||||||
"""
|
|
||||||
package_ahriman.packages[package_ahriman.base].architecture = "any"
|
|
||||||
assert package_ahriman.supports_architecture("x86_64")
|
|
||||||
|
|
||||||
|
|
||||||
def test_supports_architecture_mismatch(package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must not support mismatched architecture
|
|
||||||
"""
|
|
||||||
package_ahriman.packages[package_ahriman.base].architecture = "i686"
|
|
||||||
assert not package_ahriman.supports_architecture("x86_64")
|
|
||||||
|
|
||||||
|
|
||||||
def test_vercmp(package_ahriman: Package, mocker: MockerFixture) -> None:
|
def test_vercmp(package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must call vercmp
|
must call vercmp
|
||||||
@@ -372,7 +362,7 @@ def test_vercmp(package_ahriman: Package, mocker: MockerFixture) -> None:
|
|||||||
vercmp_mock.assert_called_once_with(package_ahriman.version, "version")
|
vercmp_mock.assert_called_once_with(package_ahriman.version, "version")
|
||||||
|
|
||||||
|
|
||||||
def test_with_packages(package_ahriman: Package, package_python_schedule: Package,
|
def test_with_packages(package_ahriman: Package, package_python_schedule: Package, pacman: Pacman,
|
||||||
mocker: MockerFixture) -> None:
|
mocker: MockerFixture) -> None:
|
||||||
"""
|
"""
|
||||||
must correctly replace packages descriptions
|
must correctly replace packages descriptions
|
||||||
@@ -385,8 +375,8 @@ def test_with_packages(package_ahriman: Package, package_python_schedule: Packag
|
|||||||
result = copy.deepcopy(package_ahriman)
|
result = copy.deepcopy(package_ahriman)
|
||||||
package_ahriman.packages[package_ahriman.base].architecture = "i686"
|
package_ahriman.packages[package_ahriman.base].architecture = "i686"
|
||||||
|
|
||||||
result.with_packages(paths)
|
result.with_packages(paths, pacman)
|
||||||
from_archive_mock.assert_has_calls([
|
from_archive_mock.assert_has_calls([
|
||||||
MockCall(path) for path in paths
|
MockCall(path, pacman) for path in paths
|
||||||
])
|
])
|
||||||
assert result.packages[result.base] == package_ahriman.packages[package_ahriman.base]
|
assert result.packages[result.base] == package_ahriman.packages[package_ahriman.base]
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from ahriman.core.exceptions import InitializeError
|
|||||||
from ahriman.core.spawn import Spawn
|
from ahriman.core.spawn import Spawn
|
||||||
from ahriman.core.status.watcher import Watcher
|
from ahriman.core.status.watcher import Watcher
|
||||||
from ahriman.web.keys import ConfigurationKey
|
from ahriman.web.keys import ConfigurationKey
|
||||||
from ahriman.web.web import _create_socket, _create_watcher, _on_shutdown, _on_startup, run_server, setup_server
|
from ahriman.web.web import _create_socket, _on_shutdown, _on_startup, run_server, setup_server
|
||||||
|
|
||||||
|
|
||||||
async def test_create_socket(application: Application, mocker: MockerFixture) -> None:
|
async def test_create_socket(application: Application, mocker: MockerFixture) -> None:
|
||||||
@@ -139,20 +139,6 @@ def test_run_with_socket(application: Application, mocker: MockerFixture) -> Non
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_watcher(configuration: Configuration, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must create watcher for repository
|
|
||||||
"""
|
|
||||||
database_mock = mocker.patch("ahriman.core.database.SQLite.load")
|
|
||||||
client_mock = mocker.patch("ahriman.core.status.Client.load")
|
|
||||||
configuration_path, repository_id = configuration.check_loaded()
|
|
||||||
|
|
||||||
result = _create_watcher(configuration_path, repository_id)
|
|
||||||
assert isinstance(result, Watcher)
|
|
||||||
database_mock.assert_called_once()
|
|
||||||
client_mock.assert_called_once()
|
|
||||||
|
|
||||||
|
|
||||||
def test_setup_no_repositories(configuration: Configuration, spawner: Spawn) -> None:
|
def test_setup_no_repositories(configuration: Configuration, spawner: Spawn) -> None:
|
||||||
"""
|
"""
|
||||||
must raise InitializeError if no repositories set
|
must raise InitializeError if no repositories set
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
from aiohttp.test_utils import TestClient
|
|
||||||
from pytest_mock import MockerFixture
|
|
||||||
|
|
||||||
from ahriman.models.build_status import BuildStatusEnum
|
|
||||||
from ahriman.models.package import Package
|
|
||||||
from ahriman.models.user_access import UserAccess
|
|
||||||
from ahriman.web.views.v1.packages.archives import Archives
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_permission() -> None:
|
|
||||||
"""
|
|
||||||
must return correct permission for the request
|
|
||||||
"""
|
|
||||||
for method in ("GET",):
|
|
||||||
request = pytest.helpers.request("", "", method)
|
|
||||||
assert await Archives.get_permission(request) == UserAccess.Reporter
|
|
||||||
|
|
||||||
|
|
||||||
def test_routes() -> None:
|
|
||||||
"""
|
|
||||||
must return correct routes
|
|
||||||
"""
|
|
||||||
assert Archives.ROUTES == ["/api/v1/packages/{package}/archives"]
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get(client: TestClient, package_ahriman: Package, mocker: MockerFixture) -> None:
|
|
||||||
"""
|
|
||||||
must get archives for package
|
|
||||||
"""
|
|
||||||
await client.post(f"/api/v1/packages/{package_ahriman.base}",
|
|
||||||
json={"status": BuildStatusEnum.Success.value, "package": package_ahriman.view()})
|
|
||||||
mocker.patch("ahriman.core.status.watcher.Watcher.package_archives", return_value=[package_ahriman])
|
|
||||||
response_schema = pytest.helpers.schema_response(Archives.get)
|
|
||||||
|
|
||||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/archives")
|
|
||||||
assert response.status == 200
|
|
||||||
|
|
||||||
archives = await response.json()
|
|
||||||
assert not response_schema.validate(archives)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_get_not_found(client: TestClient, package_ahriman: Package) -> None:
|
|
||||||
"""
|
|
||||||
must return not found for missing package
|
|
||||||
"""
|
|
||||||
response_schema = pytest.helpers.schema_response(Archives.get, code=404)
|
|
||||||
|
|
||||||
response = await client.get(f"/api/v1/packages/{package_ahriman.base}/archives")
|
|
||||||
assert response.status == 404
|
|
||||||
assert not response_schema.validate(await response.json())
|
|
||||||
Reference in New Issue
Block a user