1 |
|
|
/** |
2 |
|
|
* pyalpm - a Python C module wrapping libalpm |
3 |
|
|
* |
4 |
|
|
* Copyright 2008 Imanol Celaya <ilcra1989@gmail.com> |
5 |
|
|
* Copyright (c) 2011 Rémy Oudompheng <remy@archlinux.org> |
6 |
|
|
* |
7 |
|
|
* pyalpm is free software: you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* pyalpm is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with pyalpm. If not, see <http://www.gnu.org/licenses/>. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "pyalpm.h" |
22 |
|
|
#include "util.h" |
23 |
|
|
#include "package.h" |
24 |
|
|
#include "db.h" |
25 |
|
|
|
26 |
|
3 |
static PyObject * alpmversion_alpm(PyObject *self, PyObject *dummy) |
27 |
|
|
{ |
28 |
|
3 |
const char *str; |
29 |
|
3 |
str = alpm_version(); |
30 |
|
|
|
31 |
|
3 |
return Py_BuildValue("s", str); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
3 |
static PyObject * version_alpm(PyObject *self, PyObject *dummy) |
35 |
|
|
{ |
36 |
|
3 |
return Py_BuildValue("s", VERSION); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
/** Finds a package satisfying a dependency constraint in a package list */ |
40 |
|
12 |
static PyObject* pyalpm_find_satisfier(PyObject *self, PyObject* args) { |
41 |
|
12 |
PyObject *pkglist; |
42 |
|
12 |
char *depspec; |
43 |
|
12 |
alpm_list_t *alpm_pkglist; |
44 |
|
12 |
alpm_pkg_t *p; |
45 |
|
|
|
46 |
✓✓ |
12 |
if(!PyArg_ParseTuple(args, "Os", &pkglist, &depspec)) |
47 |
|
|
{ |
48 |
|
3 |
PyErr_SetString(PyExc_TypeError, "find_satisfier() takes a Package list and a string"); |
49 |
|
3 |
return NULL; |
50 |
|
|
} |
51 |
|
|
|
52 |
✓✓ |
9 |
if(pylist_pkg_to_alpmlist(pkglist, &alpm_pkglist) == -1) |
53 |
|
|
return NULL; |
54 |
|
|
|
55 |
|
6 |
p = alpm_find_satisfier(alpm_pkglist, depspec); |
56 |
|
6 |
alpm_list_free(alpm_pkglist); |
57 |
|
|
|
58 |
✓✓ |
6 |
if (p == NULL) { |
59 |
|
3 |
Py_RETURN_NONE; |
60 |
|
|
} else { |
61 |
|
3 |
PyObject *result; |
62 |
|
3 |
result = pyalpm_package_from_pmpkg(p); |
63 |
✓✗ |
3 |
if (result == NULL) { |
64 |
|
|
return NULL; |
65 |
|
|
} else { |
66 |
|
3 |
return result; |
67 |
|
|
} |
68 |
|
|
} |
69 |
|
|
} |
70 |
|
|
|
71 |
|
18 |
static PyObject *pyalpm_vercmp(PyObject *self, PyObject *args) { |
72 |
|
18 |
const char *x, *y; |
73 |
|
18 |
int result; |
74 |
✓✗ |
18 |
if (!PyArg_ParseTuple(args, "ss", &x, &y)) |
75 |
|
|
return NULL; |
76 |
|
18 |
result = alpm_pkg_vercmp(x, y); |
77 |
|
18 |
return PyLong_FromLong(result); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
static PyMethodDef methods[] = { |
81 |
|
|
{"version", version_alpm, METH_NOARGS, "returns pyalpm version."}, |
82 |
|
|
{"alpmversion", alpmversion_alpm, METH_NOARGS, "returns alpm version."}, |
83 |
|
|
{"vercmp", pyalpm_vercmp, METH_VARARGS, "compares version strings"}, |
84 |
|
|
|
85 |
|
|
{ "find_satisfier", pyalpm_find_satisfier, METH_VARARGS, |
86 |
|
|
"finds a package satisfying the given dependency among a list\n" |
87 |
|
|
"args: a list of packages, a dependency string\n" |
88 |
|
|
"returns: a Package object or None" }, |
89 |
|
|
|
90 |
|
|
{"sync_newversion", pyalpm_sync_get_new_version, METH_VARARGS, |
91 |
|
|
"finds an available upgrade for a package in a list of databases\n" |
92 |
|
|
"args: a package, a list of databases\n" |
93 |
|
|
"returns: an upgrade candidate or None" }, |
94 |
|
|
|
95 |
|
|
/* from db.c */ |
96 |
|
|
{"find_grp_pkgs", pyalpm_find_grp_pkgs, METH_VARARGS, |
97 |
|
|
"find packages from a given group across databases\n" |
98 |
|
|
"args: a list of databases, a group name"}, |
99 |
|
|
|
100 |
|
|
{NULL, NULL, 0, NULL} |
101 |
|
|
}; |
102 |
|
|
|
103 |
|
|
static int pyalpm_clear(PyObject *m) |
104 |
|
|
{ |
105 |
|
|
PyObject *dict = PyModule_GetDict(m); |
106 |
|
|
if (dict == NULL) { |
107 |
|
|
return 0; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
PyObject *error = PyDict_GetItemString(dict, "error"); |
111 |
|
|
if (error == NULL) { |
112 |
|
|
return 0; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
Py_DECREF(error); |
116 |
|
|
|
117 |
|
|
return 0; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
static struct PyModuleDef pyalpm_def = { |
121 |
|
|
PyModuleDef_HEAD_INIT, |
122 |
|
|
"alpm", |
123 |
|
|
"This module wraps the libalpm library", |
124 |
|
|
-1, |
125 |
|
|
methods, |
126 |
|
|
NULL, NULL, |
127 |
|
|
pyalpm_clear, |
128 |
|
|
NULL, |
129 |
|
|
}; |
130 |
|
|
|
131 |
|
3 |
PyMODINIT_FUNC PyInit_pyalpm(void) |
132 |
|
|
{ |
133 |
|
3 |
PyObject* m = PyModule_Create(&pyalpm_def); |
134 |
|
|
|
135 |
|
3 |
init_pyalpm_error(m); |
136 |
|
3 |
init_pyalpm_handle(m); |
137 |
|
3 |
init_pyalpm_package(m); |
138 |
|
3 |
init_pyalpm_db(m); |
139 |
|
3 |
init_pyalpm_transaction(m); |
140 |
|
|
|
141 |
|
3 |
return m; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
/* vim: set ts=2 sw=2 et: */ |
145 |
|
|
|