]> git.ipfire.org Git - pakfire.git/blame - src/_pakfire/util.c
Use autotools.
[pakfire.git] / src / _pakfire / util.c
CommitLineData
b792d887
MT
1/*#############################################################################
2# #
3# Pakfire - The IPFire package management system #
4# Copyright (C) 2011 Pakfire development team #
5# #
6# This program is free software: you can redistribute it and/or modify #
7# it under the terms of the GNU General Public License as published by #
8# the Free Software Foundation, either version 3 of the License, or #
9# (at your option) any later version. #
10# #
11# This program is distributed in the hope that it will be useful, #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14# GNU General Public License for more details. #
15# #
16# You should have received a copy of the GNU General Public License #
17# along with this program. If not, see <http://www.gnu.org/licenses/>. #
18# #
19#############################################################################*/
102c5ee7
MT
20
21#include <Python.h>
22
392371f7
MT
23#include <errno.h>
24#include <sched.h>
ed4a9455 25#include <sys/personality.h>
92aef532 26#include <unistd.h>
ed4a9455 27
b55979b4 28#include "constants.h"
102c5ee7
MT
29#include "util.h"
30
ed4a9455
MT
31PyObject *_personality(PyObject *self, PyObject *args) {
32 unsigned long persona;
33 int ret = 0;
34
35 if (!PyArg_ParseTuple(args, "l", &persona)) {
36 /* XXX raise exception */
37 return NULL;
38 }
39
40 /* Change personality here. */
41 ret = personality(persona);
42
43 if (ret < 0) {
44 PyErr_SetString(PyExc_RuntimeError, "Could not set personality.");
45 return NULL;
46 }
47
48 return Py_BuildValue("i", ret);
49}
50
92aef532
MT
51PyObject *_sync(PyObject *self, PyObject *args) {
52 /* Just sync everything to disks. */
53 sync();
54
55 Py_RETURN_NONE;
56}
57
392371f7
MT
58PyObject *_unshare(PyObject *self, PyObject *args) {
59 int flags = 0;
60
61 if (!PyArg_ParseTuple(args, "i", &flags)) {
62 return NULL;
63 }
64
65 int ret = unshare(flags);
66 if (ret < 0) {
67 return PyErr_SetFromErrno(PyExc_RuntimeError);
68 }
69
70 return Py_BuildValue("i", ret);
71}
72
102c5ee7
MT
73PyObject *version_compare(PyObject *self, PyObject *args) {
74 Pool *pool;
75 const char *evr1, *evr2;
76
77 if (!PyArg_ParseTuple(args, "Oss", &pool, &evr1, &evr2)) {
78 /* XXX raise exception */
79 return NULL;
80 }
81
82 int ret = pool_evrcmp_str(pool, evr1, evr2, EVRCMP_COMPARE);
83
84 return Py_BuildValue("i", ret);
85}