From: Michael Tremer Date: Sat, 12 Oct 2024 17:23:52 +0000 (+0000) Subject: python: Drop the native Python code and move the C module X-Git-Tag: 0.9.30~1062 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=307ddaead3259d59132586d999dc63d05bd6453f;p=pakfire.git python: Drop the native Python code and move the C module Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index b43c3b0ca..1a660dfcb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -102,66 +102,53 @@ dist_doc_DATA = \ # ------------------------------------------------------------------------------ -pakfire_PYTHON = \ - src/pakfire/__init__.py \ - src/pakfire/__version__.py \ - src/pakfire/config.py \ - src/pakfire/constants.py \ - src/pakfire/errors.py \ - src/pakfire/i18n.py \ - src/pakfire/logger.py \ - src/pakfire/util.py - -pakfiredir = $(pythondir)/pakfire - -# ------------------------------------------------------------------------------ - pkgpyexec_LTLIBRARIES += \ - _pakfire.la - -_pakfire_la_SOURCES = \ - src/_pakfire/_pakfiremodule.c \ - src/_pakfire/archive.c \ - src/_pakfire/archive.h \ - src/_pakfire/archive_file.c \ - src/_pakfire/archive_file.h \ - src/_pakfire/ctx.c \ - src/_pakfire/ctx.h \ - src/_pakfire/errors.h \ - src/_pakfire/file.c \ - src/_pakfire/file.h \ - src/_pakfire/key.c \ - src/_pakfire/key.h \ - src/_pakfire/package.c \ - src/_pakfire/package.h \ - src/_pakfire/pakfire.c \ - src/_pakfire/pakfire.h \ - src/_pakfire/problem.c \ - src/_pakfire/problem.h \ - src/_pakfire/repo.c \ - src/_pakfire/repo.h \ - src/_pakfire/solution.c \ - src/_pakfire/solution.h \ - src/_pakfire/util.c \ - src/_pakfire/util.h - -_pakfire_la_CPPFLAGS = \ + pakfire.la + +pakfire_la_SOURCES = \ + src/python/pakfiremodule.c \ + src/python/archive.c \ + src/python/archive.h \ + src/python/archive_file.c \ + src/python/archive_file.h \ + src/python/ctx.c \ + src/python/ctx.h \ + src/python/errors.h \ + src/python/file.c \ + src/python/file.h \ + src/python/key.c \ + 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/solution.c \ + src/python/solution.h \ + src/python/util.c \ + src/python/util.h + +pakfire_la_CPPFLAGS = \ -include $(top_builddir)/config.h \ $(PAKFIRE_CPPFLAGS) -_pakfire_la_CFLAGS = \ +pakfire_la_CFLAGS = \ $(AM_CFLAGS) \ $(PYTHON_DEVEL_CFLAGS) \ - $(JSON_C_CFLAGS) \ - -Wno-cast-function-type + -Wno-cast-function-type \ + -Wno-redundant-decls \ + -Wno-strict-aliasing -_pakfire_la_LDFLAGS = \ +pakfire_la_LDFLAGS = \ $(AM_LDFLAGS) \ -shared \ -module \ -avoid-version -_pakfire_la_LIBADD = \ +pakfire_la_LIBADD = \ $(PYTHON_DEVEL_LIBS) \ $(PAKFIRE_LIBS) @@ -1129,7 +1116,7 @@ TESTS_ENVIRONMENT += \ # Test the Python modules we just built TESTS_ENVIRONMENT += \ - PYTHONPATH=$(top_srcdir)/src:$(top_srcdir)/.libs:$(PYTHONPATH) + PYTHONPATH=$(top_srcdir)/.libs:$(PYTHONPATH) dist_check_SCRIPTS = \ tests/python/archive.py \ diff --git a/configure.ac b/configure.ac index 192acb855..8ac5aa597 100644 --- a/configure.ac +++ b/configure.ac @@ -340,7 +340,6 @@ AC_DEFINE_UNQUOTED([PAKFIRE_TMP_DIR], ["/var/tmp"], AC_CONFIG_FILES([ Makefile po/Makefile.in - src/pakfire/__version__.py ]) AC_OUTPUT diff --git a/src/pakfire/__init__.py b/src/pakfire/__init__.py deleted file mode 100644 index 92264a729..000000000 --- a/src/pakfire/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -# Import version -from .__version__ import PAKFIRE_VERSION as __version__ - -# Import everything from the C module -try: - from ._pakfire import * -except ImportError: - from _pakfire import * diff --git a/src/pakfire/__version__.py.in b/src/pakfire/__version__.py.in deleted file mode 100644 index 90bf0ca68..000000000 --- a/src/pakfire/__version__.py.in +++ /dev/null @@ -1,2 +0,0 @@ -# this file is autogenerated by the buildsystem -PAKFIRE_VERSION = "@PACKAGE_VERSION@" diff --git a/src/pakfire/config.py b/src/pakfire/config.py deleted file mode 100644 index 912e16642..000000000 --- a/src/pakfire/config.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -import configparser -import logging -import os - -log = logging.getLogger("pakfire.config") -log.propagate = 1 - -from .constants import * - -class Config(object): - def __init__(self, *files): - self._config = configparser.ConfigParser( - interpolation=configparser.ExtendedInterpolation() - ) - - # Read any passed configuration files - for f in files: - self.read(f) - - def read(self, path): - """ - Reads configuration from the given file - """ - if not path.startswith("/"): - path = os.path.join(CONFIG_DIR, path) - - # Silently return if nothing is found - if not os.path.exists(path): - return - - log.debug("Reading configuration from %s" % path) - - with open(path) as f: - self._config.read_file(f) - - def parse(self, s): - """ - Takes configuration as a string and parses it - """ - self._config.read_string(s) - - def get(self, section, option=None, default=None): - if option is None: - try: - section = self._config.items(section) - except configparser.NoSectionError: - return default - - return dict(section) - - return self._config.get(section, option, fallback=default) - - def get_bool(self, section, option, default=None): - return self._config.getboolean(section, option, fallback=default) diff --git a/src/pakfire/constants.py b/src/pakfire/constants.py deleted file mode 100644 index b3b3dc347..000000000 --- a/src/pakfire/constants.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -import os.path - -from .errors import * - -from .__version__ import PAKFIRE_VERSION - -# The default hub to connect to. -PAKFIRE_HUB = "https://pakfire.ipfire.org/" - -SYSCONFDIR = "/etc" - -CONFIG_DIR = os.path.join(SYSCONFDIR, "pakfire") -CONFIG_DISTRO_DIR = os.path.join(CONFIG_DIR, "distros") - -PACKAGE_EXTENSION = "pfm" -MAKEFILE_EXTENSION = "nm" diff --git a/src/pakfire/errors.py b/src/pakfire/errors.py deleted file mode 100644 index 3ec0ba24d..000000000 --- a/src/pakfire/errors.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -from .i18n import _ - -from ._pakfire import ( - CommandExecutionError, - DependencyError, -) - -class Error(Exception): - exit_code = 1 - - message = _("An unhandled error occured.") - - -class BuildError(Error): - pass - - -class DownloadError(Error): - message = _("An error occured when pakfire tried to download files.") - - -class TransportError(Error): - pass - - -class TransportMaxTriesExceededError(TransportError): - pass diff --git a/src/pakfire/i18n.py b/src/pakfire/i18n.py deleted file mode 100644 index 75e7811e9..000000000 --- a/src/pakfire/i18n.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -""" - The translation process of all strings is done in here. -""" - -import gettext - -""" - A function that returnes the same string. -""" -N_ = lambda x: x - -def _(singular, plural=None, n=None): - """ - A function that returnes the translation of a string if available. - - The language is taken from the system environment. - """ - if not plural is None: - assert n is not None - return gettext.dngettext("pakfire", singular, plural, n) - - return gettext.dgettext("pakfire", singular) diff --git a/src/pakfire/logger.py b/src/pakfire/logger.py deleted file mode 100644 index c20b077b1..000000000 --- a/src/pakfire/logger.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -import logging -import sys -import systemd.journal -import time - -def setup(name, syslog_identifier="pakfire", enable_console=True, debug=False): - level = logging.INFO - - # Enable debug logging - if debug: - level = logging.DEBUG - - log = logging.getLogger(name) - log.setLevel(level) - - # Do not propagate anything - log.propagate = False - - # Clear any previous handlers - log.handlers.clear() - - # Enable console output - if enable_console: - console = ConsoleHandler() - log.addHandler(console) - - # Do not send any debug output to the console - console.setLevel(logging.INFO) - - # Enable logging to journald - journal = systemd.journal.JournalHandler( - SYSLOG_IDENTIFIER=syslog_identifier, - ) - log.addHandler(journal) - - return log - -class BuildFormatter(logging.Formatter): - def __init__(self): - self._fmt = "[%(asctime)s] %(message)s" - self.datefmt = None - - self.starttime = time.time() - - def converter(self, recordtime): - """ - This returns a timestamp relatively to the time when we started - the build. - """ - recordtime -= self.starttime - - return time.gmtime(recordtime) - - def formatTime(self, record, datefmt=None): - ct = self.converter(record.created) - t = time.strftime("%H:%M:%S", ct) - s = "%s,%03d" % (t, record.msecs) - return s - - -class ConsoleHandler(logging.Handler): - """ - This simply writes everything to the console it receives. - """ - def emit(self, record): - try: - msg = self.format(record) - - # Append newline if necessary - if not msg.endswith("\n"): - msg = "%s\n" % msg - - # Select output file - if record.levelno == logging.DEBUG or record.levelno >= logging.ERROR: - fd = sys.stderr - else: - fd = sys.stdout - - # Write the output - fd.write(msg) - - # Immediately flush - self.flush() - except Exception: - self.handleError(record) - - def flush(self): - sys.stdout.flush() - sys.stderr.flush() diff --git a/src/pakfire/util.py b/src/pakfire/util.py deleted file mode 100644 index 7a2c9b65a..000000000 --- a/src/pakfire/util.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 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 . # -# # -############################################################################### - -import platform - -def get_distro_name(): - """ - Returns the distro name of the host - """ - try: - release = platform.freedesktop_os_release() - except AttributeError: - release = _read_os_release() - - return release.get("PRETTY_NAME") or release.get("NAME") - -def _read_os_release(): - """ - This is a simple implementation to read /etc/os-release and /var/lib/os-release - """ - for file in ("/etc/os-release", "/var/lib/os-release"): - try: - with open(file, "r") as f: - release = {} - - for line in f: - key, delim, value = line.partition("=") - - release[key] = value - - return release - except FileNotFoundError: - pass - - raise OSError("Could not find os-release") diff --git a/src/_pakfire/archive.c b/src/python/archive.c similarity index 100% rename from src/_pakfire/archive.c rename to src/python/archive.c diff --git a/src/_pakfire/archive.h b/src/python/archive.h similarity index 100% rename from src/_pakfire/archive.h rename to src/python/archive.h diff --git a/src/_pakfire/archive_file.c b/src/python/archive_file.c similarity index 100% rename from src/_pakfire/archive_file.c rename to src/python/archive_file.c diff --git a/src/_pakfire/archive_file.h b/src/python/archive_file.h similarity index 100% rename from src/_pakfire/archive_file.h rename to src/python/archive_file.h diff --git a/src/_pakfire/ctx.c b/src/python/ctx.c similarity index 100% rename from src/_pakfire/ctx.c rename to src/python/ctx.c diff --git a/src/_pakfire/ctx.h b/src/python/ctx.h similarity index 100% rename from src/_pakfire/ctx.h rename to src/python/ctx.h diff --git a/src/_pakfire/errors.h b/src/python/errors.h similarity index 100% rename from src/_pakfire/errors.h rename to src/python/errors.h diff --git a/src/_pakfire/file.c b/src/python/file.c similarity index 100% rename from src/_pakfire/file.c rename to src/python/file.c diff --git a/src/_pakfire/file.h b/src/python/file.h similarity index 100% rename from src/_pakfire/file.h rename to src/python/file.h diff --git a/src/_pakfire/key.c b/src/python/key.c similarity index 100% rename from src/_pakfire/key.c rename to src/python/key.c diff --git a/src/_pakfire/key.h b/src/python/key.h similarity index 100% rename from src/_pakfire/key.h rename to src/python/key.h diff --git a/src/_pakfire/package.c b/src/python/package.c similarity index 100% rename from src/_pakfire/package.c rename to src/python/package.c diff --git a/src/_pakfire/package.h b/src/python/package.h similarity index 100% rename from src/_pakfire/package.h rename to src/python/package.h diff --git a/src/_pakfire/pakfire.c b/src/python/pakfire.c similarity index 100% rename from src/_pakfire/pakfire.c rename to src/python/pakfire.c diff --git a/src/_pakfire/pakfire.h b/src/python/pakfire.h similarity index 100% rename from src/_pakfire/pakfire.h rename to src/python/pakfire.h diff --git a/src/_pakfire/_pakfiremodule.c b/src/python/pakfiremodule.c similarity index 89% rename from src/_pakfire/_pakfiremodule.c rename to src/python/pakfiremodule.c index 69421588b..2213fff8d 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/python/pakfiremodule.c @@ -39,7 +39,7 @@ #include "solution.h" #include "util.h" -PyMODINIT_FUNC PyInit__pakfire(void); +PyMODINIT_FUNC PyInit_pakfire(void); PyObject* PyExc_BadSignatureError; PyObject* PyExc_CommandExecutionError; @@ -48,7 +48,7 @@ PyObject* PyExc_DependencyError; PyObject* PyExc_CheckError; PyObject* PyExc_CheckFileVerificationError; -static PyObject* _pakfire_supported_arches(void) { +static PyObject* Pakfire_supported_arches(void) { int r; // Fetch all architectures @@ -86,7 +86,7 @@ ERROR: return NULL; } -static PyObject* _pakfire_version_compare(PyObject* self, PyObject* args) { +static PyObject* Pakfire_version_compare(PyObject* self, PyObject* args) { const char* evr1 = NULL; const char* evr2 = NULL; int r; @@ -102,10 +102,10 @@ static PyObject* _pakfire_version_compare(PyObject* self, PyObject* args) { } static PyMethodDef pakfireModuleMethods[] = { - {"supported_arches", (PyCFunction)_pakfire_supported_arches, METH_NOARGS, NULL }, + {"supported_arches", (PyCFunction)Pakfire_supported_arches, METH_NOARGS, NULL }, { "version_compare", - (PyCFunction)_pakfire_version_compare, + (PyCFunction)Pakfire_version_compare, METH_VARARGS, NULL, }, @@ -114,14 +114,12 @@ static PyMethodDef pakfireModuleMethods[] = { static struct PyModuleDef moduledef = { .m_base = PyModuleDef_HEAD_INIT, - .m_name = "_pakfire", + .m_name = "pakfire", .m_size = -1, .m_methods = pakfireModuleMethods, }; -PyMODINIT_FUNC PyInit__pakfire(void) { - int r; - +PyMODINIT_FUNC PyInit_pakfire(void) { /* Initialize locale */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_TARNAME, "/usr/share/locale"); @@ -132,22 +130,22 @@ PyMODINIT_FUNC PyInit__pakfire(void) { if (!module) return NULL; - PyExc_BadSignatureError = PyErr_NewException("_pakfire.BadSignatureError", NULL, NULL); + PyExc_BadSignatureError = PyErr_NewException("pakfire.BadSignatureError", NULL, NULL); Py_INCREF(PyExc_BadSignatureError); PyModule_AddObject(module, "BadSignatureError", PyExc_BadSignatureError); - PyExc_CommandExecutionError = PyErr_NewException("_pakfire.CommandExecutionError", NULL, NULL); + PyExc_CommandExecutionError = PyErr_NewException("pakfire.CommandExecutionError", NULL, NULL); Py_INCREF(PyExc_CommandExecutionError); PyModule_AddObject(module, "CommandExecutionError", PyExc_CommandExecutionError); - PyExc_DependencyError = PyErr_NewException("_pakfire.DependencyError", NULL, NULL); + PyExc_DependencyError = PyErr_NewException("pakfire.DependencyError", NULL, NULL); Py_INCREF(PyExc_DependencyError); PyModule_AddObject(module, "DependencyError", PyExc_DependencyError); // Check Exceptions // CheckError - PyExc_CheckError = PyErr_NewException("_pakfire.CheckError", NULL, NULL); + PyExc_CheckError = PyErr_NewException("pakfire.CheckError", NULL, NULL); Py_INCREF(PyExc_CheckError); if (PyModule_AddObject(module, "CheckError", PyExc_CheckError) < 0) { Py_XDECREF(PyExc_CheckError); @@ -157,7 +155,7 @@ PyMODINIT_FUNC PyInit__pakfire(void) { // CheckFileVerificationError based on CheckError PyExc_CheckFileVerificationError = PyErr_NewExceptionWithDoc( - "_pakfire.CheckFileVerificationError", + "pakfire.CheckFileVerificationError", "The file verification process failed", PyExc_CheckError, NULL diff --git a/src/_pakfire/problem.c b/src/python/problem.c similarity index 100% rename from src/_pakfire/problem.c rename to src/python/problem.c diff --git a/src/_pakfire/problem.h b/src/python/problem.h similarity index 100% rename from src/_pakfire/problem.h rename to src/python/problem.h diff --git a/src/_pakfire/repo.c b/src/python/repo.c similarity index 100% rename from src/_pakfire/repo.c rename to src/python/repo.c diff --git a/src/_pakfire/repo.h b/src/python/repo.h similarity index 100% rename from src/_pakfire/repo.h rename to src/python/repo.h diff --git a/src/_pakfire/solution.c b/src/python/solution.c similarity index 100% rename from src/_pakfire/solution.c rename to src/python/solution.c diff --git a/src/_pakfire/solution.h b/src/python/solution.h similarity index 100% rename from src/_pakfire/solution.h rename to src/python/solution.h diff --git a/src/_pakfire/util.c b/src/python/util.c similarity index 100% rename from src/_pakfire/util.c rename to src/python/util.c diff --git a/src/_pakfire/util.h b/src/python/util.h similarity index 100% rename from src/_pakfire/util.h rename to src/python/util.h