From: Michael Tremer Date: Sun, 1 Oct 2023 10:58:26 +0000 (+0000) Subject: _pakfire: Drop the Python wrapper for the progress bar X-Git-Tag: 0.9.30~1586 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c61eff1450b011f55fa2d1e6b382c4d1eee00a66;p=pakfire.git _pakfire: Drop the Python wrapper for the progress bar Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 270339ba2..121ca9540 100644 --- a/Makefile.am +++ b/Makefile.am @@ -153,8 +153,6 @@ _pakfire_la_SOURCES = \ src/_pakfire/pakfire.h \ src/_pakfire/problem.c \ src/_pakfire/problem.h \ - src/_pakfire/progressbar.c \ - src/_pakfire/progressbar.h \ src/_pakfire/repo.c \ src/_pakfire/repo.h \ src/_pakfire/solution.c \ @@ -1020,7 +1018,6 @@ dist_check_SCRIPTS = \ tests/python/keys.py \ tests/python/jail.py \ tests/python/package.py \ - tests/python/progressbar.py \ tests/python/test.py TESTS = \ diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index c0c0ce2a9..b16b65a8a 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -33,7 +33,6 @@ #include "package.h" #include "pakfire.h" #include "problem.h" -#include "progressbar.h" #include "repo.h" #include "solution.h" #include "util.h" @@ -223,12 +222,6 @@ PyMODINIT_FUNC PyInit__pakfire(void) { Py_INCREF(&ProblemType); PyModule_AddObject(module, "Problem", (PyObject *)&ProblemType); - // Progressbar - if (PyType_Ready(&ProgressbarType) < 0) - return NULL; - Py_INCREF(&ProgressbarType); - PyModule_AddObject(module, "Progressbar", (PyObject *)&ProgressbarType); - // Repo if (PyType_Ready(&RepoType) < 0) return NULL; diff --git a/src/_pakfire/progressbar.c b/src/_pakfire/progressbar.c deleted file mode 100644 index 35dc840e4..000000000 --- a/src/_pakfire/progressbar.c +++ /dev/null @@ -1,344 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2021 Pakfire development team # -# # -# 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 . # -# # -#############################################################################*/ - -#define PY_SSIZE_T_CLEAN -#include - -#include - -#include "progressbar.h" - -static PyObject* Progressbar_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { - ProgressbarObject* self = (ProgressbarObject *)type->tp_alloc(type, 0); - if (self) { - self->progressbar = NULL; - } - - return (PyObject *)self; -} - -static void Progressbar_dealloc(ProgressbarObject* self) { - if (self->progressbar) - pakfire_progressbar_unref(self->progressbar); - - Py_TYPE(self)->tp_free((PyObject *)self); -} - -static int Progressbar_init(ProgressbarObject* self, PyObject* args, PyObject* kwds) { - int r = pakfire_progressbar_create(&self->progressbar, NULL); - if (r) - return -1; - - return 0; -} - -static PyObject* Progressbar_start(ProgressbarObject* self, PyObject* args) { - unsigned long value = 0; - - if (!PyArg_ParseTuple(args, "k", &value)) - return NULL; - - int r = pakfire_progressbar_start(self->progressbar, value); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_update(ProgressbarObject* self, PyObject* args) { - unsigned long value = 0; - - if (!PyArg_ParseTuple(args, "k", &value)) - return NULL; - - int r = pakfire_progressbar_update(self->progressbar, value); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_increment(ProgressbarObject* self, PyObject* args) { - unsigned long value = 1; - - if (!PyArg_ParseTuple(args, "|k", &value)) - return NULL; - - int r = pakfire_progressbar_increment(self->progressbar, value); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_finish(ProgressbarObject* self) { - int r = pakfire_progressbar_finish(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_reset(ProgressbarObject* self) { - int r = pakfire_progressbar_reset(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_set_max(ProgressbarObject* self, PyObject* args) { - unsigned long value = 0; - - if (!PyArg_ParseTuple(args, "k", &value)) - return NULL; - - pakfire_progressbar_set_max(self->progressbar, value); - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_string(ProgressbarObject* self, PyObject* args) { - const char* string = NULL; - - if (!PyArg_ParseTuple(args, "s", &string)) - return NULL; - - int r = pakfire_progressbar_add_string(self->progressbar, "%s", string); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_counter(ProgressbarObject* self) { - int r = pakfire_progressbar_add_counter(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_percentage(ProgressbarObject* self) { - int r = pakfire_progressbar_add_percentage(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_bar(ProgressbarObject* self) { - int r = pakfire_progressbar_add_bar(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_timer(ProgressbarObject* self) { - int r = pakfire_progressbar_add_timer(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_bytes_transferred(ProgressbarObject* self) { - int r = pakfire_progressbar_add_bytes_transferred(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_eta(ProgressbarObject* self) { - int r = pakfire_progressbar_add_eta(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_add_transfer_speed(ProgressbarObject* self) { - int r = pakfire_progressbar_add_transfer_speed(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static PyObject* Progressbar_enter(ProgressbarObject* self) { - int r = pakfire_progressbar_start(self->progressbar, 0); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - // Return self - Py_INCREF(self); - return (PyObject*)self; -} - -static PyObject* Progressbar_exit(ProgressbarObject* self, PyObject* args) { - int r = pakfire_progressbar_finish(self->progressbar); - if (r) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - Py_RETURN_NONE; -} - -static struct PyMethodDef Progressbar_methods[] = { - { - "start", - (PyCFunction)Progressbar_start, - METH_VARARGS, - NULL, - }, - { - "update", - (PyCFunction)Progressbar_update, - METH_VARARGS, - NULL, - }, - { - "increment", - (PyCFunction)Progressbar_increment, - METH_VARARGS, - NULL, - }, - { - "finish", - (PyCFunction)Progressbar_finish, - METH_NOARGS, - NULL, - }, - { - "reset", - (PyCFunction)Progressbar_reset, - METH_NOARGS, - NULL, - }, - { - "set_max", - (PyCFunction)Progressbar_set_max, - METH_VARARGS, - NULL, - }, - { - "add_string", - (PyCFunction)Progressbar_add_string, - METH_VARARGS, - NULL, - }, - { - "add_counter", - (PyCFunction)Progressbar_add_counter, - METH_NOARGS, - NULL, - }, - { - "add_percentage", - (PyCFunction)Progressbar_add_percentage, - METH_NOARGS, - NULL, - }, - { - "add_bar", - (PyCFunction)Progressbar_add_bar, - METH_NOARGS, - NULL, - }, - { - "add_timer", - (PyCFunction)Progressbar_add_timer, - METH_NOARGS, - NULL, - }, - { - "add_bytes_transferred", - (PyCFunction)Progressbar_add_bytes_transferred, - METH_NOARGS, - NULL, - }, - { - "add_eta", - (PyCFunction)Progressbar_add_eta, - METH_NOARGS, - NULL, - }, - { - "add_transfer_speed", - (PyCFunction)Progressbar_add_transfer_speed, - METH_NOARGS, - NULL, - }, - { - "__enter__", - (PyCFunction)Progressbar_enter, - METH_NOARGS, - NULL, - }, - { - "__exit__", - (PyCFunction)Progressbar_exit, - METH_VARARGS, - NULL, - }, - { NULL }, -}; - -PyTypeObject ProgressbarType = { - PyVarObject_HEAD_INIT(NULL, 0) - tp_name: "_pakfire.Progressbar", - tp_basicsize: sizeof(ProgressbarObject), - tp_flags: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - tp_new: (newfunc)Progressbar_new, - tp_dealloc: (destructor)Progressbar_dealloc, - tp_init: (initproc)Progressbar_init, - tp_doc: "Progressbar Object", - tp_methods: Progressbar_methods, -}; diff --git a/src/_pakfire/progressbar.h b/src/_pakfire/progressbar.h deleted file mode 100644 index f3b5b2c65..000000000 --- a/src/_pakfire/progressbar.h +++ /dev/null @@ -1,35 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2021 Pakfire development team # -# # -# 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 . # -# # -#############################################################################*/ - -#ifndef PYTHON_PAKFIRE_PROGRESSBAR_H -#define PYTHON_PAKFIRE_PROGRESSBAR_H - -#include - -#include - -typedef struct { - PyObject_HEAD - struct pakfire_progressbar* progressbar; -} ProgressbarObject; - -extern PyTypeObject ProgressbarType; - -#endif /* PYTHON_PAKFIRE_PROGRESSBAR_H */ diff --git a/tests/python/progressbar.py b/tests/python/progressbar.py deleted file mode 100755 index caf452ea8..000000000 --- a/tests/python/progressbar.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/python3 - -import pakfire -import time -import unittest - -from pakfire._pakfire import Progressbar - -class Test(unittest.TestCase): - """ - This tests the progressbar command - """ - def test_simple(self): - p = Progressbar() - - # Add a string - p.add_string("Progress...") - - # Add the bar - p.add_bar() - - # Show the percentage - p.add_percentage() - - # Show ETA - p.add_eta() - - # Start the progressbar - p.start(1000) - - for i in range(1000): - p.update(i) - - p.finish() - - def test_context(self): - p = Progressbar() - - p.add_string("Progress...") - p.add_bar() - - p.set_max(1000) - - with p: - p.set_max(1000) - - for i in range(1000): - p.increment() - - -if __name__ == "__main__": - unittest.main()