]> git.ipfire.org Git - pakfire.git/commitdiff
python: Remove exporting the parser to Python
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jul 2021 11:51:06 +0000 (11:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jul 2021 11:53:51 +0000 (11:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/_pakfire/_pakfiremodule.c
src/_pakfire/pakfire.c
src/_pakfire/parser.c [deleted file]
src/_pakfire/parser.h [deleted file]
tests/python/parser.py [deleted file]

index 3767ae720eaa051fcde673ab7f8e6daec1e86061..1722d23c8ad8dd86abab4e460b9ded577be29450 100644 (file)
@@ -159,8 +159,6 @@ _pakfire_la_SOURCES = \
        src/_pakfire/package.h \
        src/_pakfire/pakfire.c \
        src/_pakfire/pakfire.h \
-       src/_pakfire/parser.c \
-       src/_pakfire/parser.h \
        src/_pakfire/problem.c \
        src/_pakfire/problem.h \
        src/_pakfire/progressbar.c \
@@ -629,7 +627,6 @@ TESTS_ENVIRONMENT = \
 
 dist_check_SCRIPTS = \
        tests/python/execute.py \
-       tests/python/parser.py \
        tests/python/progressbar.py \
        tests/python/test.py
 
index 34359a5287aa78696cddda317d27bb8a81ca219f..2e31f8f3bbf4ced13ccf7707f4908c06e05e3575 100644 (file)
@@ -28,7 +28,6 @@
 #include "key.h"
 #include "package.h"
 #include "pakfire.h"
-#include "parser.h"
 #include "problem.h"
 #include "progressbar.h"
 #include "repo.h"
@@ -118,13 +117,6 @@ PyMODINIT_FUNC PyInit__pakfire(void) {
        Py_INCREF(&PackageType);
        PyModule_AddObject(module, "Package", (PyObject *)&PackageType);
 
-       // Parser
-       if (PyType_Ready(&ParserType) < 0)
-               return NULL;
-
-       Py_INCREF(&ParserType);
-       PyModule_AddObject(module, "Parser", (PyObject *)&ParserType);
-
        // Problem
        if (PyType_Ready(&ProblemType) < 0)
                return NULL;
index 666a6df1599cb3664ee03ee1dee5f9743e9cc5eb..43a358cf2924feb3653fee3170eca98bdf1b20b3 100644 (file)
@@ -37,7 +37,6 @@
 #include "errors.h"
 #include "key.h"
 #include "pakfire.h"
-#include "parser.h"
 #include "repo.h"
 #include "util.h"
 
diff --git a/src/_pakfire/parser.c b/src/_pakfire/parser.c
deleted file mode 100644 (file)
index 234f424..0000000
+++ /dev/null
@@ -1,231 +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 <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-#############################################################################*/
-
-#include <Python.h>
-
-#include <pakfire/parser.h>
-
-#include "pakfire.h"
-#include "parser.h"
-
-static ParserObject* Parser_new_core(PyTypeObject* type, struct pakfire_parser* parser) {
-       ParserObject* self = (ParserObject *)type->tp_alloc(type, 0);
-       if (self) {
-               self->parser = pakfire_parser_ref(parser);
-       }
-
-       return self;
-}
-
-PyObject* new_parser(struct pakfire_parser* parser) {
-       ParserObject* p = Parser_new_core(&ParserType, parser);
-
-       return (PyObject*)p;
-}
-
-static PyObject* Parser_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
-       ParserObject* self = Parser_new_core(type, NULL);
-
-       return (PyObject *)self;
-}
-
-static void Parser_dealloc(ParserObject* self) {
-       pakfire_parser_unref(self->parser);
-
-       Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-static int Parser_init(ParserObject* self, PyObject* args, PyObject* kwds) {
-       PakfireObject* pakfire = NULL;
-       const char* namespace = NULL;
-       int flags = 0;
-
-       if (!PyArg_ParseTuple(args, "O!|zi", &PakfireType, &pakfire, &namespace, &flags))
-               return -1;
-
-       // Allocate a new parser
-       self->parser = pakfire_parser_create(pakfire->pakfire, NULL, namespace, flags);
-       if (!self->parser) {
-               // What went wrong here?
-               return -1;
-       }
-
-       return 0;
-}
-
-static PyObject* Parser_repr(ParserObject* self) {
-       const char* namespace = pakfire_parser_get_namespace(self->parser);
-
-       return PyUnicode_FromFormat("<_pakfire.Parser %s>", namespace);
-}
-
-static PyObject* Parser_str(ParserObject* self) {
-       char* s = pakfire_parser_dump(self->parser);
-       if (!s) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       PyObject* ret = PyUnicode_FromString(s);
-       free(s);
-
-       return ret;
-}
-
-static PyObject* Parser_parse(ParserObject* self, PyObject* args) {
-       const char* data = NULL;
-
-       if (!PyArg_ParseTuple(args, "s", &data))
-               return NULL;
-
-       int r = pakfire_parser_parse(self->parser, data, strlen(data), NULL);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       Py_RETURN_NONE;
-}
-
-static PyObject* Parser_read(ParserObject* self, PyObject* args) {
-       const char* filename = NULL;
-
-       if (!PyArg_ParseTuple(args, "s", &filename))
-               return NULL;
-
-       FILE* f = fopen(filename, "r");
-       if (!f) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       int r = pakfire_parser_read(self->parser, f, NULL);
-       fclose(f);
-
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       Py_RETURN_NONE;
-}
-
-static PyObject* Parser_get(ParserObject* self, PyObject* args) {
-       const char* namespace = NULL;
-       const char* key = NULL;
-
-       if (!PyArg_ParseTuple(args, "zs", &namespace, &key))
-               return NULL;
-
-       char* value = pakfire_parser_get(self->parser, namespace, key);
-       if (!value) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       PyObject* ret = PyUnicode_FromString(value);
-       free(value);
-
-       return ret;
-}
-
-static PyObject* Parser_set(ParserObject* self, PyObject* args) {
-       const char* namespace = NULL;
-       const char* key = NULL;
-       const char* value = NULL;
-
-       if (!PyArg_ParseTuple(args, "zsz", &namespace, &key, &value))
-               return NULL;
-
-       int r = pakfire_parser_set(self->parser, namespace, key, value, 0);
-       if (r) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       Py_RETURN_NONE;
-}
-
-static PyObject* Parser_expand(ParserObject* self, PyObject* args) {
-       const char* namespace = NULL;
-       const char* s = NULL;
-
-       if (!PyArg_ParseTuple(args, "zs", &namespace, &s))
-               return NULL;
-
-       char* value = pakfire_parser_expand(self->parser, namespace, s);
-       if (!value) {
-               PyErr_SetFromErrno(PyExc_OSError);
-               return NULL;
-       }
-
-       PyObject* ret = PyUnicode_FromString(value);
-       free(value);
-
-       return ret;
-}
-
-static struct PyMethodDef Parser_methods[] = {
-       {
-               "parse",
-               (PyCFunction)Parser_parse,
-               METH_VARARGS,
-               NULL,
-       },
-       {
-               "expand",
-               (PyCFunction)Parser_expand,
-               METH_VARARGS,
-               NULL,
-       },
-       {
-               "get",
-               (PyCFunction)Parser_get,
-               METH_VARARGS,
-               NULL,
-       },
-       {
-               "read",
-               (PyCFunction)Parser_read,
-               METH_VARARGS,
-               NULL,
-       },
-       {
-               "set",
-               (PyCFunction)Parser_set,
-               METH_VARARGS,
-               NULL,
-       },
-       { NULL },
-};
-
-PyTypeObject ParserType = {
-       PyVarObject_HEAD_INIT(NULL, 0)
-       tp_name:            "_pakfire.Parser",
-       tp_basicsize:       sizeof(ParserObject),
-       tp_flags:           Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
-       tp_new:             Parser_new,
-       tp_dealloc:         (destructor)Parser_dealloc,
-       tp_init:            (initproc)Parser_init,
-       tp_doc:             "Parser Object",
-       tp_methods:         Parser_methods,
-       tp_repr:            (reprfunc)Parser_repr,
-       tp_str:             (reprfunc)Parser_str,
-};
diff --git a/src/_pakfire/parser.h b/src/_pakfire/parser.h
deleted file mode 100644 (file)
index e664bc4..0000000
+++ /dev/null
@@ -1,37 +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 <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-#############################################################################*/
-
-#ifndef PYTHON_PAKFIRE_PARSER_H
-#define PYTHON_PAKFIRE_PARSER_H
-
-#include <Python.h>
-
-#include <pakfire/parser.h>
-
-typedef struct {
-       PyObject_HEAD
-       struct pakfire_parser* parser;
-} ParserObject;
-
-extern PyTypeObject ParserType;
-
-PyObject* new_parser(struct pakfire_parser* parser);
-
-#endif /* PYTHON_PAKFIRE_PARSER_H */
diff --git a/tests/python/parser.py b/tests/python/parser.py
deleted file mode 100755 (executable)
index d6bb452..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/python3
-
-import os
-import pakfire
-import unittest
-
-from pakfire._pakfire import Parser
-
-class Test(unittest.TestCase):
-       """
-               This tests the parser command
-       """
-       def setUp(self):
-               self.pakfire = pakfire.Pakfire("/")
-
-       def test_simple_parse(self):
-               p = Parser(self.pakfire)
-
-               # Parse something simple
-               p.parse("""
-                       a = 1
-                       b = 2
-               """)
-
-               # Read back a
-               a = p.get("a")
-               self.assertEqual(a, "1")
-
-               # Read back b
-               b = p.get("b")
-               self.assertEqual(b, "2")
-
-       def test_dump(self):
-               p = Parser(self.pakfire)
-
-               # Parse something simple
-               p.parse("""
-                       a = 1
-                       b = 2
-               """)
-
-               dump = "%s" % p
-
-       def test_read(self):
-               p = Parser(self.pakfire)
-
-               fn = os.path.join(os.environ.get("TEST_DATA_DIR"), "kernel.nm")
-
-               # Read something
-               p.read(fn)
-
-               # Check if we could parse something useful
-               self.assertEqual(p.get("name"), "kernel")
-
-if __name__ == "__main__":
-       unittest.main()