summaryrefslogtreecommitdiffstats
path: root/python/apt_instmodule.cc
blob: eb0107471d80dbfc79d8e6e9389423b44f44dfbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: apt_instmodule.cc,v 1.3 2002/01/08 06:53:04 jgg Exp $
/* ######################################################################

   apt_intmodule - Top level for the python module. Create the internal
                   structures for the module in the interpriter.

   Note, this module shares state (particularly global config) with the
   apt_pkg module.

   ##################################################################### */
									/*}}}*/
// Include Files							/*{{{*/
#include "apt_instmodule.h"
#include "generic.h"

#include <apt-pkg/debfile.h>
#include <apt-pkg/error.h>

#include <sys/stat.h>
#include <unistd.h>
#include <Python.h>
									/*}}}*/

PyObject *PyAptError;
PyObject *PyAptWarning;
static PyMethodDef *methods = 0;


static const char *apt_inst_doc =
    "Functions for working with ar/tar archives and .deb packages.\n\n"
    "This module provides useful classes and functions to work with\n"
    "archives, modelled after the 'TarFile' class in the 'tarfile' module.";
#define ADDTYPE(mod,name,type) { \
    if (PyType_Ready(type) == -1) RETURN(0); \
    Py_INCREF(type); \
    PyModule_AddObject(mod,name,(PyObject *)type); }


#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
        PyModuleDef_HEAD_INIT,
        "apt_inst",
        apt_inst_doc,
        -1,
        methods,
        0,
        0,
        0,
        0
};
#define RETURN(x) return x
#define INIT_ERROR return 0
extern "C" PyObject * PyInit_apt_inst()
#else
#define INIT_ERROR return
extern "C" void initapt_inst()
#define RETURN(x) return
#endif
{
#if PY_MAJOR_VERSION >= 3
   PyObject *module = PyModule_Create(&moduledef);
#else
   PyObject *module = Py_InitModule3("apt_inst",methods, apt_inst_doc);
#endif

   PyObject *apt_pkg = PyImport_ImportModule("apt_pkg");
   if (apt_pkg == NULL)
      INIT_ERROR;
   PyAptError = PyObject_GetAttrString(apt_pkg, "Error");
   if (PyAptError == NULL)
      INIT_ERROR;
   PyAptWarning = PyObject_GetAttrString(apt_pkg, "Warning");
   if (PyAptWarning == NULL)
      INIT_ERROR;

   PyModule_AddObject(module,"Error",PyAptError);
   PyModule_AddObject(module,"Warning",PyAptWarning);
   ADDTYPE(module,"ArMember",&PyArMember_Type);
   ADDTYPE(module,"ArArchive",&PyArArchive_Type);
   ADDTYPE(module,"DebFile",&PyDebFile_Type);
   ADDTYPE(module,"TarFile",&PyTarFile_Type);
   ADDTYPE(module,"TarMember",&PyTarMember_Type);
   ADDTYPE(module,"__FileFd",&PyFileFd_Type);
   RETURN(module);
}