1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2017 Pakfire development team #
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. #
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. #
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/>. #
19 #############################################################################*/
24 #include <pakfire/archive.h>
25 #include <pakfire/build.h>
26 #include <pakfire/constants.h>
27 #include <pakfire/dist.h>
28 #include <pakfire/execute.h>
29 #include <pakfire/logging.h>
30 #include <pakfire/packagelist.h>
31 #include <pakfire/pakfire.h>
32 #include <pakfire/key.h>
33 #include <pakfire/repo.h>
34 #include <pakfire/repolist.h>
35 #include <pakfire/request.h>
36 #include <pakfire/util.h>
45 static PyObject
* Pakfire_new(PyTypeObject
* type
, PyObject
* args
, PyObject
* kwds
) {
46 PakfireObject
* self
= (PakfireObject
*)type
->tp_alloc(type
, 0);
52 return (PyObject
*)self
;
55 static void Pakfire_logging_callback(void* data
, int priority
, const char* file
, int line
,
56 const char* fn
, const char* format
, va_list args
) {
57 PyObject
* callback
= (PyObject
*)data
;
59 // Do nothing if callback isn't set
63 // Translate priority to Python logging priorities
77 // Drop messages of an unknown priority
82 PyObject
* tuple
= NULL
;
83 PyObject
* result
= NULL
;
87 int r
= vasprintf(&buffer
, format
, args
);
91 // Build a tuple with the priority and the log message
92 tuple
= Py_BuildValue("(is)", priority
, buffer
);
97 result
= PyObject_CallObject(callback
, tuple
);
106 static int Pakfire_init(PakfireObject
* self
, PyObject
* args
, PyObject
* kwds
) {
107 char* kwlist
[] = { "path", "arch", "logger", "offline", "conf", "build",
108 "enable_ccache", "enable_snapshot", NULL
};
109 const char* path
= NULL
;
110 const char* arch
= NULL
;
111 const char* conf
= NULL
;
114 int enable_ccache
= 1;
115 int enable_snapshot
= 1;
117 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "|zzOpzppp", kwlist
,
118 &path
, &arch
, &self
->logger
, &offline
, &conf
, &build
,
119 &enable_ccache
, &enable_snapshot
))
122 // Check if logger is callable
123 if (self
->logger
&& !PyCallable_Check(self
->logger
)) {
124 PyErr_SetString(PyExc_TypeError
, "logger must be callable\n");
130 // Enable offline mode
132 flags
|= PAKFIRE_FLAGS_OFFLINE
;
136 flags
|= PAKFIRE_FLAGS_BUILD
;
139 flags
|= PAKFIRE_FLAGS_DISABLE_CCACHE
;
141 if (!enable_snapshot
)
142 flags
|= PAKFIRE_FLAGS_DISABLE_SNAPSHOT
;
145 // Create a new Pakfire instance
146 int r
= pakfire_create(&self
->pakfire
, path
, arch
, conf
, flags
,
147 (self
->logger
) ? Pakfire_logging_callback
: NULL
, self
->logger
);
150 // Invalid architecture or path
152 PyErr_SetString(PyExc_ValueError
, "Invalid architecture or path");
157 PyErr_SetFromErrno(PyExc_OSError
);
163 Py_XINCREF(self
->logger
);
168 static void Pakfire_dealloc(PakfireObject
* self
) {
170 pakfire_unref(self
->pakfire
);
173 Py_DECREF(self
->logger
);
175 Py_TYPE(self
)->tp_free((PyObject
*)self
);
178 static PyObject
* Pakfire_repr(PakfireObject
* self
) {
179 const char* path
= pakfire_get_path(self
->pakfire
);
180 const char* arch
= pakfire_get_arch(self
->pakfire
);
182 return PyUnicode_FromFormat("<_pakfire.Pakfire %s (%s)>", path
, arch
);
185 static PyObject
* Pakfire_get_path(PakfireObject
* self
) {
186 const char* path
= pakfire_get_path(self
->pakfire
);
188 return PyUnicode_FromString(path
);
191 static PyObject
* Pakfire_get_arch(PakfireObject
* self
) {
192 const char* arch
= pakfire_get_arch(self
->pakfire
);
194 return PyUnicode_FromString(arch
);
197 static PyObject
* Pakfire_get_repo(PakfireObject
* self
, PyObject
* args
) {
198 const char* name
= NULL
;
200 if (!PyArg_ParseTuple(args
, "s", &name
))
203 struct pakfire_repo
* repo
= pakfire_get_repo(self
->pakfire
, name
);
207 PyObject
* obj
= new_repo(&RepoType
, repo
);
208 pakfire_repo_unref(repo
);
213 static int convert_packages(PyObject
* object
, void* address
) {
214 char*** packages
= (char***)address
;
216 // Called for cleanup
220 if (!PySequence_Check(object
)) {
221 PyErr_SetString(PyExc_ValueError
, "Packages must be a sequence");
225 const unsigned int length
= PySequence_Length(object
);
227 return Py_CLEANUP_SUPPORTED
;
230 *packages
= calloc(length
+ 1, sizeof(*packages
));
232 PyErr_SetFromErrno(PyExc_OSError
);
236 for (unsigned int i
= 0; i
< length
; i
++) {
237 PyObject
* item
= PySequence_GetItem(object
, i
);
239 // Check if input is a string
240 if (!PyUnicode_Check(item
)) {
243 PyErr_SetString(PyExc_AttributeError
, "Expected a string");
248 const char* package
= PyUnicode_AsUTF8(item
);
254 // Add package to array
255 (*packages
)[i
] = strdup(package
);
256 if (!(*packages
)[i
]) {
265 return Py_CLEANUP_SUPPORTED
;
269 for (char** package
= *packages
; *package
; package
++)
277 static PyObject
* Pakfire_install(PakfireObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
280 "without_recommended",
285 char** packages
= NULL
;
286 int without_recommended
= 0;
287 int allow_uninstall
= 0;
288 int allow_downgrade
= 0;
289 int solver_flags
= 0;
291 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "O&|$ppp", kwlist
,
292 convert_packages
, &packages
, &without_recommended
, &allow_uninstall
,
296 // Do not install recommended packages
297 if (without_recommended
)
298 solver_flags
|= PAKFIRE_REQUEST_WITHOUT_RECOMMENDED
;
300 // Can the solver uninstall packages?
302 solver_flags
|= PAKFIRE_REQUEST_ALLOW_UNINSTALL
;
304 // Can the solver downgrade packages?
306 solver_flags
|= PAKFIRE_REQUEST_ALLOW_DOWNGRADE
;
308 // Run pakfire_install
309 int r
= pakfire_install(self
->pakfire
, solver_flags
, (const char**)packages
, NULL
, 0, NULL
);
311 PyErr_SetFromErrno(PyExc_OSError
);
314 for (char** package
= packages
; *package
; package
++)
325 static PyObject
* Pakfire_erase(PakfireObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
331 char** packages
= NULL
;
332 int keep_dependencies
= 0;
335 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "O&|$p", kwlist
,
336 convert_packages
, &packages
, &keep_dependencies
))
339 if (keep_dependencies
)
340 flags
|= PAKFIRE_REQUEST_KEEP_DEPS
;
343 int r
= pakfire_erase(self
->pakfire
, 0, (const char**)packages
, NULL
, flags
, NULL
);
345 PyErr_SetFromErrno(PyExc_OSError
);
348 for (char** package
= packages
; *package
; package
++)
359 static PyObject
* Pakfire_update(PakfireObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
367 char** packages
= NULL
;
368 char** excludes
= NULL
;
369 int allow_uninstall
= 0;
370 int allow_downgrade
= 0;
371 int solver_flags
= 0;
373 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "O&|$O&pp", kwlist
,
374 convert_packages
, &packages
, convert_packages
, &excludes
,
375 &allow_uninstall
, &allow_downgrade
))
378 // Can the solver uninstall packages?
380 solver_flags
|= PAKFIRE_REQUEST_ALLOW_UNINSTALL
;
382 // Can the solver downgrade packages?
384 solver_flags
|= PAKFIRE_REQUEST_ALLOW_DOWNGRADE
;
386 // Run pakfire_update
387 int r
= pakfire_update(self
->pakfire
, solver_flags
, (const char**)packages
,
388 (const char**)excludes
, 0, NULL
);
390 PyErr_SetFromErrno(PyExc_OSError
);
393 for (char** package
= packages
; *package
; package
++)
399 for (char** exclude
= excludes
; *exclude
; exclude
++)
410 static PyObject
* Pakfire_keys_to_list(struct pakfire_key
** keys
) {
411 PyObject
* list
= PyList_New(0);
417 // Push all keys onto the list
418 for (struct pakfire_key
** key
= keys
; *key
; key
++) {
419 PyObject
* object
= new_key(&KeyType
, *key
);
423 PyList_Append(list
, object
);
434 static PyObject
* Pakfire_get_keys(PakfireObject
* self
) {
435 struct pakfire_key
** keys
= NULL
;
437 int r
= pakfire_list_keys(self
->pakfire
, &keys
);
439 PyErr_SetFromErrno(PyExc_OSError
);
443 // Convert keys to list
444 PyObject
* list
= Pakfire_keys_to_list(keys
);
447 for (struct pakfire_key
** key
= keys
; *key
; key
++)
448 pakfire_key_unref(*key
);
454 static PyObject
* Pakfire_get_key(PakfireObject
* self
, PyObject
* args
) {
455 const char* pattern
= NULL
;
457 if (!PyArg_ParseTuple(args
, "s", &pattern
))
460 struct pakfire_key
* key
= pakfire_key_get(self
->pakfire
, pattern
);
464 return new_key(&KeyType
, key
);
467 static PyObject
* Pakfire_generate_key(PakfireObject
* self
, PyObject
* args
, PyObject
* kwds
) {
468 char* kwlist
[] = { "userid", "algorithm", NULL
};
469 struct pakfire_key
* key
= NULL
;
470 const char* userid
= NULL
;
471 const char* algo
= NULL
;
473 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "s|$z", kwlist
, &userid
, &algo
))
476 // Generate a new key
477 int r
= pakfire_key_generate(&key
, self
->pakfire
, algo
, userid
);
479 PyErr_SetFromErrno(PyExc_OSError
);
483 return new_key(&KeyType
, key
);
486 static PyObject
* Pakfire_import_key(PakfireObject
* self
, PyObject
* args
) {
487 PyObject
* object
= NULL
;
489 if (!PyArg_ParseTuple(args
, "O", &object
))
492 // Get a file descriptor from object
493 int fd
= PyObject_AsFileDescriptor(object
);
498 FILE* f
= fdopen(fd
, "r");
500 PyErr_SetFromErrno(PyExc_OSError
);
504 struct pakfire_key
** keys
= NULL
;
506 // Import keys from f
507 int r
= pakfire_key_import(self
->pakfire
, f
, &keys
);
509 PyErr_SetFromErrno(PyExc_OSError
);
513 // Convert keys to list
514 PyObject
* list
= Pakfire_keys_to_list(keys
);
517 for (struct pakfire_key
** key
= keys
; *key
; key
++)
518 pakfire_key_unref(*key
);
524 static PyObject
* Pakfire_fetch_key(PakfireObject
* self
, PyObject
* args
, PyObject
* kwds
) {
525 char* kwlist
[] = { "userid", "fingerprint", NULL
};
526 struct pakfire_key
* key
= NULL
;
527 const char* userid
= NULL
;
528 const char* fingerprint
= NULL
;
530 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "|$zz", kwlist
, &userid
, &fingerprint
))
534 int r
= pakfire_key_fetch(&key
, self
->pakfire
, userid
, fingerprint
);
536 PyErr_SetFromErrno(PyExc_OSError
);
542 return new_key(&KeyType
, key
);
547 static PyObject
* Pakfire_whatprovides(PakfireObject
* self
, PyObject
* args
) {
548 const char* provides
= NULL
;
549 struct pakfire_packagelist
* list
= NULL
;
551 if (!PyArg_ParseTuple(args
, "s", &provides
))
554 int r
= pakfire_whatprovides(self
->pakfire
, provides
, 0, &list
);
556 PyErr_SetFromErrno(PyExc_OSError
);
560 PyObject
* obj
= PyList_FromPackageList(list
);
561 pakfire_packagelist_unref(list
);
566 static PyObject
* Pakfire_whatrequires(PakfireObject
* self
, PyObject
* args
) {
567 const char* requires
= NULL
;
568 struct pakfire_packagelist
* list
= NULL
;
570 if (!PyArg_ParseTuple(args
, "s", &requires
))
573 int r
= pakfire_whatrequires(self
->pakfire
, requires
, 0, &list
);
575 PyErr_SetFromErrno(PyExc_OSError
);
579 PyObject
* obj
= PyList_FromPackageList(list
);
580 pakfire_packagelist_unref(list
);
585 static PyObject
* Pakfire_search(PakfireObject
* self
, PyObject
* args
, PyObject
* kwds
) {
586 char* kwlist
[] = { "pattern", "name_only", NULL
};
587 struct pakfire_packagelist
* list
= NULL
;
588 const char* pattern
= NULL
;
592 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "s|$p", kwlist
, &pattern
, &name_only
))
595 // Search for package names only
597 flags
|= PAKFIRE_SEARCH_NAME_ONLY
;
599 int r
= pakfire_search(self
->pakfire
, pattern
, flags
, &list
);
601 PyErr_SetFromErrno(PyExc_OSError
);
605 PyObject
* obj
= PyList_FromPackageList(list
);
606 pakfire_packagelist_unref(list
);
611 static PyObject
* Pakfire_version_compare(PakfireObject
* self
, PyObject
* args
) {
612 const char* evr1
= NULL
;
613 const char* evr2
= NULL
;
615 if (!PyArg_ParseTuple(args
, "ss", &evr1
, &evr2
))
618 int cmp
= pakfire_version_compare(self
->pakfire
, evr1
, evr2
);
620 return PyLong_FromLong(cmp
);
623 static PyObject
* Pakfire_execute_logging_callback
= NULL
;
625 static int __Pakfire_execute_logging_callback(Pakfire pakfire
, void* data
,
626 int priority
, const char* line
, size_t length
) {
629 // Do nothing if callback isn't set
630 if (!Pakfire_execute_logging_callback
)
633 // Translate priority to Python logging priorities
644 // Remove the trailing newline
645 if (line
&& line
[length
- 1] == '\n')
648 // Create tuple with arguments for the callback function
649 PyObject
* args
= Py_BuildValue("(is#)", priority
, line
, length
);
653 PyObject
* result
= PyObject_CallObject(Pakfire_execute_logging_callback
, args
);
654 if (result
&& PyLong_Check(result
)) {
655 r
= PyLong_AsLong(result
);
664 static PyObject
* Pakfire_execute(PakfireObject
* self
, PyObject
* args
, PyObject
* kwds
) {
665 char* kwlist
[] = {"command", "environ", "enable_network", "interactive",
666 "logging_callback", NULL
};
668 PyObject
* command
= NULL
;
669 PyObject
* environ
= NULL
;
670 int enable_network
= 0;
672 PyObject
* logging_callback
= NULL
;
674 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "O|OppO", kwlist
, &command
, &environ
,
675 &enable_network
, &interactive
, &logging_callback
))
678 // Check if command is a list
679 if (!PyList_Check(command
)) {
680 PyErr_SetString(PyExc_TypeError
, "command must be a list");
684 ssize_t command_length
= PyList_Size(command
);
686 // Check if command is not empty
687 if (command_length
== 0) {
688 PyErr_SetString(PyExc_ValueError
, "command is empty");
692 // All arguments in command must be strings
693 for (unsigned int i
= 0; i
< command_length
; i
++) {
694 PyObject
* item
= PyList_GET_ITEM(command
, i
);
696 if (!PyUnicode_Check(item
)) {
697 PyErr_Format(PyExc_TypeError
, "Item %u in command is not a string", i
);
702 // Check if logging_callback is
703 if (logging_callback
&& !PyCallable_Check(logging_callback
)) {
704 PyErr_SetString(PyExc_TypeError
, "logging_callback must be callable\n");
708 ssize_t environ_length
= 0;
714 // Check if environ is a dictionary
715 if (!PyDict_Check(environ
)) {
716 PyErr_SetString(PyExc_TypeError
, "environ must be a dictionary");
720 // All keys and values must be strings
721 while (PyDict_Next(environ
, &p
, &key
, &value
)) {
722 if (!PyUnicode_Check(key
) || !PyUnicode_Check(value
)) {
723 PyErr_SetString(PyExc_TypeError
, "Environment contains a non-string object");
728 environ_length
= PyDict_Size(environ
);
731 // All inputs look fine
733 const char* argv
[command_length
+ 1];
734 char* envp
[environ_length
+ 1];
738 for (unsigned int i
= 0; i
< command_length
; i
++) {
739 PyObject
* item
= PyList_GET_ITEM(command
, i
);
740 argv
[i
] = PyUnicode_AsUTF8(item
);
748 while (PyDict_Next(environ
, &p
, &key
, &value
)) {
749 int r
= asprintf(&envp
[i
++], "%s=%s",
750 PyUnicode_AsUTF8(key
), PyUnicode_AsUTF8(value
));
755 for (unsigned int i
= 0; envp
[i
]; i
++)
758 return PyErr_NoMemory();
763 // Terminate argv and envp
764 argv
[command_length
] = NULL
;
765 envp
[environ_length
] = NULL
;
769 flags
|= PAKFIRE_EXECUTE_ENABLE_NETWORK
;
773 flags
|= PAKFIRE_EXECUTE_INTERACTIVE
;
775 // Set logging callback
776 Pakfire_execute_logging_callback
= logging_callback
;
779 int r
= pakfire_execute(self
->pakfire
, argv
, envp
, flags
,
780 (logging_callback
) ? __Pakfire_execute_logging_callback
: NULL
, NULL
);
783 for (unsigned int i
= 0; envp
[i
]; i
++)
786 // Raise an OS error if r < 0
790 PyErr_SetFromErrno(PyExc_OSError
);
793 // Raise exception when the command failed
795 PyObject
* code
= PyLong_FromLong(r
);
797 PyErr_SetObject(PyExc_CommandExecutionError
, code
);
807 static PyObject
* Pakfire_dist(PakfireObject
* self
, PyObject
* args
) {
808 const char* path
= NULL
;
809 const char* target
= NULL
;
811 if (!PyArg_ParseTuple(args
, "s|z", &path
, &target
))
814 int r
= pakfire_dist(self
->pakfire
, path
, target
);
816 PyErr_SetFromErrno(PyExc_OSError
);
823 static PyObject
* Pakfire_bind(PakfireObject
* self
, PyObject
* args
) {
824 const char* src
= NULL
;
825 const char* dst
= NULL
;
827 if (!PyArg_ParseTuple(args
, "s|z", &src
, &dst
))
830 int r
= pakfire_bind(self
->pakfire
, src
, dst
, 0);
832 PyErr_SetFromErrno(PyExc_OSError
);
839 static PyObject
* Pakfire_copy_in(PakfireObject
* self
, PyObject
* args
) {
840 const char* src
= NULL
;
841 const char* dst
= NULL
;
843 if (!PyArg_ParseTuple(args
, "ss", &src
, &dst
))
846 int r
= pakfire_copy_in(self
->pakfire
, src
, dst
);
848 PyErr_SetFromErrno(PyExc_OSError
);
855 static PyObject
* Pakfire_copy_out(PakfireObject
* self
, PyObject
* args
) {
856 const char* src
= NULL
;
857 const char* dst
= NULL
;
859 if (!PyArg_ParseTuple(args
, "ss", &src
, &dst
))
862 int r
= pakfire_copy_out(self
->pakfire
, src
, dst
);
864 PyErr_SetFromErrno(PyExc_OSError
);
871 static PyObject
* Pakfire_get_repos(PakfireObject
* self
) {
872 struct pakfire_repolist
* repos
= pakfire_get_repos(self
->pakfire
);
874 PyErr_SetFromErrno(PyExc_OSError
);
878 const size_t l
= pakfire_repolist_size(repos
);
880 PyObject
* list
= PyList_New(l
);
884 for (unsigned int i
= 0; i
< l
; i
++) {
885 struct pakfire_repo
* repo
= pakfire_repolist_get(repos
, i
);
889 PyObject
* obj
= new_repo(&RepoType
, repo
);
890 PyList_SET_ITEM(list
, i
, obj
);
892 pakfire_repo_unref(repo
);
896 pakfire_repolist_unref(repos
);
901 static PyObject
* execute_return_value(int r
) {
902 // Raise an OS error if r < 0
906 PyErr_SetFromErrno(PyExc_OSError
);
909 // Raise exception when the command failed
911 PyObject
* code
= PyLong_FromLong(r
);
913 PyErr_SetObject(PyExc_CommandExecutionError
, code
);
922 static PyObject
* Pakfire_build(PakfireObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
923 char* kwlist
[] = { "path", "build_id", "logging_callback", "interactive", NULL
};
925 const char* path
= NULL
;
926 const char* build_id
= NULL
;
927 PyObject
* logging_callback
= NULL
;
930 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "s|zOp", kwlist
, &path
,
931 &build_id
, &logging_callback
, &interactive
))
936 // Enable interactive mode
938 flags
|= PAKFIRE_BUILD_INTERACTIVE
;
940 // Check if logging_callback is
941 if (logging_callback
&& !PyCallable_Check(logging_callback
)) {
942 PyErr_SetString(PyExc_TypeError
, "logging_callback must be callable\n");
946 // Set logging callback
947 Pakfire_execute_logging_callback
= logging_callback
;
950 int r
= pakfire_build(self
->pakfire
, path
, NULL
, build_id
, flags
,
951 (logging_callback
) ? __Pakfire_execute_logging_callback
: NULL
, NULL
);
953 return execute_return_value(r
);
956 static PyObject
* Pakfire_shell(PakfireObject
* self
) {
957 int r
= pakfire_shell(self
->pakfire
);
959 return execute_return_value(r
);
962 static PyObject
* Pakfire_clean(PakfireObject
* self
) {
963 int r
= pakfire_clean(self
->pakfire
, 0);
965 PyErr_SetFromErrno(PyExc_OSError
);
972 static PyObject
* Pakfire_refresh(PakfireObject
* self
, PyObject
* args
) {
975 if (!PyArg_ParseTuple(args
, "|p", &force
))
978 int r
= pakfire_refresh(self
->pakfire
, force
);
980 PyErr_SetFromErrno(PyExc_OSError
);
987 static PyObject
* Pakfire_check(PakfireObject
* self
) {
988 int r
= pakfire_check(self
->pakfire
);
990 PyErr_SetFromErrno(PyExc_OSError
);
997 static PyObject
* Pakfire_sync(PakfireObject
* self
, PyObject
* args
, PyObject
* kwargs
) {
998 char* kwlist
[] = {"keep_orphaned", NULL
};
999 int keep_orphaned
= 0;
1002 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|$p", kwlist
, &keep_orphaned
))
1006 flags
|= PAKFIRE_REQUEST_KEEP_ORPHANED
;
1008 int r
= pakfire_sync(self
->pakfire
, 0, flags
, NULL
);
1010 PyErr_SetFromErrno(PyExc_OSError
);
1017 static PyObject
* Pakfire_open(PakfireObject
* self
, PyObject
* args
) {
1018 struct pakfire_archive
* archive
= NULL
;
1019 const char* path
= NULL
;
1021 if (!PyArg_ParseTuple(args
, "s", &path
))
1024 int r
= pakfire_archive_open(&archive
, self
->pakfire
, path
);
1026 PyErr_SetFromErrno(PyExc_OSError
);
1030 // Create Python object
1031 PyObject
* object
= new_archive(&ArchiveType
, archive
);
1032 pakfire_archive_unref(archive
);
1037 static struct PyMethodDef Pakfire_methods
[] = {
1040 (PyCFunction
)Pakfire_bind
,
1046 (PyCFunction
)Pakfire_build
,
1047 METH_VARARGS
|METH_KEYWORDS
,
1052 (PyCFunction
)Pakfire_check
,
1058 (PyCFunction
)Pakfire_clean
,
1064 (PyCFunction
)Pakfire_copy_in
,
1070 (PyCFunction
)Pakfire_copy_out
,
1076 (PyCFunction
)Pakfire_dist
,
1082 (PyCFunction
)Pakfire_erase
,
1083 METH_VARARGS
|METH_KEYWORDS
,
1088 (PyCFunction
)Pakfire_execute
,
1089 METH_VARARGS
|METH_KEYWORDS
,
1094 (PyCFunction
)Pakfire_fetch_key
,
1095 METH_VARARGS
|METH_KEYWORDS
,
1100 (PyCFunction
)Pakfire_generate_key
,
1101 METH_VARARGS
|METH_KEYWORDS
,
1106 (PyCFunction
)Pakfire_get_key
,
1112 (PyCFunction
)Pakfire_get_repo
,
1118 (PyCFunction
)Pakfire_import_key
,
1124 (PyCFunction
)Pakfire_install
,
1125 METH_VARARGS
|METH_KEYWORDS
,
1130 (PyCFunction
)Pakfire_open
,
1136 (PyCFunction
)Pakfire_refresh
,
1142 (PyCFunction
)Pakfire_search
,
1143 METH_VARARGS
|METH_KEYWORDS
,
1148 (PyCFunction
)Pakfire_shell
,
1154 (PyCFunction
)Pakfire_sync
,
1155 METH_VARARGS
|METH_KEYWORDS
,
1160 (PyCFunction
)Pakfire_update
,
1161 METH_VARARGS
|METH_KEYWORDS
,
1166 (PyCFunction
)Pakfire_version_compare
,
1172 (PyCFunction
)Pakfire_whatprovides
,
1178 (PyCFunction
)Pakfire_whatrequires
,
1185 static struct PyGetSetDef Pakfire_getsetters
[] = {
1188 (getter
)Pakfire_get_arch
,
1195 (getter
)Pakfire_get_keys
,
1202 (getter
)Pakfire_get_path
,
1209 (getter
)Pakfire_get_repos
,
1217 PyTypeObject PakfireType
= {
1218 PyVarObject_HEAD_INIT(NULL
, 0)
1219 tp_name
: "_pakfire.Pakfire",
1220 tp_basicsize
: sizeof(PakfireObject
),
1221 tp_flags
: Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
,
1222 tp_new
: Pakfire_new
,
1223 tp_dealloc
: (destructor
)Pakfire_dealloc
,
1224 tp_init
: (initproc
)Pakfire_init
,
1225 tp_doc
: "Pakfire object",
1226 tp_methods
: Pakfire_methods
,
1227 tp_getset
: Pakfire_getsetters
,
1228 tp_repr
: (reprfunc
)Pakfire_repr
,