add possibility to run full update

In case if packages are not set from web, the spawner will run full
repository update
This commit is contained in:
Evgenii Alekseev 2022-10-31 02:41:24 +02:00
parent 8e2732f6fe
commit 09678a3ae1
6 changed files with 20 additions and 26 deletions

View File

@ -27,7 +27,7 @@
<button id="add-btn" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-form" hidden>
<i class="bi bi-plus"></i> add
</button>
<button id="update-btn" class="btn btn-secondary" onclick="updatePackages()" disabled hidden>
<button id="update-btn" class="btn btn-secondary" onclick="updatePackages()" hidden>
<i class="bi bi-play"></i> update
</button>
<button id="remove-btn" class="btn btn-danger" onclick="removePackages()" disabled hidden>

View File

@ -7,7 +7,6 @@
table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table",
() => {
removeButton.prop("disabled", !table.bootstrapTable("getSelections").length);
updateButton.prop("disabled", !table.bootstrapTable("getSelections").length);
});
const architectureBadge = $("#badge-architecture");
@ -16,8 +15,6 @@
const versionBadge = $("#badge-version");
function doPackageAction(uri, packages) {
if (packages.length === 0)
return;
$.ajax({
url: uri,
data: JSON.stringify({packages: packages}),

View File

@ -86,10 +86,12 @@ class Spawn(Thread, LazyLogging):
packages(Iterable[str]): packages list to add
now(bool): build packages now
"""
if not packages:
return self.spawn_process("repo-update")
kwargs = {"source": PackageSource.AUR.value} # avoid abusing by building non-aur packages
if now:
kwargs["now"] = ""
self.spawn_process("add", *packages, **kwargs)
return self.spawn_process("package-add", *packages, **kwargs)
def packages_remove(self, packages: Iterable[str]) -> None:
"""
@ -98,7 +100,7 @@ class Spawn(Thread, LazyLogging):
Args:
packages(Iterable[str]): packages list to remove
"""
self.spawn_process("remove", *packages)
self.spawn_process("package-remove", *packages)
def spawn_process(self, command: str, *args: str, **kwargs: str) -> None:
"""

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from aiohttp.web import HTTPBadRequest, HTTPFound
from aiohttp.web import HTTPFound
from ahriman.models.user_access import UserAccess
from ahriman.web.views.base import BaseView
@ -47,11 +47,8 @@ class AddView(BaseView):
HTTPBadRequest: if bad data is supplied
HTTPFound: in case of success response
"""
try:
data = await self.extract_data(["packages"])
packages = data["packages"]
except Exception as e:
raise HTTPBadRequest(reason=str(e))
data = await self.extract_data(["packages"])
packages = data.get("packages", [])
self.spawner.packages_add(packages, now=True)

View File

@ -42,7 +42,7 @@ def test_packages_add(spawner: Spawn, mocker: MockerFixture) -> None:
"""
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
spawner.packages_add(["ahriman", "linux"], now=False)
spawn_mock.assert_called_once_with("add", "ahriman", "linux", source="aur")
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur")
def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
@ -51,7 +51,16 @@ def test_packages_add_with_build(spawner: Spawn, mocker: MockerFixture) -> None:
"""
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
spawner.packages_add(["ahriman", "linux"], now=True)
spawn_mock.assert_called_once_with("add", "ahriman", "linux", source="aur", now="")
spawn_mock.assert_called_once_with("package-add", "ahriman", "linux", source="aur", now="")
def test_packages_add_update(spawner: Spawn, mocker: MockerFixture) -> None:
"""
must call repo update
"""
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
spawner.packages_add([], now=False)
spawn_mock.assert_called_once_with("repo-update")
def test_packages_remove(spawner: Spawn, mocker: MockerFixture) -> None:
@ -60,7 +69,7 @@ def test_packages_remove(spawner: Spawn, mocker: MockerFixture) -> None:
"""
spawn_mock = mocker.patch("ahriman.core.spawn.Spawn.spawn_process")
spawner.packages_remove(["ahriman", "linux"])
spawn_mock.assert_called_once_with("remove", "ahriman", "linux")
spawn_mock.assert_called_once_with("package-remove", "ahriman", "linux")
def test_spawn_process(spawner: Spawn, mocker: MockerFixture) -> None:

View File

@ -27,17 +27,6 @@ async def test_post(client: TestClient, mocker: MockerFixture) -> None:
add_mock.assert_called_once_with(["ahriman"], now=True)
async def test_post_exception(client: TestClient, mocker: MockerFixture) -> None:
"""
must raise exception on missing packages payload
"""
add_mock = mocker.patch("ahriman.core.spawn.Spawn.packages_add")
response = await client.post("/api/v1/service/add")
assert response.status == 400
add_mock.assert_not_called()
async def test_post_update(client: TestClient, mocker: MockerFixture) -> None:
"""
must call post request correctly for alias