From ef69c002a69e5d7983554b68d41f26e06ad8fb7c Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sat, 5 Nov 2011 19:17:01 +0100 Subject: Use ctypes module to access alpm_pkg_vercmp() instead of the C module. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Oudompheng --- cron-jobs/check_archlinux/README | 8 +----- cron-jobs/check_archlinux/alpm.c | 40 ---------------------------- cron-jobs/check_archlinux/alpm.so | Bin 7057 -> 0 bytes cron-jobs/check_archlinux/check_packages.py | 17 ++++++++++-- cron-jobs/check_archlinux/setup.py | 10 ------- 5 files changed, 16 insertions(+), 59 deletions(-) delete mode 100644 cron-jobs/check_archlinux/alpm.c delete mode 100755 cron-jobs/check_archlinux/alpm.so delete mode 100644 cron-jobs/check_archlinux/setup.py (limited to 'cron-jobs') diff --git a/cron-jobs/check_archlinux/README b/cron-jobs/check_archlinux/README index 8f178dc..03bb0e0 100644 --- a/cron-jobs/check_archlinux/README +++ b/cron-jobs/check_archlinux/README @@ -1,8 +1,2 @@ -1) Build the python module -$ python2 setup.py build - -2) copy it back to the current working directory -$ cp build/lib.*/alpm.* . - -3) run the script +1) run the script $ ./check_packages.py -h diff --git a/cron-jobs/check_archlinux/alpm.c b/cron-jobs/check_archlinux/alpm.c deleted file mode 100644 index 0b7cd2c..0000000 --- a/cron-jobs/check_archlinux/alpm.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - -static PyObject * -alpm_vercmp(PyObject *self, PyObject *args) -{ - const char *v1, *v2; - int ret; - - if (!PyArg_ParseTuple(args, "ss", &v1, &v2)) - return NULL; - ret = alpm_pkg_vercmp(v1, v2); - return Py_BuildValue("i", ret); -} - -static PyMethodDef AlpmMethods[] = { - {"vercmp", alpm_vercmp, METH_VARARGS, - "Execute vercmp."}, - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -PyMODINIT_FUNC -initalpm(void) -{ - (void) Py_InitModule("alpm", AlpmMethods); -} - -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 */ - initalpm(); - return 0; -} diff --git a/cron-jobs/check_archlinux/alpm.so b/cron-jobs/check_archlinux/alpm.so deleted file mode 100755 index 8944bbe..0000000 Binary files a/cron-jobs/check_archlinux/alpm.so and /dev/null differ diff --git a/cron-jobs/check_archlinux/check_packages.py b/cron-jobs/check_archlinux/check_packages.py index 0a2b10e..06589ca 100755 --- a/cron-jobs/check_archlinux/check_packages.py +++ b/cron-jobs/check_archlinux/check_packages.py @@ -16,9 +16,12 @@ # a non-core package) # 8. Circular dependencies -import os,re,commands,getopt,sys,tarfile,alpm +import os,re,commands,getopt,sys,tarfile import pdb +import ctypes +_alpm = ctypes.cdll.LoadLibrary("libalpm.so") + DBEXT='.db.tar.gz' packages = {} # pkgname : PacmanPackage @@ -143,7 +146,17 @@ def splitprov(prov): return (name,version) def vercmp(v1,mod,v2): - res = alpm.vercmp(v1,v2) + """ + >>> vercmp("1.0", "<=", "2.0") + True + >>> vercmp("1:1.0", ">", "2.0") + True + >>> vercmp("1.0.2", ">=", "2.1.0") + False + """ + s1 = ctypes.c_char_p(v1) + s2 = ctypes.c_char_p(v2) + res = _alpm.alpm_pkg_vercmp(s1,s2) if res == 0: return (mod.find("=") > -1) elif res < 0: diff --git a/cron-jobs/check_archlinux/setup.py b/cron-jobs/check_archlinux/setup.py deleted file mode 100644 index b172752..0000000 --- a/cron-jobs/check_archlinux/setup.py +++ /dev/null @@ -1,10 +0,0 @@ -from distutils.core import setup, Extension - -alpm = Extension('alpm', - libraries = ['alpm'], - sources = ['alpm.c']) - -setup (name = 'Alpm', - version = '1.0', - description = 'Alpm bindings', - ext_modules = [alpm]) -- cgit v1.2.3-24-g4f1b