diff --git a/CMakeLists.txt b/CMakeLists.txt index 5de7f517..38b8d1e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,6 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/jsondump") add_subdirectory("${PROJECT_SOURCE_DIR}/history") add_subdirectory("${PROJECT_SOURCE_DIR}/llconf") add_subdirectory("${PROJECT_SOURCE_DIR}/plugins") -add_subdirectory("${PROJECT_SOURCE_DIR}/python") add_subdirectory("${PROJECT_SOURCE_DIR}/etc") add_subdirectory("${PROJECT_SOURCE_DIR}/bin") add_subdirectory("${PROJECT_SOURCE_DIR}/solv") diff --git a/ci/docker-entrypoint.sh b/ci/docker-entrypoint.sh index 132a8e03..7af71f75 100755 --- a/ci/docker-entrypoint.sh +++ b/ci/docker-entrypoint.sh @@ -5,8 +5,12 @@ rm -rf build mkdir -p build cd build || exit 1 +JOBS=$(nproc) + mkdir -p /usr/lib/sysimage/tdnf -cmake -DHISTORY_DB_DIR=/usr/lib/sysimage/tdnf .. && make -j32 && make python -j32 && make check -j32 || exit +cmake -DHISTORY_DB_DIR=/usr/lib/sysimage/tdnf .. || exit 1 +make -j${JOBS} || exit 1 +make check -j${JOBS} || exit 1 if ! flake8 ../pytests ; then echo "flake8 tests failed" diff --git a/pytests/tests/test_tdnf_python.py b/pytests/tests/test_tdnf_python.py deleted file mode 100755 index 89b0b0eb..00000000 --- a/pytests/tests/test_tdnf_python.py +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved. -# -# Licensed under the GNU General Public License v2 (the "License"); -# you may not use this file except in compliance with the License. The terms -# of the License are located in the COPYING file of this distribution. -# - -import os -import sys -import pytest - - -@pytest.fixture(scope='module', autouse=True) -def setup_test(utils): - global mulpkgname - mulpkgname = utils.config['mulversion_pkgname'] - - global sglpkgname - sglpkgname = utils.config['sglversion_pkgname'] - - global config - config = os.path.join(utils.config['repo_path'], "tdnf.conf") - - if not utils.config.get('installed', False): - # find path to our tdnf python module - builddir = utils.config['build_dir'] - arch = os.uname().machine - pymajor = sys.version_info.major - pyminor = sys.version_info.minor - - # only support python3 - assert pymajor == 3 - - if pyminor < 11: - path = f"{builddir}/python/build/lib.linux-{arch}-{pymajor}.{pyminor}" - else: - path = f"{builddir}/python/build/lib.linux-{arch}-cpython-{pymajor}{pyminor}" - - assert os.path.isdir(path) - sys.path.append(path) - - global tdnf - import tdnf - - yield - teardown_test(utils) - - -def teardown_test(utils): - utils.run(['tdnf', 'erase', '-y', sglpkgname]) - utils.run(['tdnf', 'erase', '-y', mulpkgname]) - assert not utils.check_package(sglpkgname) - assert not utils.check_package(mulpkgname) - - -def tdnf_py_erase(pkgs, quiet=False, refresh=False, cfg=None): - conf = cfg if cfg else config - pkgs = [x for x in pkgs if x] - for p in pkgs: - try: - tdnf.erase(pkgs=[p], quiet=quiet, refresh=refresh, config=conf) - except Exception: - pass - - -def tdnf_py_install(pkgs, quiet=False, refresh=False, cfg=None): - pkgs = [x for x in pkgs if x] - conf = cfg if cfg else config - tdnf.install(pkgs=pkgs, quiet=quiet, refresh=refresh, config=conf) - - -def tdnf_py_repolist(filter=None, cfg=None): - conf = cfg if cfg else config - if filter: - return tdnf.repolist(filter=filter, config=conf) - - return tdnf.repolist(config=conf) - - -def tdnf_py_distro_sync(quiet=False, refresh=False, cfg=None): - conf = cfg if cfg else config - tdnf.distro_sync(quiet=quiet, refresh=refresh, config=conf) - - -def tdnf_py_downgrade(pkgs, quiet=False, refresh=False, cfg=None): - pkgs = [x for x in pkgs if x] - conf = cfg if cfg else config - tdnf.downgrade(pkgs=pkgs, quiet=quiet, refresh=refresh, config=conf) - - -def tdnf_py_update(pkgs=[], quiet=False, refresh=False, cfg=None): - pkgs = [x for x in pkgs if x] - conf = cfg if cfg else config - if pkgs: - tdnf.update(pkgs=pkgs, quiet=quiet, refresh=refresh, config=conf) - else: - tdnf.update(quiet=quiet, refresh=refresh, config=conf) - - -def test_tdnf_python_install_single(utils): - pkgs = [sglpkgname] - - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - tdnf_py_install(pkgs=pkgs) - assert utils.check_package(sglpkgname) - - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - tdnf_py_install(pkgs=pkgs, refresh=True) - assert utils.check_package(sglpkgname) - - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - tdnf_py_install(pkgs=pkgs, refresh=True, quiet=True) - assert utils.check_package(sglpkgname) - - -def test_tdnf_python_install_multiple(utils): - pkgs = [sglpkgname, mulpkgname] - - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - assert not utils.check_package(mulpkgname) - tdnf_py_install(pkgs=pkgs) - assert utils.check_package(sglpkgname) - assert utils.check_package(mulpkgname) - - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - assert not utils.check_package(mulpkgname) - tdnf_py_install(pkgs=pkgs, refresh=True) - assert utils.check_package(sglpkgname) - assert utils.check_package(mulpkgname) - - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - assert not utils.check_package(mulpkgname) - tdnf_py_install(pkgs=pkgs, refresh=True, quiet=True) - assert utils.check_package(sglpkgname) - assert utils.check_package(mulpkgname) - - -def test_tdnf_python_erase_single(utils): - pkgs = [sglpkgname] - - tdnf_py_install(pkgs=pkgs) - assert utils.check_package(sglpkgname) - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - - -def test_tdnf_python_erase_multiple(utils): - pkgs = [sglpkgname, mulpkgname] - - tdnf_py_install(pkgs=pkgs) - assert utils.check_package(sglpkgname) - assert utils.check_package(mulpkgname) - tdnf_py_erase(pkgs=pkgs) - assert not utils.check_package(sglpkgname) - assert not utils.check_package(mulpkgname) - - -def check_repodata(data, filter=0): - if filter != 2: - assert data.enabled == 1 - assert data.name.decode('utf-8') == 'basic' - assert data.id.decode('utf-8') == 'photon-test' - assert data.baseurl.decode('utf-8') == 'http://localhost:8080/photon-test' - else: - assert data.enabled == 0 - assert data.name.decode('utf-8') == '@cmdline' - assert data.id.decode('utf-8') == '@cmdline' - assert not hasattr(data, 'baseurl') - - -def test_tdnf_python_repolist(utils): - check_repodata(tdnf_py_repolist()[0]) - - for i in [0, 1, 2, -1, 10]: - check_repodata(tdnf_py_repolist(i)[0], i) - - -def test_tdnf_python_update_single(utils): - pkgs = [sglpkgname] - tdnf_py_install(pkgs=pkgs) - tdnf_py_update(pkgs=pkgs) - tdnf_py_update(pkgs=pkgs, quiet=True) - tdnf_py_update(pkgs=pkgs, quiet=True, refresh=True) - - -def test_tdnf_python_update_multiple(utils): - pkgs = [sglpkgname, mulpkgname + '-' + utils.config['mulversion_lower']] - - tdnf_py_erase(pkgs=[sglpkgname, mulpkgname]) - tdnf_py_install(pkgs=pkgs) - tdnf_py_update(pkgs=pkgs) - - tdnf_py_erase(pkgs=[sglpkgname, mulpkgname]) - tdnf_py_install(pkgs=pkgs) - tdnf_py_update(pkgs=pkgs, quiet=True) - - tdnf_py_erase(pkgs=[sglpkgname, mulpkgname]) - tdnf_py_install(pkgs=pkgs) - tdnf_py_update(pkgs=pkgs, quiet=True, refresh=True) - - -def test_tdnf_python_update_all(utils): - tdnf_py_update() - - -def test_tdnf_python_downgrade_single(utils): - pkgs = [mulpkgname] - tdnf_py_erase(pkgs=pkgs) - tdnf_py_install(pkgs=pkgs) - tdnf_py_downgrade(pkgs=pkgs, refresh=True) - tdnf_py_downgrade(pkgs=pkgs, quiet=True, refresh=True) - - -def test_tdnf_python_downgrade_multiple(utils): - pkgs = [sglpkgname, mulpkgname] - tdnf_py_erase(pkgs=pkgs) - tdnf_py_install(pkgs=pkgs) - tdnf_py_downgrade(pkgs=pkgs, refresh=True) - tdnf_py_downgrade(pkgs=pkgs, quiet=True, refresh=True) - - -def test_tdnf_python_distro_sync(utils): - tdnf_py_distro_sync(quiet=True) - tdnf_py_distro_sync(refresh=True, quiet=True) - - -def test_tdnf_python_repofilter(utils): - assert tdnf.REPOLISTFILTER_ALL == 0 - assert tdnf.REPOLISTFILTER_ENABLED == 1 - assert tdnf.REPOLISTFILTER_DISABLED == 2 diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt deleted file mode 100644 index e5878cc6..00000000 --- a/python/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -# -# Copyright (C) 2020 VMware, Inc. All Rights Reserved. -# -# Licensed under the GNU General Public License v2 (the "License"); -# you may not use this file except in compliance with the License. The terms -# of the License are located in the COPYING file of this distribution. -# - -find_package(PythonInterp 3.7 REQUIRED) -find_package(PythonLibs 3.7 REQUIRED) - -set(PYTDNF_PACKAGE_NAME "${PROJECT_NAME}") -set(PYTDNF_VERSION "${PROJECT_VERSION}") -set(PYTDNF_SRC_DIR "${PROJECT_SOURCE_DIR}/python") -set(PYTDNF_INC_DIR "${PROJECT_SOURCE_DIR}/include") -set(PYTDNF_LIB_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - -configure_file( - setup.py.in - setup.py -) - -add_custom_target(python - COMMAND cp -r "${CMAKE_CURRENT_SOURCE_DIR}/tdnf" . - COMMAND ${PYTHON_EXECUTABLE} setup.py build -) - -add_custom_target(package_pytdnf - COMMAND ${PYTHON_EXECUTABLE} setup.py bdist --formats=rpm -) diff --git a/python/README.md b/python/README.md deleted file mode 100644 index c19c6e38..00000000 --- a/python/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# tdnf python interface -tdnf python interfaces will work for python2 and python3. details as follows. - -### api -- [repolist](#repolist) -- [install](#install) -- [update](#update) -- [downgrade](#downgrade) -- [erase](#erase) -- [distro-sync](#distro-sync) - -## repolist -returns a python list of repodata types. - -### parameter (optional): filter -``` - REPOLISTFILTER_ALL = 0 - REPOLISTFILTER_DISABLED = 2 - REPOLISTFILTER_ENABLED = 1 -``` - -example: -``` -root [ / ]# python3 -Python 3.7.3 (default, Jun 20 2019, 03:44:05) -[GCC 7.3.0] on linux -Type "help", "copyright", "credits" or "license" for more information. ->>> import tdnf ->>> tdnf.repolist() -[{id: photon-updates, name: VMware Photon Linux 3.0(x86_64) Updates, baseurl: https://dl.bintray.com/vmware/photon_updates_3.0_x86_64, enabled: 1}, {id: photon, name: VMware Photon Linux 3.0(x86_64), baseurl: https://dl.bintray.com/vmware/photon_release_3.0_x86_64, enabled: 1}, {id: photon-extras, name: VMware Photon Extras 3.0(x86_64), baseurl: https://dl.bintray.com/vmware/photon_extras_3.0_x86_64, enabled: 1}] ->>> tdnf.repolist(filter=tdnf.REPOLISTFILTER_DISABLED) -[{id: photon-iso, name: VMWare Photon Linux ISO 3.0(x86_64), baseurl: file:///mnt/cdrom/RPMS, enabled: 0}, {id: photon-debuginfo, name: VMware Photon Linux debuginfo 3.0(x86_64), baseurl: https://dl.bintray.com/vmware/photon_debuginfo_$releasever_$basearch, enabled: 0}] -``` - -##install -installs a list of packages and their depedencies. updates installed packages if there are updates available. - -##parameter (required): pkgs -``` -tdnf.install(pkgs=['curl','wget']) -``` - -##parameter (optional): quiet -``` -tdnf.install(pkgs=['curl','wget'], quiet=True) -``` - -##parameter (optional): refresh -``` -tdnf.install(pkgs=['curl','wget'], refresh=True) -``` - -##update -updates specified packages or all packages that have updates. - -##parameter (optional): pkgs -``` -tdnf.update(pkgs=['curl','wget']) -``` - -##parameter (optional): quiet -``` -tdnf.update(pkgs=['curl','wget'], quiet=True) -``` - -##parameter (optional): refresh -``` -tdnf.update(pkgs=['curl','wget'], refresh=True) -``` - -##downgrade -downgrades specified packages or all packages that have a downgrade path. - -##parameter (optional): pkgs -``` -tdnf.downgrade(pkgs=['curl','wget']) -``` - -##parameter (optional): quiet -``` -tdnf.downgrade(pkgs=['curl','wget'], quiet=True) -``` - -##parameter (optional): refresh -``` -tdnf.downgrade(pkgs=['curl','wget'], refresh=True) -``` - -##erase -remove specified packages and their dependencies - -##parameter (required): pkgs -``` -tdnf.erase(pkgs=['wget']) -``` - -##parameter (optional): quiet -``` -tdnf.erase(pkgs=['wget'], quiet=True) -``` - -##parameter (optional): refresh -``` -tdnf.erase(pkgs=['wget'], refresh=True) -``` - -##erase -synchronize installed packages to the latest available versions - -##parameter (optional): quiet -``` -tdnf.distro_sync(quiet=True) -``` - -##parameter (optional): refresh -``` -tdnf.distro_sync(refresh=True) -``` diff --git a/python/includes.h b/python/includes.h deleted file mode 100644 index 0ffb5f33..00000000 --- a/python/includes.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU Lesser General Public License v2.1 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#pragma once - -#include -#include -#include -#include -#include - -#include "../common/defines.h" -#include "../common/structs.h" -#include "../common/prototypes.h" -#include "structs.h" -#include "prototypes.h" diff --git a/python/prototypes.h b/python/prototypes.h deleted file mode 100644 index 5049021b..00000000 --- a/python/prototypes.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2019 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#pragma once - -/* tdnfpycommands.c */ -PyObject * -TDNFPyRepoList(PyObject *self, PyObject *args, PyObject *kwds); - -PyObject * -TDNFPyInstall(PyObject *self, PyObject *args, PyObject *kwds); - -PyObject * -TDNFPyUpdate(PyObject *self, PyObject *args, PyObject *kwds); - -PyObject * -TDNFPyDowngrade(PyObject *self, PyObject *args, PyObject *kwds); - -PyObject * -TDNFPyErase(PyObject *self, PyObject *args, PyObject *kwds); - -PyObject * -TDNFPyDistroSync(PyObject *self, PyObject *args, PyObject *kwds); - -/* tdnfpyrepodata.c */ -uint32_t -TDNFPyMakeRepoData( - PTDNF_REPO_DATA pRepoData, - PyObject **ppPyRepoData - ); - -/* utils.c */ -uint32_t -TDNFPyListAsStringList( - PyObject *pyList, - char ***pppszStrings, - size_t *pnCount - ); - -uint32_t -TDNFPyAddEnums( - PyObject *pModule - ); - -void -TDNFPyRaiseException( - PyObject *self, - uint32_t dwErrorCode - ); diff --git a/python/setup.py.in b/python/setup.py.in deleted file mode 100644 index 089a018d..00000000 --- a/python/setup.py.in +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved. -# -# Licensed under the GNU General Public License v2 (the "License"); -# you may not use this file except in compliance with the License. The terms -# of the License are located in the COPYING file of this distribution. -# - -from setuptools import setup -from distutils.core import Extension - -cflags = [ - '-I@PYTDNF_INC_DIR@', -] - -pytdnf_sources = [ - '@PYTDNF_SRC_DIR@/tdnfbase.c', - '@PYTDNF_SRC_DIR@/tdnfpyrepodata.c', - '@PYTDNF_SRC_DIR@/tdnfpycommands.c', - '@PYTDNF_SRC_DIR@/tdnfmodule.c', - '@PYTDNF_SRC_DIR@/utils.c' -] - -tdnfmodule = Extension('tdnf._tdnf', - libraries=['tdnf'], - library_dirs=['${PYTDNF_LIB_DIR}'], - sources=pytdnf_sources, - extra_compile_args=cflags) - -setup(name='@PYTDNF_PACKAGE_NAME@', - version='@PYTDNF_VERSION@', - description='Python bindings for @PYTDNF_PACKAGE_NAME@', - packages=['@PYTDNF_PACKAGE_NAME@'], - url='https://github.com/vmware/tdnf', - ext_modules=[tdnfmodule]) diff --git a/python/structs.h b/python/structs.h deleted file mode 100644 index 03af88a3..00000000 --- a/python/structs.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2019-2020 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#pragma once - -typedef struct _PY_TDNF_ -{ - PyObject_HEAD -}PY_TDNF, *PPY_TDNF; - -typedef struct _PY_TDNF_BASE_ -{ - PyObject_HEAD -}PY_TDNF_BASE, *PPY_TDNF_BASE; - -typedef struct _PY_TDNF_REPODATA -{ - PyObject_HEAD - PyObject *id; - PyObject *name; - PyObject *baseurl; - PyObject *metalink; - int enabled; -}PY_TDNF_REPODATA, *PPY_TDNF_REPODATA; diff --git a/python/tdnf/__init__.py b/python/tdnf/__init__.py deleted file mode 100644 index b3573c41..00000000 --- a/python/tdnf/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright (C) 2019 VMware, Inc. All Rights Reserved. -# -# Licensed under the GNU General Public License v2 (the "License"); -# you may not use this file except in compliance with the License. The terms -# of the License are located in the COPYING file of this distribution. -# - -from tdnf._tdnf import * diff --git a/python/tdnfbase.c b/python/tdnfbase.c deleted file mode 100644 index 39c75155..00000000 --- a/python/tdnfbase.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2019-2020 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#include "includes.h" -#include "tdnfbase.h" - -static char base__doc__[] = ""; - -static void -base_dealloc(PPY_TDNF_BASE self) -{ - Py_TYPE(self)->tp_free((PyObject*)self); -} - -static PyObject * -base_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PPY_TDNF_BASE self = NULL; - - self = (PPY_TDNF_BASE)type->tp_alloc(type, 0); - if (self != NULL) - { - } - - return (PyObject *)self; -} - -static int -base_init(PPY_TDNF_BASE self, PyObject *args, PyObject *kwds) -{ - uint32_t dwError = 0; - -//error: - return dwError; -} - -static PyObject * -base_get_version( - PPY_TDNF_BASE self, - void *closure) -{ - return NULL; -} - -static PyGetSetDef base_getset[] = { - {"version", - (getter)base_get_version, (setter)NULL, - "tdnf version", - NULL}, - {NULL} /* Sentinel */ -}; - -static PyMethodDef base_methods[] = { - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -static PyMemberDef base_members[] = { - {NULL} /* Sentinel */ -}; - -PyTypeObject baseType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "tdnf.Base", /*tp_name*/ - sizeof(PY_TDNF_BASE), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)base_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - base__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - base_methods, /* tp_methods */ - base_members, /* tp_members */ - base_getset, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)base_init, /* tp_init */ - 0, /* tp_alloc */ - base_new, /* tp_new */ - 0, /* tp_free */ - 0, /* tp_is_gc */ -}; diff --git a/python/tdnfbase.h b/python/tdnfbase.h deleted file mode 100644 index 064b0892..00000000 --- a/python/tdnfbase.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (C) 2019 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#pragma once - -extern PyTypeObject baseType; diff --git a/python/tdnfmodule.c b/python/tdnfmodule.c deleted file mode 100644 index 022b6ba9..00000000 --- a/python/tdnfmodule.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (C) 2019-2021 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#include "includes.h" -#include "tdnfpyrepodata.h" - -static char tdnf__doc__[] = ""; - -PyObject *pyTDNFError = NULL; - -static int -TDNFPyPrepareInitModule( - ) -{ - if (PyType_Ready(&repodataType) < 0) return 0; - return 1; -} - -static PyMethodDef TDNFPyMethods[] = -{ - {"repolist", (PyCFunction)TDNFPyRepoList, METH_VARARGS|METH_KEYWORDS, - "repolist() -- returns a list of enabled repositories\n\n" - "repolist(filter=tdnf.REPOLISTFILTER_ALL) -- returns a list of all repositories\n\n" - "options: config= -- tdnf config file path\n\n"}, - {"install", (PyCFunction)TDNFPyInstall, METH_VARARGS|METH_KEYWORDS, - "install(list of package names) -- install packages\n\n" - "Eg: import tdnf; tdnf.install(pkgs=['curl','curl-devel'])\n\n" - "options: quiet=True -- dont print progress\n\n" - "options: refresh=True -- refresh cache before install\n\n" - "options: config= -- tdnf config file path\n\n"}, - {"update", (PyCFunction)TDNFPyUpdate, METH_VARARGS|METH_KEYWORDS, - "update(optional list of package names) -- update packages\n\n" - "Eg: import tdnf; tdnf.update() -- update all\n\n" - "Eg: import tdnf; tdnf.update(pkgs=['curl']) -- update curl\n\n" - "options: quiet=True -- dont print progress\n\n" - "options: refresh=True -- refresh cache before update\n\n" - "options: config= -- tdnf config file path\n\n"}, - {"downgrade", (PyCFunction)TDNFPyDowngrade, METH_VARARGS|METH_KEYWORDS, - "downgrade(optional list of package names) -- downgrade packages\n\n" - "Eg: import tdnf; tdnf.downgrade() -- downgrade all\n\n" - "Eg: import tdnf; tdnf.downgrade(pkgs=['curl']) -- downgrade curl\n\n" - "options: quiet=True -- dont print progress\n\n" - "options: refresh=True -- refresh cache before downgrade\n\n" - "options: config= -- tdnf config file path\n\n"}, - {"erase", (PyCFunction)TDNFPyErase, METH_VARARGS|METH_KEYWORDS, - "erase(list of package names) -- erase packages\n\n" - "Eg: import tdnf; tdnf.erase(['wget']) -- erase wget\n\n" - "options: quiet=True -- dont print progress\n\n" - "options: refresh=True -- refresh cache before remove\n\n" - "options: config= -- tdnf config file path\n\n"}, - {"distro_sync", (PyCFunction)TDNFPyDistroSync, METH_VARARGS|METH_KEYWORDS, - "distro_sync() -- distro sync installed packages\n\n" - "Eg: import tdnf; tdnf.distro_sync() -- distro sync all\n\n" - "options: quiet=True -- dont print progress\n\n" - "options: refresh=True -- refresh cache before distro sync\n\n" - "options: config= -- tdnf config file path\n\n"}, - {NULL} /* Sentinel */ -}; - -static int -TDNFPyInitModule( - PyObject *pModule - ) -{ - int ret = 0; - int dwError = 0; - PyObject *pyDict = NULL; - - dwError = TDNFInit(); - BAIL_ON_TDNF_ERROR(dwError); - - pyDict = PyModule_GetDict(pModule); - if (!pyDict) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - pyTDNFError = PyErr_NewException("_tdnf.error", NULL, NULL); - if (pyTDNFError != NULL) - { - PyDict_SetItemString(pyDict, "error", pyTDNFError); - } - - PyModule_AddStringConstant(pModule, "__version__", TDNFGetVersion()); - - dwError = TDNFPyAddEnums(pModule); - BAIL_ON_TDNF_ERROR(dwError); - - ret = 1; - -error: - return ret; -} - -#if PY_MAJOR_VERSION >= 3 - -static struct PyModuleDef tdnfModule = -{ - PyModuleDef_HEAD_INIT, - "_tdnf", /* name of module */ - tdnf__doc__, /* module documentation, may be NULL */ - 0, /* m_size */ - TDNFPyMethods -}; - -PyObject * -PyInit__tdnf( - ) -{ - PyObject *pModule = NULL; - - if (!TDNFPyPrepareInitModule()) - return NULL; - - pModule = PyModule_Create(&tdnfModule); - if(!pModule) - { - goto error; - } - - if(!TDNFPyInitModule(pModule)) - { - goto error; - } - -cleanup: - return pModule; - -error: - if(pModule) - { - Py_XDECREF(pModule); - } - pModule = NULL; - goto cleanup; -} - -static int __Pyx_main(int argc, wchar_t **argv) -{ - /* Add a built-in module, before Py_Initialize */ - PyImport_AppendInittab("_tdnf", PyInit__tdnf); - -#if PY_VERSION_HEX < 0x03080000 - /* Pass argv[0] to the Python interpreter */ - Py_SetProgramName(argv[0]); - - /* Initialize the Python interpreter. Required. */ - Py_Initialize(); -#else - { - PyStatus status; - - PyConfig config; - PyConfig_InitPythonConfig(&config); - - if (argc && argv) { - status = PyConfig_SetString(&config, &config.program_name, argv[0]); - if (PyStatus_Exception(status)) { - PyConfig_Clear(&config); - return 1; - } - - status = PyConfig_SetArgv(&config, argc, argv); - if (PyStatus_Exception(status)) { - PyConfig_Clear(&config); - return 1; - } - } - - status = Py_InitializeFromConfig(&config); - if (PyStatus_Exception(status)) { - PyConfig_Clear(&config); - return 1; - } - - PyConfig_Clear(&config); - } -#endif /* PY_VERSION_HEX < 0x03080000 */ - - /* - * Optionally import the module; alternatively, - * import can be deferred until the embedded script - * imports it. - */ - PyImport_ImportModule("_tdnf"); - - return 0; -} - -#else - -PyMODINIT_FUNC -init_tdnf( - ) -{ - PyObject *pModule = NULL; - - if (!TDNFPyPrepareInitModule()) - return; - - pModule = Py_InitModule3("_tdnf", TDNFPyMethods, tdnf__doc__); - if(pModule) - { - TDNFPyInitModule(pModule); - } -} - -int -main( - int argc, - char *argv[] - ) -{ - /* Pass argv[0] to the Python interpreter */ - Py_SetProgramName(argv[0]); - - - /* Initialize the Python interpreter. Required. */ - Py_Initialize(); - - /* Add a static module */ - init_tdnf(); - - return 0; -} - -#endif diff --git a/python/tdnfpycommands.c b/python/tdnfpycommands.c deleted file mode 100644 index 25e07d92..00000000 --- a/python/tdnfpycommands.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#include "includes.h" - -/* returns a list of repos */ -PyObject * -TDNFPyRepoList(PyObject *self, PyObject *args, PyObject *kwds) -{ - uint32_t dwError = 0; - char *kwlist[] = { "filter", "config", NULL }; - PyObject *ppyRepoList = Py_None; - TDNF_CMD_ARGS cmdArgs = {0}; - char *szCmds[] = {""}; - PTDNF pTDNF = NULL; - PTDNF_REPO_DATA pRepos = NULL; - PTDNF_REPO_DATA pReposTemp = NULL; - TDNF_REPOLISTFILTER nFilter = REPOLISTFILTER_ENABLED; - PyObject *CfgFile = NULL; - - cmdArgs.pszInstallRoot = "/"; - cmdArgs.ppszCmds = szCmds; - cmdArgs.nCmdCount = 1; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|iO", kwlist, - &nFilter, &CfgFile)) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - if (CfgFile) - { - const char *fname = PyUnicode_AsUTF8(CfgFile); - dwError = TDNFAllocateString(fname, &cmdArgs.pszConfFile); - BAIL_ON_TDNF_ERROR(dwError); - } - - ppyRepoList = PyList_New(0); - if (!ppyRepoList) - { - dwError = ERROR_TDNF_OUT_OF_MEMORY; - BAIL_ON_TDNF_ERROR(dwError); - } - - dwError = TDNFOpenHandle(&cmdArgs, &pTDNF); - BAIL_ON_TDNF_ERROR(dwError); - - if (nFilter < REPOLISTFILTER_ALL || nFilter > REPOLISTFILTER_DISABLED) - { - nFilter = REPOLISTFILTER_ENABLED; - } - dwError = TDNFRepoList(pTDNF, nFilter, &pRepos); - BAIL_ON_TDNF_ERROR(dwError); - - for(pReposTemp = pRepos; pReposTemp; pReposTemp = pReposTemp->pNext) - { - PyObject *pPyRepoData = NULL; - - dwError = TDNFPyMakeRepoData(pReposTemp, &pPyRepoData); - BAIL_ON_TDNF_ERROR(dwError); - - if(PyList_Append(ppyRepoList, pPyRepoData) == -1) - { - dwError = ERROR_TDNF_OUT_OF_MEMORY; - BAIL_ON_TDNF_ERROR(dwError); - } - } - -cleanup: - TDNF_SAFE_FREE_MEMORY(cmdArgs.pszConfFile); - if (pRepos) - { - TDNFFreeRepos(pRepos); - } - if (pTDNF) - { - TDNFCloseHandle(pTDNF); - } - return ppyRepoList; - -error: - TDNFPyRaiseException(self, dwError); - goto cleanup; -} - -/* alter */ -uint32_t -_TDNFPyGetAlterArgs(TDNF_ALTERTYPE type, PyObject *args, - PyObject *kwds, PTDNF_CMD_ARGS pCmdArgs) -{ - size_t nPkgCount = 0; - uint32_t dwError = 0; - char *kwlist[] = { "pkgs", "refresh", "quiet", "config", NULL }; - PyObject *pyPkgList = NULL; - PyObject *pyRefresh = NULL; - PyObject *pyQuiet = NULL; - PyObject *CfgFile = NULL; - PyObject *ppyString = NULL; - - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|O!O!O!O", kwlist, - &PyList_Type, &pyPkgList, - &PyBool_Type, &pyRefresh, - &PyBool_Type, &pyQuiet, - &CfgFile)) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - if(pyPkgList) - { - ppyString = PyBytes_FromFormat("%s", " "); - if (!ppyString) - { - dwError = ERROR_TDNF_OUT_OF_MEMORY; - BAIL_ON_TDNF_ERROR(dwError); - } - - /* add an empty item in front of list for cmdargs book keeping */ - dwError = PyList_Insert(pyPkgList, 0, ppyString); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFPyListAsStringList( - pyPkgList, - &pCmdArgs->ppszCmds, - &nPkgCount); - BAIL_ON_TDNF_ERROR(dwError); - } - else - { - dwError = TDNFAllocateMemory(2, sizeof(char *), (void **)&pCmdArgs->ppszCmds); - BAIL_ON_TDNF_ERROR(dwError); - - pCmdArgs->ppszCmds[0] = strdup(""); - nPkgCount = 1; - } - - if (CfgFile) - { - const char *fname = PyUnicode_AsUTF8(CfgFile); - dwError = TDNFAllocateString(fname, &pCmdArgs->pszConfFile); - BAIL_ON_TDNF_ERROR(dwError); - } - - pCmdArgs->nRefresh = pyRefresh ? PyObject_IsTrue(pyRefresh) : 0; - pCmdArgs->nQuiet = pyQuiet ? PyObject_IsTrue(pyQuiet) : 0; - pCmdArgs->nCmdCount = nPkgCount; - -error: - return dwError; -} - -/* alter */ -PyObject * -_TDNFPyAlter(TDNF_ALTERTYPE alterType, PyObject *self, PyObject *args, PyObject *kwds) -{ - uint32_t dwError = 0; - TDNF_CMD_ARGS cmdArgs = {0}; - PTDNF pTDNF = NULL; - PTDNF_SOLVED_PKG_INFO pSolvedInfo = NULL; - - if (geteuid()) - { - dwError = ERROR_TDNF_PERM; - BAIL_ON_TDNF_ERROR(dwError); - } - - cmdArgs.pszInstallRoot = "/"; - - dwError = _TDNFPyGetAlterArgs(alterType, args, kwds, &cmdArgs); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFOpenHandle(&cmdArgs, &pTDNF); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFResolve(pTDNF, alterType, &pSolvedInfo); - if (dwError == ERROR_TDNF_ALREADY_INSTALLED) - { - dwError = 0; - } - BAIL_ON_TDNF_ERROR(dwError); - - if (pSolvedInfo && pSolvedInfo->nNeedAction) - { - dwError = TDNFAlterCommand(pTDNF, pSolvedInfo); - BAIL_ON_TDNF_ERROR(dwError); - } - -cleanup: - TDNF_SAFE_FREE_MEMORY(cmdArgs.pszConfFile); - TDNFFreeStringArrayWithCount(cmdArgs.ppszCmds, cmdArgs.nCmdCount); - TDNFFreeSolvedPackageInfo(pSolvedInfo); - if (pTDNF) - { - TDNFCloseHandle(pTDNF); - } - return Py_BuildValue("i", dwError); - -error: - if (dwError == ERROR_TDNF_CLI_NOTHING_TO_DO || - dwError == ERROR_TDNF_NO_DATA) - { - dwError = 0; - } - else - { - TDNFPyRaiseException(self, dwError); - } - goto cleanup; -} - -/* install command */ -PyObject * -TDNFPyInstall(PyObject *self, PyObject *args, PyObject *kwds) -{ - return _TDNFPyAlter(ALTER_INSTALL, self, args, kwds); -} - -/* update command */ -PyObject * -TDNFPyUpdate(PyObject *self, PyObject *args, PyObject *kwds) -{ - return _TDNFPyAlter(ALTER_UPGRADE, self, args, kwds); -} - -/* downgrade command */ -PyObject * -TDNFPyDowngrade(PyObject *self, PyObject *args, PyObject *kwds) -{ - return _TDNFPyAlter(ALTER_DOWNGRADE, self, args, kwds); -} - -/* erase command */ -PyObject * -TDNFPyErase(PyObject *self, PyObject *args, PyObject *kwds) -{ - return _TDNFPyAlter(ALTER_ERASE, self, args, kwds); -} - -/* distro_sync command */ -PyObject * -TDNFPyDistroSync(PyObject *self, PyObject *args, PyObject *kwds) -{ - return _TDNFPyAlter(ALTER_DISTRO_SYNC, self, args, kwds); -} diff --git a/python/tdnfpyrepodata.c b/python/tdnfpyrepodata.c deleted file mode 100644 index d955a19b..00000000 --- a/python/tdnfpyrepodata.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (C) 2019-2022 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#include "includes.h" -#include "tdnfpyrepodata.h" - -static char repodata__doc__[] = ""; - -static void -TDNFPyRepoDataFree(PY_TDNF_REPODATA *self) -{ - Py_XDECREF(self->id); - Py_XDECREF(self->name); - Py_XDECREF(self->baseurl); - Py_XDECREF(self->metalink); - Py_TYPE(self)->tp_free((PyObject*)self); -} - -static PyObject * -TDNFPyRepoDataNew( - PyTypeObject *type, - PyObject *args, - PyObject *kwds) -{ - PPY_TDNF_REPODATA self = NULL; - - self = (PPY_TDNF_REPODATA)type->tp_alloc(type, 0); - if (self) - { - if (!(self->id = PyBytes_FromString("")) || - !(self->name = PyBytes_FromString("")) || - !(self->baseurl = PyBytes_FromString("")) || - !(self->baseurl = PyBytes_FromString(""))) - { - Py_DECREF(self); - self = NULL; - } - } - - return (PyObject *)self; -} - -static int -TDNFPyRepoDataInit( - PY_TDNF_REPODATA *self, - PyObject *args, - PyObject *kwds - ) -{ - uint32_t dwError = 0; - PyObject *id = NULL; - PyObject *name = NULL; - PyObject *baseurl = NULL; - PyObject *metalink = NULL; - PyObject *tmp = NULL; - - static char *kwlist[] = {"id", "name", "baseurl", "metalink", "enabled", NULL}; - - if (! PyArg_ParseTupleAndKeywords(args, kwds, "|SSSI", kwlist, - &id, &name, &baseurl, &metalink, &self->enabled)) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - if (id) - { - tmp = self->id; - Py_INCREF(id); - self->id = id; - Py_XDECREF(tmp); - } - if (name) - { - tmp = self->name; - Py_INCREF(name); - self->name = name; - Py_XDECREF(tmp); - } - if (baseurl) - { - tmp = self->baseurl; - Py_INCREF(baseurl); - self->baseurl = baseurl; - Py_XDECREF(tmp); - } - if (metalink) - { - tmp = self->metalink; - Py_INCREF(metalink); - self->metalink = metalink; - Py_XDECREF(tmp); - } - -cleanup: - return dwError > 0 ? -1 : 0; - -error: - pr_err("Error = %u\n", dwError); - goto cleanup; -} - -PyObject* -TDNFPyRepoDataRepr( - PyObject *self - ) -{ - char *pszRepr = NULL; - uint32_t dwError = 0; - PyObject *pyRepr = Py_None; - PPY_TDNF_REPODATA pRepoData = NULL; - - pRepoData = (PPY_TDNF_REPODATA)self; - - dwError = TDNFAllocateStringPrintf( - &pszRepr, - "{id: %s, name: %s, baseurl: %s, metalink: %s, enabled: %d}", - pRepoData->id ? PyBytes_AsString(pRepoData->id) : "''", - pRepoData->name ? PyBytes_AsString(pRepoData->name) : "''", - pRepoData->baseurl ? PyBytes_AsString(pRepoData->baseurl) : "''", - pRepoData->metalink ? PyBytes_AsString(pRepoData->metalink) : "''", - pRepoData->enabled); - BAIL_ON_TDNF_ERROR(dwError); - - pyRepr = Py_BuildValue("s", pszRepr); - Py_INCREF(pyRepr); - -cleanup: - TDNF_SAFE_FREE_MEMORY(pszRepr); - return pyRepr; - -error: - pr_crit("Error = %u\n", dwError); - pyRepr = Py_None; - goto cleanup; - -} - -PyObject* -TDNFPyRepoDataStr( - PyObject *self - ) -{ - return TDNFPyRepoDataRepr(self); -} - -uint32_t -TDNFPyMakeRepoData( - PTDNF_REPO_DATA pRepoData, - PyObject **ppPyRepoData - ) -{ - uint32_t dwError = 0; - PPY_TDNF_REPODATA pPyRepoData = NULL; - PyTypeObject *retType = &repodataType; - - if(!pRepoData || !ppPyRepoData) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - pPyRepoData = (PPY_TDNF_REPODATA)retType->tp_alloc(retType, 0); - if(!pPyRepoData) - { - dwError = ERROR_TDNF_OUT_OF_MEMORY; - BAIL_ON_TDNF_ERROR(dwError); - } - - if (pRepoData->pszId) - { - pPyRepoData->id = PyBytes_FromString(pRepoData->pszId); - } - - if (pRepoData->pszName) - { - pPyRepoData->name = PyBytes_FromString(pRepoData->pszName); - } - - if (pRepoData->ppszBaseUrls && pRepoData->ppszBaseUrls[0]) - { - pPyRepoData->baseurl = PyBytes_FromString(pRepoData->ppszBaseUrls[0]); - } - - if (pRepoData->pszMetaLink) - { - pPyRepoData->metalink = PyBytes_FromString(pRepoData->pszMetaLink); - } - - pPyRepoData->enabled = pRepoData->nEnabled; - - - *ppPyRepoData = (PyObject *)pPyRepoData; -cleanup: - return dwError; - -error: - Py_XDECREF(pPyRepoData); - goto cleanup; -} - -static PyGetSetDef TDNFPyRepoDataGetSet[] = { - {NULL} /* Sentinel */ -}; - -static PyMethodDef TDNFPyRepoDataMethods[] = { - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -static PyMemberDef TDNFPyRepoDataMembers[] = { - {"id", T_OBJECT_EX, offsetof(PY_TDNF_REPODATA, id), 0, - "repo id"}, - {"name", T_OBJECT_EX, offsetof(PY_TDNF_REPODATA, name), 0, - "repo name"}, - {"baseurl", T_OBJECT_EX, offsetof(PY_TDNF_REPODATA, baseurl), 0, - "repo baseurl"}, - {"metalink", T_OBJECT_EX, offsetof(PY_TDNF_REPODATA, metalink), 0, - "repo metalink"}, - {"enabled", T_INT, offsetof(PY_TDNF_REPODATA, enabled), 0, - "repo enabled status"}, - {NULL} /* Sentinel */ -}; - -PyTypeObject repodataType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) - "repodata", /*tp_name*/ - sizeof(PY_TDNF_REPODATA), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)TDNFPyRepoDataFree, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - TDNFPyRepoDataRepr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - TDNFPyRepoDataStr, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - repodata__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - TDNFPyRepoDataMethods, /* tp_methods */ - TDNFPyRepoDataMembers, /* tp_members */ - TDNFPyRepoDataGetSet, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)TDNFPyRepoDataInit, /* tp_init */ - 0, /* tp_alloc */ - TDNFPyRepoDataNew, /* tp_new */ - 0, /* tp_free */ - 0 /* tp_is_gc */ -}; diff --git a/python/tdnfpyrepodata.h b/python/tdnfpyrepodata.h deleted file mode 100644 index 6ecf44cb..00000000 --- a/python/tdnfpyrepodata.h +++ /dev/null @@ -1,12 +0,0 @@ - -/* - * Copyright (C) 2019 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#pragma once - -extern PyTypeObject repodataType; diff --git a/python/utils.c b/python/utils.c deleted file mode 100644 index 27718ecc..00000000 --- a/python/utils.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2019 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU General Public License v2 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -#include "includes.h" - -uint32_t -py_string_as_string( - PyObject *pyObj, - PyObject **ppString - ) -{ - uint32_t dwError = 0; - PyObject *pString = NULL; - if(!pyObj || !ppString) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - if(PyBytes_Check(pyObj)) - { - Py_XINCREF(pyObj); - pString = pyObj; - } - else if(PyUnicode_Check(pyObj)) - { - pString = PyUnicode_AsUTF8String(pyObj); - } - - if(!pString) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - *ppString = pString; -cleanup: - return dwError; - -error: - goto cleanup; -} - -char * -string_from_py_string( - PyObject *pyString - ) -{ - char *pszResult = PyBytes_AsString(pyString); - if(!pszResult || !*pszResult) - { - pszResult = NULL; - } - return pszResult; -} - -uint32_t -TDNFPyListAsStringList( - PyObject *pyList, - char ***pppszStrings, - size_t *pnCount - ) -{ - uint32_t dwError = 0; - char **ppszStrings = NULL; - size_t i = 0; - size_t nCount = 0; - - if(!pyList || !pppszStrings) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - nCount = PyList_Size(pyList); - if(nCount == 0) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - dwError = TDNFAllocateMemory(nCount + 1, - sizeof(char *), - (void **)&ppszStrings); - BAIL_ON_TDNF_ERROR(dwError); - for(i = 0; i < nCount; ++i) - { - PyObject *pyItem = NULL; - PyObject *pyString = NULL; - pyItem = PyList_GetItem(pyList, i); - dwError = py_string_as_string(pyItem, &pyString); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFAllocateString(PyBytes_AsString(pyString), - &ppszStrings[i]); - BAIL_ON_TDNF_ERROR(dwError); - } - - *pppszStrings = ppszStrings; - *pnCount = nCount; - -cleanup: - return dwError; - -error: - if(pppszStrings) - { - *pppszStrings = NULL; - } - if(pnCount) - { - *pnCount = 0; - } - TDNFFreeStringArray(ppszStrings); - goto cleanup; -} - -void -TDNFPyRaiseException( - PyObject *self, - uint32_t dwErrorCode - ) -{ - uint32_t dwError = 0; - char *pszError = NULL; - char *pszMessage = NULL; - - dwError = TDNFGetErrorString(dwErrorCode, &pszError); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFAllocateStringPrintf(&pszMessage, - "Error = %d: %s", - dwErrorCode, - pszError); - BAIL_ON_TDNF_ERROR(dwError); - - PyErr_SetString(PyExc_Exception, pszMessage); - -cleanup: - TDNF_SAFE_FREE_MEMORY(pszMessage); - TDNF_SAFE_FREE_MEMORY(pszError); - return; - -error: - goto cleanup; -} - -uint32_t -TDNFPyAddEnums(PyObject *pModule) -{ - uint32_t dwError = 0; - if (!pModule) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - dwError = PyModule_AddIntMacro(pModule, REPOLISTFILTER_ALL); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = PyModule_AddIntMacro(pModule, REPOLISTFILTER_ENABLED); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = PyModule_AddIntMacro(pModule, REPOLISTFILTER_DISABLED); - BAIL_ON_TDNF_ERROR(dwError); - -cleanup: - return dwError; - -error: - goto cleanup; -} diff --git a/scripts/llvm-tdnf-build.sh b/scripts/llvm-tdnf-build.sh index 36c4f83d..d509be65 100755 --- a/scripts/llvm-tdnf-build.sh +++ b/scripts/llvm-tdnf-build.sh @@ -20,5 +20,4 @@ p=$(nproc) mkdir -p $history_loc cmake -DHISTORY_DB_DIR=$history_loc .. && \ make -j$p && \ - make python -j$p && \ make check -j$p || exit 1 diff --git a/tdnf.spec.in b/tdnf.spec.in index 9bd13453..b40ba88b 100644 --- a/tdnf.spec.in +++ b/tdnf.spec.in @@ -34,8 +34,6 @@ BuildRequires: expat-devel #repogpgcheck plugin BuildRequires: gpgme-devel BuildRequires: cmake -BuildRequires: python3-devel -BuildRequires: python3-setuptools %if 0%{?with_check} BuildRequires: createrepo_c BuildRequires: glib @@ -72,7 +70,6 @@ Requires: %{name} = %{version}-%{release} Requires: %{name}-automatic = %{version}-%{release} Requires: %{name}-plugin-repogpgcheck = %{version}-%{release} Requires: %{name}-plugin-metalink = %{version}-%{release} -Requires: %{name}-python = %{version}-%{release} Requires: python3-pytest Requires: python3-requests Requires: rpm-build @@ -110,14 +107,6 @@ Requires: gpgme %description plugin-repogpgcheck %{name} plugin providing gpg verification for repository metadata -%package python -Summary: python bindings for %{name} -Group: Development/Libraries -Requires: python3 - -%description python -python bindings for %{name} - %package automatic Summary: %{name} - automated upgrades Group: Development/Libraries @@ -140,7 +129,6 @@ cmake \ .. %make_build -%make_build python %if 0%{?with_check} %check @@ -157,9 +145,6 @@ mkdir -p %{buildroot}/var/cache/%{name} %{buildroot}%{_unitdir} ln -sfv %{name} %{buildroot}%{_bindir}/tyum ln -sfv %{name} %{buildroot}%{_bindir}/yum ln -sfv %{name} %{buildroot}%{_bindir}/tdnfj -pushd build/python -python3 setup.py install --skip-build --prefix=%{_prefix} --root=%{buildroot} -popd find %{buildroot} -name '*.pyc' -delete %pre @@ -271,10 +256,6 @@ systemctl try-restart %{name}-cache-updateinfo.timer >/dev/null 2>&1 || : %config(noreplace) %{_sysconfdir}/%{name}/pluginconf.d/tdnfrepogpgcheck.conf %{_tdnfpluginsdir}/libtdnfrepogpgcheck.so -%files python -%defattr(-,root,root) -%{python3_sitelib}/* - %files automatic %defattr(-,root,root,0755) %{_bindir}/%{name}-automatic