summaryrefslogtreecommitdiff
path: root/python/cdrom.cc
blob: bd181af7d48486e119c8ef6fa0b4776626ad776d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Description								/*{{{*/
// $Id: cdrom.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $
/* ######################################################################

   Cdrom - Wrapper for the apt-cdrom support

   ##################################################################### */

#include "generic.h"
#include "apt_pkgmodule.h"
#include "progress.h"

#include <apt-pkg/cdrom.h>

static PyObject *PkgCdromAdd(PyObject *Self,PyObject *Args)
{
   pkgCdrom &Cdrom = GetCpp<pkgCdrom>(Self);

   PyObject *pyCdromProgressInst = 0;
   if (PyArg_ParseTuple(Args, "O", &pyCdromProgressInst) == 0) {
      return 0;
   }

   PyCdromProgress progress;
   progress.setCallbackInst(pyCdromProgressInst);

   bool res = Cdrom.Add(&progress);

   return HandleErrors(Py_BuildValue("b", res));
}

static PyObject *PkgCdromIdent(PyObject *Self,PyObject *Args)
{
   pkgCdrom &Cdrom = GetCpp<pkgCdrom>(Self);
   PyObject *pyCdromProgressInst = 0;
   if (PyArg_ParseTuple(Args, "O!", &PyCdromProgress_Type,
                        &pyCdromProgressInst) == 0) {
      return 0;
   }

   PyCdromProgress progress;
   progress.setCallbackInst(pyCdromProgressInst);

   string ident;
   bool res = Cdrom.Ident(ident, &progress);

   if (res)
       return CppPyString(ident);
   else {
       Py_INCREF(Py_None);
       return HandleErrors(Py_None);
   }
}

#ifdef COMPAT_0_7
static PyObject *PkgCdromIdent_old(PyObject *Self,PyObject *Args)
{
   pkgCdrom &Cdrom = GetCpp<pkgCdrom>(Self);

   PyObject *pyCdromProgressInst = 0;
   if (PyArg_ParseTuple(Args, "O", &pyCdromProgressInst) == 0) {
      return 0;
   }

   PyCdromProgress progress;
   progress.setCallbackInst(pyCdromProgressInst);

   string ident;
   bool res = Cdrom.Ident(ident, &progress);

   PyObject *result = Py_BuildValue("(bs)", res, ident.c_str());

   return HandleErrors(result);
}
#endif


static PyMethodDef PkgCdromMethods[] =
{
   {"add",PkgCdromAdd,METH_VARARGS,"add(progress) -> Add a cdrom"},
   {"ident",PkgCdromIdent,METH_VARARGS,"ident(progress) -> Ident a cdrom"},
#ifdef COMPAT_0_7
   {"Add",PkgCdromAdd,METH_VARARGS,"Add(progress) -> Add a cdrom"},
   {"Ident",PkgCdromIdent_old,METH_VARARGS,"Ident(progress) -> Ident a cdrom"},
#endif
   {}
};


static PyObject *PkgCdromNew(PyTypeObject *type,PyObject *Args,PyObject *kwds)
{
   pkgCdrom *cdrom = new pkgCdrom();

   char *kwlist[] = {NULL};
   if (PyArg_ParseTupleAndKeywords(Args,kwds,"",kwlist) == 0)
      return 0;

   CppOwnedPyObject<pkgCdrom> *CdromObj =
	   CppOwnedPyObject_NEW<pkgCdrom>(0,type, *cdrom);

   return CdromObj;
}


PyTypeObject PyCdrom_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.Cdrom",                     // tp_name
   sizeof(CppOwnedPyObject<pkgCdrom>),   // tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   CppOwnedDealloc<pkgCdrom>,     // tp_dealloc
   0,                                   // tp_print
   0,                                   // tp_getattr
   0,                                   // tp_setattr
   0,                                   // tp_compare
   0,                                   // tp_repr
   0,                                   // tp_as_number
   0,                                   // tp_as_sequence
   0,	                                // tp_as_mapping
   0,                                   // tp_hash
   0,                                   // tp_call
   0,                                   // tp_str
   0,                                   // tp_getattro
   0,                                   // tp_setattro
   0,                                   // tp_as_buffer
   (Py_TPFLAGS_DEFAULT |                // tp_flags
    Py_TPFLAGS_BASETYPE),
   "Cdrom Object",                      // tp_doc
   0,                                   // tp_traverse
   0,                                   // tp_clear
   0,                                   // tp_richcompare
   0,                                   // tp_weaklistoffset
   0,                                   // tp_iter
   0,                                   // tp_iternext
   PkgCdromMethods,                     // tp_methods
   0,                                   // tp_members
   0,                                   // tp_getset
   0,                                   // tp_base
   0,                                   // tp_dict
   0,                                   // tp_descr_get
   0,                                   // tp_descr_set
   0,                                   // tp_dictoffset
   0,                                   // tp_init
   0,                                   // tp_alloc
   PkgCdromNew,                         // tp_new
};

#ifdef COMPAT_0_7
PyObject *GetCdrom(PyObject *Self,PyObject *Args)
{
   PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCdrom() is deprecated. "
                 "Please see apt_pkg.Cdrom() for the replacement.", 1);
   return PkgCdromNew(&PyCdrom_Type,Args,0);
}
#endif




									/*}}}*/