From: Michael Tremer Date: Sun, 29 Jun 2025 12:35:24 +0000 (+0000) Subject: python: Rename Pakfire() to Root() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68b2d365c01c0e0e3b4b3e982245622a48f39db8;p=pakfire.git python: Rename Pakfire() to Root() Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index e9da5ef4..b55aeb60 100644 --- a/Makefile.am +++ b/Makefile.am @@ -117,12 +117,12 @@ pakfire_la_SOURCES = \ src/python/key.h \ src/python/package.c \ src/python/package.h \ - src/python/pakfire.c \ - src/python/pakfire.h \ src/python/problem.c \ src/python/problem.h \ src/python/repo.c \ src/python/repo.h \ + src/python/root.c \ + src/python/root.h \ src/python/solution.c \ src/python/solution.h \ src/python/transaction.c \ diff --git a/src/python/archive.c b/src/python/archive.c index 93556309..03069334 100644 --- a/src/python/archive.c +++ b/src/python/archive.c @@ -33,6 +33,7 @@ #include "key.h" #include "package.h" #include "repo.h" +#include "root.h" #include "util.h" PyObject* new_archive(PyTypeObject* type, pakfire_archive* archive) { @@ -60,13 +61,13 @@ static void Archive_dealloc(ArchiveObject* self) { } static int Archive_init(ArchiveObject* self, PyObject* args, PyObject* kwds) { - PakfireObject* pakfire = NULL; + RootObject* root = NULL; const char* filename = NULL; - if (!PyArg_ParseTuple(args, "O!s", &PakfireType, &pakfire, &filename)) + if (!PyArg_ParseTuple(args, "O!s", &RootType, &root, &filename)) return -1; - errno = -pakfire_archive_open(&self->archive, pakfire->root, filename); + errno = -pakfire_archive_open(&self->archive, root->root, filename); if (errno) { PyErr_SetFromErrno(PyExc_OSError); return -1; diff --git a/src/python/file.c b/src/python/file.c index 131df766..ac74cf08 100644 --- a/src/python/file.c +++ b/src/python/file.c @@ -25,7 +25,7 @@ #include #include "file.h" -#include "pakfire.h" +#include "root.h" #include "util.h" PyObject* new_file(PyTypeObject* type, pakfire_file* file) { diff --git a/src/python/key.c b/src/python/key.c index 08ab8f6a..a604a3a9 100644 --- a/src/python/key.c +++ b/src/python/key.c @@ -25,7 +25,7 @@ #include #include "key.h" -#include "pakfire.h" +#include "root.h" #include "util.h" PyObject* new_key(PyTypeObject* type, pakfire_key* key) { diff --git a/src/python/package.c b/src/python/package.c index 044cc0b4..9490cdfb 100644 --- a/src/python/package.c +++ b/src/python/package.c @@ -31,8 +31,8 @@ #include "errors.h" #include "package.h" -#include "pakfire.h" #include "repo.h" +#include "root.h" #include "util.h" PyObject* new_package(PyTypeObject* type, pakfire_package* pkg) { @@ -61,7 +61,7 @@ static void Package_dealloc(PackageObject* self) { } static int Package_init(PackageObject* self, PyObject* args, PyObject* kwds) { - PakfireObject* pakfire = NULL; + RootObject* root = NULL; RepoObject* repo = NULL; const char* name = NULL; const char* evr = NULL; @@ -69,11 +69,11 @@ static int Package_init(PackageObject* self, PyObject* args, PyObject* kwds) { int r; if (!PyArg_ParseTuple(args, "O!O!sss", - &PakfireType, &pakfire, &RepoType, &repo, &name, &evr, &arch)) + &RootType, &root, &RepoType, &repo, &name, &evr, &arch)) return -1; // Create the package object - r = pakfire_package_create(&self->package, pakfire->root, repo->repo, name, evr, arch); + r = pakfire_package_create(&self->package, root->root, repo->repo, name, evr, arch); if (r < 0) { errno = -r; PyErr_SetFromErrno(PyExc_OSError); diff --git a/src/python/package.h b/src/python/package.h index 2926e23e..e1c9f55a 100644 --- a/src/python/package.h +++ b/src/python/package.h @@ -23,11 +23,8 @@ #include -#include #include -#include "pakfire.h" - typedef struct { PyObject_HEAD pakfire_package* package; diff --git a/src/python/pakfiremodule.c b/src/python/pakfiremodule.c index ebd0eb05..0fa05701 100644 --- a/src/python/pakfiremodule.c +++ b/src/python/pakfiremodule.c @@ -31,9 +31,9 @@ #include "file.h" #include "key.h" #include "package.h" -#include "pakfire.h" #include "problem.h" #include "repo.h" +#include "root.h" #include "solution.h" #include "transaction.h" #include "util.h" @@ -121,13 +121,6 @@ PyMODINIT_FUNC PyInit_pakfire(void) { Py_INCREF(PyExc_DependencyError); PyModule_AddObject(module, "DependencyError", PyExc_DependencyError); - // Pakfire - if (PyType_Ready(&PakfireType) < 0) - return NULL; - - Py_INCREF(&PakfireType); - PyModule_AddObject(module, "Pakfire", (PyObject *)&PakfireType); - // Archive if (PyType_Ready(&ArchiveType) < 0) return NULL; @@ -183,6 +176,13 @@ PyMODINIT_FUNC PyInit_pakfire(void) { Py_INCREF(&RepoType); PyModule_AddObject(module, "Repo", (PyObject *)&RepoType); + // Root + if (PyType_Ready(&RootType) < 0) + return NULL; + + Py_INCREF(&RootType); + PyModule_AddObject(module, "Root", (PyObject *)&RootType); + // Solution if (PyType_Ready(&SolutionType) < 0) return NULL; diff --git a/src/python/repo.c b/src/python/repo.c index 985399ab..bdae582d 100644 --- a/src/python/repo.c +++ b/src/python/repo.c @@ -29,6 +29,7 @@ #include "key.h" #include "package.h" #include "repo.h" +#include "root.h" PyObject* new_repo(PyTypeObject* type, pakfire_repo* repo) { RepoObject* self = (RepoObject *)type->tp_alloc(type, 0); @@ -56,15 +57,15 @@ static void Repo_dealloc(RepoObject* self) { } static int Repo_init(RepoObject* self, PyObject* args, PyObject* kwds) { - PakfireObject* pakfire; + RootObject* root = NULL; const char* name; int clean = 0; - if (!PyArg_ParseTuple(args, "O!s|i", &PakfireType, &pakfire, &name, &clean)) + if (!PyArg_ParseTuple(args, "O!s|i", &RootType, &root, &name, &clean)) return -1; // Create a new repository - int r = pakfire_repo_create(&self->repo, pakfire->root, name); + int r = pakfire_repo_create(&self->repo, root->root, name); if (r) { PyErr_SetFromErrno(PyExc_OSError); return -1; diff --git a/src/python/repo.h b/src/python/repo.h index 161cbb8e..b36488ad 100644 --- a/src/python/repo.h +++ b/src/python/repo.h @@ -25,8 +25,6 @@ #include -#include "pakfire.h" - typedef struct { PyObject_HEAD pakfire_repo* repo; diff --git a/src/python/pakfire.c b/src/python/root.c similarity index 86% rename from src/python/pakfire.c rename to src/python/root.c index 7ffa451d..afc3df67 100644 --- a/src/python/pakfire.c +++ b/src/python/root.c @@ -44,12 +44,12 @@ #include "ctx.h" #include "errors.h" #include "key.h" -#include "pakfire.h" #include "repo.h" +#include "root.h" #include "util.h" -static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { - PakfireObject* self = (PakfireObject *)type->tp_alloc(type, 0); +static PyObject* Root_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { + RootObject* self = (RootObject *)type->tp_alloc(type, 0); if (self) { self->ctx = NULL; self->root = NULL; @@ -58,7 +58,7 @@ static PyObject* Pakfire_new(PyTypeObject* type, PyObject* args, PyObject* kwds) return (PyObject *)self; } -static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { +static int Root_init(RootObject* self, PyObject* args, PyObject* kwds) { const char* kwlist[] = { "ctx", "path", "arch", "config", "stub", NULL }; pakfire_config* c = NULL; const char* config = NULL; @@ -120,7 +120,7 @@ ERROR: return r; } -static void Pakfire_dealloc(PakfireObject* self) { +static void Root_dealloc(RootObject* self) { Py_BEGIN_ALLOW_THREADS if (self->root) @@ -133,26 +133,26 @@ static void Pakfire_dealloc(PakfireObject* self) { Py_TYPE(self)->tp_free((PyObject *)self); } -static PyObject* Pakfire_repr(PakfireObject* self) { +static PyObject* Root_repr(RootObject* self) { const char* path = pakfire_root_get_path(self->root); const char* arch = pakfire_root_get_arch(self->root); - return PyUnicode_FromFormat("<_pakfire.Pakfire %s (%s)>", path, arch); + return PyUnicode_FromFormat("<_pakfire.Root %s (%s)>", path, arch); } -static PyObject* Pakfire_get_path(PakfireObject* self) { +static PyObject* Root_get_path(RootObject* self) { const char* path = pakfire_root_get_path(self->root); return PyUnicode_FromString(path); } -static PyObject* Pakfire_get_arch(PakfireObject* self) { +static PyObject* Root_get_arch(RootObject* self) { const char* arch = pakfire_root_get_arch(self->root); return PyUnicode_FromString(arch); } -static PyObject* Pakfire_get_repo(PakfireObject* self, PyObject* args) { +static PyObject* Root_get_repo(RootObject* self, PyObject* args) { const char* name = NULL; if (!PyArg_ParseTuple(args, "s", &name)) @@ -171,7 +171,7 @@ static PyObject* Pakfire_get_repo(PakfireObject* self, PyObject* args) { /* XXX This could be moved out of here as this no longer depends on Pakfire */ -static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args, PyObject* kwds) { +static PyObject* Root_generate_key(RootObject* self, PyObject* args, PyObject* kwds) { const char* kwlist[] = { "algorithm", "comment", NULL }; pakfire_key* key = NULL; pakfire_key_algo_t algo = PAKFIRE_KEY_ALGO_NULL; @@ -195,7 +195,7 @@ static PyObject* Pakfire_generate_key(PakfireObject* self, PyObject* args, PyObj /* XXX This could be moved out of here as this no longer depends on Pakfire */ -static PyObject* Pakfire_import_key(PakfireObject* self, PyObject* args) { +static PyObject* Root_import_key(RootObject* self, PyObject* args) { pakfire_key* key = NULL; PyObject* object = NULL; char* data = NULL; @@ -232,7 +232,7 @@ ERROR: return object; } -static PyObject* Pakfire_whatprovides(PakfireObject* self, PyObject* args) { +static PyObject* Root_whatprovides(RootObject* self, PyObject* args) { const char* provides = NULL; pakfire_packagelist* list = NULL; PyObject* ret = NULL; @@ -266,7 +266,7 @@ ERROR: return ret; } -static PyObject* Pakfire_whatrequires(PakfireObject* self, PyObject* args) { +static PyObject* Root_whatrequires(RootObject* self, PyObject* args) { pakfire_packagelist* list = NULL; const char* requires = NULL; PyObject* ret = NULL; @@ -306,7 +306,7 @@ ERROR: return ret; } -static PyObject* Pakfire_search(PakfireObject* self, PyObject* args, PyObject* kwds) { +static PyObject* Root_search(RootObject* self, PyObject* args, PyObject* kwds) { const char* kwlist[] = { "pattern", "name_only", NULL }; pakfire_packagelist* list = NULL; const char* pattern = NULL; @@ -345,7 +345,7 @@ ERROR: return ret; } -static PyObject* Pakfire_version_compare(PakfireObject* self, PyObject* args) { +static PyObject* Root_version_compare(RootObject* self, PyObject* args) { const char* evr1 = NULL; const char* evr2 = NULL; @@ -357,7 +357,7 @@ static PyObject* Pakfire_version_compare(PakfireObject* self, PyObject* args) { return PyLong_FromLong(cmp); } -static PyObject* Pakfire_dist(PakfireObject* self, PyObject* args) { +static PyObject* Root_dist(RootObject* self, PyObject* args) { pakfire_archive* archive = NULL; const char* path = NULL; PyObject* ret = NULL; @@ -387,7 +387,7 @@ static PyObject* Pakfire_dist(PakfireObject* self, PyObject* args) { return ret; } -static PyObject* Pakfire_get_repos(PakfireObject* self) { +static PyObject* Root_get_repos(RootObject* self) { pakfire_repolist* repos = pakfire_root_get_repos(self->root); if (!repos) { PyErr_SetFromErrno(PyExc_OSError); @@ -417,7 +417,7 @@ ERROR: return list; } -static PyObject* Pakfire_clean(PakfireObject* self) { +static PyObject* Root_clean(RootObject* self) { int r; Py_BEGIN_ALLOW_THREADS @@ -434,7 +434,7 @@ static PyObject* Pakfire_clean(PakfireObject* self) { Py_RETURN_NONE; } -static PyObject* Pakfire_open(PakfireObject* self, PyObject* args) { +static PyObject* Root_open(RootObject* self, PyObject* args) { pakfire_archive* archive = NULL; const char* path = NULL; @@ -459,7 +459,7 @@ static PyObject* Pakfire_open(PakfireObject* self, PyObject* args) { return object; } -static PyObject* Pakfire_repo_compose(PakfireObject* self, PyObject* args, PyObject* kwargs) { +static PyObject* Root_repo_compose(RootObject* self, PyObject* args, PyObject* kwargs) { const char* kwlist[] = { "path", "files", "key", NULL }; const char* path = NULL; PyObject* list = NULL; @@ -539,7 +539,7 @@ struct Pakfire_execute_output { PyObject* stderr; }; -static int Pakfire_execute_stdout_callback(pakfire_ctx* ctx, void* data, +static int Root_execute_stdout_callback(pakfire_ctx* ctx, void* data, const enum pakfire_jail_output_stream stream, const char* line, const size_t length) { struct Pakfire_execute_output* output = data; PyObject* chunk = NULL; @@ -563,7 +563,7 @@ static int Pakfire_execute_stdout_callback(pakfire_ctx* ctx, void* data, return 0; } -static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* kwargs) { +static PyObject* Root_execute(RootObject* self, PyObject* args, PyObject* kwargs) { struct pakfire_input_buffer input = {}; pakfire_jail* jail = NULL; pakfire_env* env = NULL; @@ -738,7 +738,7 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject* // Execute command r = pakfire_jail_communicate(jail, argv, env, 0, - input_callback, &input, Pakfire_execute_stdout_callback, &output); + input_callback, &input, Root_execute_stdout_callback, &output); Py_END_ALLOW_THREADS @@ -785,100 +785,100 @@ ERROR: return ret; } -static struct PyMethodDef Pakfire_methods[] = { +static struct PyMethodDef Root_methods[] = { { "clean", - (PyCFunction)Pakfire_clean, + (PyCFunction)Root_clean, METH_NOARGS, NULL, }, { "dist", - (PyCFunction)Pakfire_dist, + (PyCFunction)Root_dist, METH_VARARGS, NULL }, { "execute", - (PyCFunction)Pakfire_execute, + (PyCFunction)Root_execute, METH_VARARGS|METH_KEYWORDS, NULL, }, { "generate_key", - (PyCFunction)Pakfire_generate_key, + (PyCFunction)Root_generate_key, METH_VARARGS|METH_KEYWORDS, NULL }, { "get_repo", - (PyCFunction)Pakfire_get_repo, + (PyCFunction)Root_get_repo, METH_VARARGS, NULL }, { "import_key", - (PyCFunction)Pakfire_import_key, + (PyCFunction)Root_import_key, METH_VARARGS, NULL, }, { "open", - (PyCFunction)Pakfire_open, + (PyCFunction)Root_open, METH_VARARGS, NULL }, { "repo_compose", - (PyCFunction)Pakfire_repo_compose, + (PyCFunction)Root_repo_compose, METH_VARARGS|METH_KEYWORDS, NULL }, { "search", - (PyCFunction)Pakfire_search, + (PyCFunction)Root_search, METH_VARARGS|METH_KEYWORDS, NULL }, { "version_compare", - (PyCFunction)Pakfire_version_compare, + (PyCFunction)Root_version_compare, METH_VARARGS, NULL }, { "whatprovides", - (PyCFunction)Pakfire_whatprovides, + (PyCFunction)Root_whatprovides, METH_VARARGS, NULL }, { "whatrequires", - (PyCFunction)Pakfire_whatrequires, + (PyCFunction)Root_whatrequires, METH_VARARGS, NULL }, { NULL }, }; -static struct PyGetSetDef Pakfire_getsetters[] = { +static struct PyGetSetDef Root_getsetters[] = { { "arch", - (getter)Pakfire_get_arch, + (getter)Root_get_arch, NULL, NULL, NULL }, { "path", - (getter)Pakfire_get_path, + (getter)Root_get_path, NULL, NULL, NULL }, { "repos", - (getter)Pakfire_get_repos, + (getter)Root_get_repos, NULL, NULL, NULL @@ -886,16 +886,16 @@ static struct PyGetSetDef Pakfire_getsetters[] = { { NULL }, }; -PyTypeObject PakfireType = { +PyTypeObject RootType = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "pakfire.Pakfire", - .tp_basicsize = sizeof(PakfireObject), + .tp_name = "pakfire.Root", + .tp_basicsize = sizeof(RootObject), .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - .tp_new = Pakfire_new, - .tp_dealloc = (destructor)Pakfire_dealloc, - .tp_init = (initproc)Pakfire_init, - .tp_doc = "Pakfire Object", - .tp_methods = Pakfire_methods, - .tp_getset = Pakfire_getsetters, - .tp_repr = (reprfunc)Pakfire_repr, + .tp_new = Root_new, + .tp_dealloc = (destructor)Root_dealloc, + .tp_init = (initproc)Root_init, + .tp_doc = "Root Object", + .tp_methods = Root_methods, + .tp_getset = Root_getsetters, + .tp_repr = (reprfunc)Root_repr, }; diff --git a/src/python/pakfire.h b/src/python/root.h similarity index 91% rename from src/python/pakfire.h rename to src/python/root.h index d805986b..2cad39e0 100644 --- a/src/python/pakfire.h +++ b/src/python/root.h @@ -18,8 +18,8 @@ # # #############################################################################*/ -#ifndef PYTHON_PAKFIRE_PAKFIRE_H -#define PYTHON_PAKFIRE_PAKFIRE_H +#ifndef PYTHON_PAKFIRE_ROOT_H +#define PYTHON_PAKFIRE_ROOT_H #include @@ -35,8 +35,8 @@ typedef struct { // Root pakfire_root* root; -} PakfireObject; +} RootObject; -extern PyTypeObject PakfireType; +extern PyTypeObject RootType; -#endif /* PYTHON_PAKFIRE_PAKFIRE_H */ +#endif /* PYTHON_PAKFIRE_ROOT_H */ diff --git a/src/python/transaction.c b/src/python/transaction.c index 54c94ddb..cb447020 100644 --- a/src/python/transaction.c +++ b/src/python/transaction.c @@ -24,7 +24,7 @@ #include #include "errors.h" -#include "pakfire.h" +#include "root.h" #include "transaction.h" static PyObject* Transaction_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { @@ -44,7 +44,7 @@ static void Transaction_dealloc(TransactionObject* self) { } static int Transaction_init(TransactionObject* self, PyObject* args, PyObject* kwargs) { - PakfireObject* pakfire = NULL; + RootObject* root = NULL; int allow_downgrade = 0; int allow_uninstall = 0; int without_recommended = 0; @@ -60,7 +60,7 @@ static int Transaction_init(TransactionObject* self, PyObject* args, PyObject* k }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|bbb", (char**)kwlist, - &PakfireType, &pakfire, &allow_downgrade, &allow_uninstall, &without_recommended)) + &RootType, &root, &allow_downgrade, &allow_uninstall, &without_recommended)) return -1; if (allow_downgrade) @@ -73,7 +73,7 @@ static int Transaction_init(TransactionObject* self, PyObject* args, PyObject* k flags |= PAKFIRE_TRANSACTION_WITHOUT_RECOMMENDED; // Create a new transaction - r = pakfire_transaction_create(&self->transaction, pakfire->root, flags); + r = pakfire_transaction_create(&self->transaction, root->root, flags); if (r < 0) { errno = -r; PyErr_SetFromErrno(PyExc_OSError); diff --git a/tests/python/archive.py b/tests/python/archive.py index 7bdaa6c3..faf3b4c7 100755 --- a/tests/python/archive.py +++ b/tests/python/archive.py @@ -12,7 +12,7 @@ class ArchiveTest(tests.TestCase): This tests the Package class """ def setUp(self): - self.pakfire = self.setup_pakfire() + self.root = self.setup_root() def test_open(self): """ @@ -21,7 +21,7 @@ class ArchiveTest(tests.TestCase): path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - archive = self.pakfire.open(path) + archive = self.root.open(path) # Read back the path self.assertEqual(archive.path, path) @@ -36,7 +36,7 @@ class ArchiveTest(tests.TestCase): path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - archive = self.pakfire.open(path) + archive = self.root.open(path) # Check that we read the entire list of 7 files self.assertEqual(len(archive.filelist), 7) @@ -80,7 +80,7 @@ class ArchiveTest(tests.TestCase): path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - archive = self.pakfire.open(path) + archive = self.root.open(path) # Try opening /usr/bin/beep f = archive.read("/usr/bin/beep") @@ -118,7 +118,7 @@ class ArchiveTest(tests.TestCase): path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - archive = self.pakfire.open(path) + archive = self.root.open(path) with self.tempdir() as t: # Perform extraction @@ -141,7 +141,7 @@ class ArchiveTest(tests.TestCase): path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - archive = self.pakfire.open(path) + archive = self.root.open(path) # Fetch the package metadata package = archive.get_package() @@ -152,13 +152,13 @@ class ArchiveTest(tests.TestCase): def test_open_stub(self): # Launch Pakfire in stub mode - p = self.setup_pakfire(stub=True) + p = self.setup_root(stub=True) # Make path path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - archive = self.pakfire.open(path) + archive = self.root.open(path) # Fetch the filelist self.assertIsInstance(archive.filelist, list) diff --git a/tests/python/ctx.py b/tests/python/ctx.py index 3c9fc923..7ea6a0ef 100755 --- a/tests/python/ctx.py +++ b/tests/python/ctx.py @@ -59,7 +59,7 @@ class CtxTests(tests.TestCase): logger = logging.getLogger("pakfire") with self.assertLogs(logger, logging.DEBUG): - self.setup_pakfire() + self.setup_root() def test_log_custom(self): """ @@ -82,7 +82,7 @@ class CtxTests(tests.TestCase): ctx.set_logger(logger) # Create a new Pakfire instance to create some log messages - self.setup_pakfire(ctx=ctx) + self.setup_root(ctx=ctx) # Check if we have received anything self.assertTrue(logger.buffer) diff --git a/tests/python/dist.py b/tests/python/dist.py index 6a4f3ffd..7f3a2bbb 100755 --- a/tests/python/dist.py +++ b/tests/python/dist.py @@ -29,7 +29,7 @@ class DistTests(tests.TestCase): This tests the dist command """ def setUp(self): - self.pakfire = self.setup_pakfire() + self.root = self.setup_root() def test_dist(self): """ @@ -42,7 +42,7 @@ class DistTests(tests.TestCase): makefile = os.path.join(TEST_DATA_DIR, "packages/dummy/dummy.nm") # Run dist() - archive = self.pakfire.dist(makefile) + archive = self.root.dist(makefile) self.assertIsInstance(archive, pakfire.Archive) diff --git a/tests/python/execute.py b/tests/python/execute.py index 30ddcebd..14e12685 100755 --- a/tests/python/execute.py +++ b/tests/python/execute.py @@ -29,17 +29,17 @@ class ExecuteTests(tests.TestCase): This tests the execute command """ def setUp(self): - self.pakfire = self.setup_pakfire() + self.root = self.setup_root() # XXX Temporarily disabled, because the jail messes up the console def test_execute(self): - r = self.pakfire.execute(["/command", "exit-with-code", "0"]) + r = self.root.execute(["/command", "exit-with-code", "0"]) self.assertIsNone(r) def test_return_value(self): with self.assertRaises(pakfire.CommandExecutionError) as e: - self.pakfire.execute(["/command", "exit-with-code", "123"]) + self.root.execute(["/command", "exit-with-code", "123"]) # Extract return code code, output = e.exception.args @@ -48,7 +48,7 @@ class ExecuteTests(tests.TestCase): self.assertIsInstance(output, bytes) def test_environ(self): - r = self.pakfire.execute(["/command", "echo-environ", "VAR1"], + r = self.root.execute(["/command", "echo-environ", "VAR1"], environ={"VAR1" : "VAL1"}) self.assertIsNone(r) @@ -56,48 +56,48 @@ class ExecuteTests(tests.TestCase): def test_invalid_inputs(self): # Arguments with self.assertRaises(TypeError): - self.pakfire.execute("/command") + self.root.execute("/command") with self.assertRaises(TypeError): - self.pakfire.execute(["/command", 1]) + self.root.execute(["/command", 1]) with self.assertRaises(TypeError): - self.pakfire.execute(("/command", "--help")) + self.root.execute(("/command", "--help")) # Environment with self.assertRaises(TypeError): - self.pakfire.execute(["/command", "--help"], environ={"VAR1" : 1}) + self.root.execute(["/command", "--help"], environ={"VAR1" : 1}) with self.assertRaises(TypeError): - self.pakfire.execute(["/command", "--help"], environ={1 : "VAL1"}) + self.root.execute(["/command", "--help"], environ={1 : "VAL1"}) with self.assertRaises(TypeError): - self.pakfire.execute(["/command", "--help"], environ="VAR1=VAL1") + self.root.execute(["/command", "--help"], environ="VAR1=VAL1") def test_execute_non_existant_command(self): """ Executing non-existant commands should raise an error """ with self.assertRaises(pakfire.CommandExecutionError): - self.pakfire.execute(["/command-does-not-exist"]) + self.root.execute(["/command-does-not-exist"]) def test_execute_output(self): self.assertEqual( - self.pakfire.execute(["/command", "echo", "123"], return_output=True), + self.root.execute(["/command", "echo", "123"], return_output=True), b"123\n", ) # Multiple newlines in one read self.assertEqual( - self.pakfire.execute(["/command", "echo", "1\n2\n3"], return_output=True), + self.root.execute(["/command", "echo", "1\n2\n3"], return_output=True), b"1\n2\n3\n", ) # Run a command with a lot of output which exceeds the buffer size - self.pakfire.execute(["/command", "lines", "1", "65536"]) + self.root.execute(["/command", "lines", "1", "65536"]) # Run a command that generates lots of lines - output = self.pakfire.execute(["/command", "lines", "100", "40"], return_output=True) + output = self.root.execute(["/command", "lines", "100", "40"], return_output=True) self.assertEqual(output.count(b"\n"), 100) def test_execute_input(self): @@ -106,7 +106,7 @@ class ExecuteTests(tests.TestCase): output = input # Pipe the data through the command - output = self.pakfire.execute(["/command", "pipe"], + output = self.root.execute(["/command", "pipe"], input=input, return_output=True) # Input and output must match @@ -120,7 +120,7 @@ class ExecuteTests(tests.TestCase): # Ensure that we won't run forever in case the command cannot be found with self.assertRaises(pakfire.CommandExecutionError): - self.pakfire.execute(["/does-not-exist"], input=b"1234") + self.root.execute(["/does-not-exist"], input=b"1234") def test_execute_bind(self): """ @@ -130,20 +130,20 @@ class ExecuteTests(tests.TestCase): mountpoint = self.path() # Check if this is actually a mountpoint - self.pakfire.execute(["/command", "check-mountpoint", mountpoint], bind=[mountpoint]) + self.root.execute(["/command", "check-mountpoint", mountpoint], bind=[mountpoint]) # Try some invalid inputs with self.assertRaises(TypeError): - self.pakfire.execute(["/command", "exit-with-code", "0"], bind="/something") + self.root.execute(["/command", "exit-with-code", "0"], bind="/something") with self.assertRaises(TypeError): - self.pakfire.execute(["/command", "exit-with-code", "0"], bind=[123]) + self.root.execute(["/command", "exit-with-code", "0"], bind=[123]) def test_nice(self): """ Check if the jail is able to set the nice level """ - output = self.pakfire.execute(["/command", "print-nice"], + output = self.root.execute(["/command", "print-nice"], nice=5, return_output=True) # Check that we have received 5 @@ -154,14 +154,14 @@ class ExecuteTests(tests.TestCase): Tries using an invalid nice value """ with self.assertRaises(OSError): - self.pakfire.execute(["/command", "print-nice"], nice=100) + self.root.execute(["/command", "print-nice"], nice=100) def test_check_open_file_descriptors(self): """ Since we are spawning child processes, it might happen that we leak file descriptors to the child process. """ - self.pakfire.execute(["/command", "check-open-file-descriptors"]) + self.root.execute(["/command", "check-open-file-descriptors"]) # Signals @@ -169,19 +169,19 @@ class ExecuteTests(tests.TestCase): """ Sends a stupid signal which doesn't do anything """ - self.pakfire.execute(["/command", "send-signal", "0"]) + self.root.execute(["/command", "send-signal", "0"]) def test_send_signal_KILL(self): """ Test the process killing itself """ - self.pakfire.execute(["/command", "send-signal", "9"]) + self.root.execute(["/command", "send-signal", "9"]) def test_send_signal_TERM(self): """ Test the process terminating itself """ - self.pakfire.execute(["/command", "send-signal", "15"]) + self.root.execute(["/command", "send-signal", "15"]) if __name__ == "__main__": diff --git a/tests/python/keys.py b/tests/python/keys.py index 9663776e..1be9a6b6 100755 --- a/tests/python/keys.py +++ b/tests/python/keys.py @@ -28,13 +28,13 @@ class KeysTests(tests.TestCase): This tests the keys """ def setUp(self): - self.pakfire = self.setup_pakfire() + self.root = self.setup_root() def test_generate(self): """ Generate a new key """ - key = self.pakfire.generate_key( + key = self.root.generate_key( algorithm=pakfire.PAKFIRE_KEY_ALGO_ED25519, comment="Key 1") # Check if we got the correct type @@ -50,7 +50,7 @@ class KeysTests(tests.TestCase): with self.open(path) as f: payload = f.read() - return self.pakfire.import_key(payload) + return self.root.import_key(payload) def test_import_public_key(self): # Import a public key @@ -70,7 +70,7 @@ class KeysTests(tests.TestCase): """ Generate a new key """ - key = self.pakfire.generate_key( + key = self.root.generate_key( algorithm=pakfire.PAKFIRE_KEY_ALGO_ED25519, comment="Key 1") data = b"Pakfire" diff --git a/tests/python/main.py b/tests/python/main.py index b9409f11..4521044a 100755 --- a/tests/python/main.py +++ b/tests/python/main.py @@ -28,12 +28,12 @@ class PakfireTest(tests.TestCase): This tests the main Pakfire class """ def test_repr(self): - p = self.setup_pakfire() + p = self.setup_root() self.assertIn("Pakfire", repr(p)) def test_properties(self): - p = self.setup_pakfire() + p = self.setup_root() # Fetch the path and check if it is absolute self.assertTrue(p.path.startswith("/")) @@ -41,7 +41,7 @@ class PakfireTest(tests.TestCase): self.assertIn(p.arch, pakfire.supported_arches()) def test_repo(self): - p = self.setup_pakfire() + p = self.setup_root() # Fetch a repository repo = p.get_repo("@system") @@ -59,7 +59,7 @@ class PakfireTest(tests.TestCase): self.assertIsInstance(repo, pakfire.Repo) def test_whatprovides_whatrequires(self): - p = self.setup_pakfire() + p = self.setup_root() self.assertIsInstance(p.whatprovides("bash"), list) self.assertIsInstance(p.whatrequires("bash"), list) diff --git a/tests/python/package.py b/tests/python/package.py index 5be2f9df..cf57b9eb 100755 --- a/tests/python/package.py +++ b/tests/python/package.py @@ -7,13 +7,13 @@ class PackageTest(tests.TestCase): This tests the Package class """ def setUp(self): - self.pakfire = self.setup_pakfire() + self.root = self.setup_root() def test_open(self): path = self.path("beep-1.3-2.ip3.x86_64.pfm") # Open the archive - a = self.pakfire.open(path) + a = self.root.open(path) # Fetch the package p = a.get_package() diff --git a/tests/python/tests.py b/tests/python/tests.py index 5482cce9..e1500cc1 100644 --- a/tests/python/tests.py +++ b/tests/python/tests.py @@ -48,9 +48,9 @@ class TestCase(unittest.TestCase): # Return a new context return pakfire.Ctx(path=path, **kwargs) - def setup_pakfire(self, ctx=None, path=None, config=None, stub=False, **kwargs): + def setup_root(self, ctx=None, path=None, config=None, stub=False, **kwargs): """ - Sets up a new Pakfire environment + Sets up a new root """ # Create a context if none given if ctx is None: @@ -69,7 +69,7 @@ class TestCase(unittest.TestCase): with open(config, "r") as f: config = f.read() - return pakfire.Pakfire(ctx=ctx, path=path, config=config, stub=stub, **kwargs) + return pakfire.Root(ctx=ctx, path=path, config=config, stub=stub, **kwargs) def path(self, *args, **kwargs): """ diff --git a/tests/python/transaction.py b/tests/python/transaction.py index 2a1ce27d..5d4596da 100755 --- a/tests/python/transaction.py +++ b/tests/python/transaction.py @@ -8,11 +8,11 @@ class TransactionTest(tests.TestCase): This tests the Transaction class """ def setUp(self): - self.pakfire = self.setup_pakfire() + self.root = self.setup_root() def test_create(self): # Create a new transaction - t = pakfire.Transaction(self.pakfire) + t = pakfire.Transaction(self.root) # Ensure we get a transaction self.assertIsInstance(t, pakfire.Transaction) @@ -21,7 +21,7 @@ class TransactionTest(tests.TestCase): """ Performs some very simple operations which should all fail """ - t = pakfire.Transaction(self.pakfire) + t = pakfire.Transaction(self.root) # Install a few packages t.install("a", essential=True)