summaryrefslogtreecommitdiff
path: root/python/acquire.cc
blob: 25b10b06c81cedaefdf4587acb764fbc8bd38315 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
// Description								/*{{{*/
// $Id: acquire.cc,v 1.1 2003/06/03 03:03:23 mvo Exp $
/* ######################################################################

   Acquire - Wrapper for the acquire code

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

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

#include <apt-pkg/acquire-item.h>
#include <apt-pkg/acquire-worker.h>

typedef CppPyObject<pkgAcquire::Item*> PyAcquireItemObject;

// Keep a vector to PyAcquireItemObject pointers, so we can set the Object
// pointers to NULL when deallocating the main object (mostly AcquireFile).
struct PyAcquireObject : public CppPyObject<pkgAcquire*> {
    vector<PyAcquireItemObject *> items;
};


static PyObject *acquireworker_get_current_item(PyObject *self, void *closure)
{
    return PyAcquireItemDesc_FromCpp((GetCpp<pkgAcquire::Worker*>(self)->CurrentItem),false,self);
}

static PyObject *acquireworker_get_status(PyObject *self, void *closure)
{
    return CppPyString(GetCpp<pkgAcquire::Worker*>(self)->Status);
}

static PyObject *acquireworker_get_current_size(PyObject *self, void *closure)
{
    return Py_BuildValue("k",GetCpp<pkgAcquire::Worker*>(self)->CurrentSize);
}

static PyObject *acquireworker_get_total_size(PyObject *self, void *closure)
{
    return Py_BuildValue("k",GetCpp<pkgAcquire::Worker*>(self)->TotalSize);
}

static PyObject *acquireworker_get_resumepoint(PyObject *self, void *closure)
{
    return Py_BuildValue("k",GetCpp<pkgAcquire::Worker*>(self)->ResumePoint);
}

static PyGetSetDef acquireworker_getset[] = {
    {"current_item",acquireworker_get_current_item},
    {"status",acquireworker_get_status},
    {"current_size",acquireworker_get_current_size},
    {"total_size",acquireworker_get_total_size},
    {"resumepoint",acquireworker_get_resumepoint},
    {NULL}
};


PyTypeObject PyAcquireWorker_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.AcquireWorker",                // tp_name
   sizeof(CppOwnedPyObject<pkgAcquire::Worker*>),// tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   CppOwnedDealloc<pkgAcquire::Worker*>, // 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_HAVE_GC,
   0,                 // tp_doc
   CppOwnedTraverse<pkgAcquire::Worker*>, // tp_traverse
   CppOwnedClear<pkgAcquire::Worker*>,    // tp_clear
   0,                                    // tp_richcompare
   0,                                    // tp_weaklistoffset
   0,                                    // tp_iter
   0,                                    // tp_iternext
   0,                                    // tp_methods
   0,                                    // tp_members
   acquireworker_getset,                 // tp_getset
};

static PyObject *acquireitemdesc_get_uri(PyObject *self, void *closure)
{
    return CppPyString(GetCpp<pkgAcquire::ItemDesc*>(self)->URI);
}
static PyObject *acquireitemdesc_get_description(PyObject *self, void *closure)
{
    return CppPyString(GetCpp<pkgAcquire::ItemDesc*>(self)->Description);
}
static PyObject *acquireitemdesc_get_shortdesc(PyObject *self, void *closure)
{
    return CppPyString(GetCpp<pkgAcquire::ItemDesc*>(self)->ShortDesc);
}
static PyObject *acquireitemdesc_get_owner(PyObject *self, void *closure)
{
    return GetOwner<pkgAcquire::ItemDesc*>(self);
}

static PyGetSetDef acquireitemdesc_getset[] = {
   {"uri",acquireitemdesc_get_uri,0,"The URI from which to download this item."},
   {"description",acquireitemdesc_get_description},
   {"shortdesc",acquireitemdesc_get_shortdesc},
   {"owner",acquireitemdesc_get_owner},
   {NULL}
};

static char *acquireitemdesc_doc =
    "Represent an AcquireItemDesc";

PyTypeObject PyAcquireItemDesc_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.AcquireItemDesc",                // tp_name
   sizeof(CppOwnedPyObject<pkgAcquire::ItemDesc*>),// tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   CppOwnedDealloc<pkgAcquire::ItemDesc*>, // 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_HAVE_GC),
   acquireitemdesc_doc,                 // tp_doc
   CppOwnedTraverse<pkgAcquire::ItemDesc*>,// tp_traverse
   CppOwnedClear<pkgAcquire::ItemDesc*>, // tp_clear
   0,                                   // tp_richcompare
   0,                                   // tp_weaklistoffset
   0,                                   // tp_iter
   0,                                   // tp_iternext
   0,                                   // tp_methods
   0,                                   // tp_members
   acquireitemdesc_getset,              // 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
   0,                                   // tp_new
};

inline pkgAcquire::Item *acquireitem_tocpp(PyObject *self) {
    pkgAcquire::Item *itm = GetCpp<pkgAcquire::Item*>(self);
    if (itm == 0)
        PyErr_SetString(PyExc_ValueError, "Acquire() has been shut down or "
                        "the AcquireFile() object has been deallocated.");
    return itm;
}

#define MkGet(PyFunc,Ret) static PyObject *PyFunc(PyObject *Self,void*) \
{ \
    pkgAcquire::Item *Itm = acquireitem_tocpp(Self); \
    if (Itm == 0) \
        return 0; \
    return Ret; \
}

// Define our getters
MkGet(AcquireItemGetComplete,Py_BuildValue("i",Itm->Complete));
MkGet(AcquireItemGetDescURI,Safe_FromString(Itm->DescURI().c_str()));
MkGet(AcquireItemGetDestFile,Safe_FromString(Itm->DestFile.c_str()));
MkGet(AcquireItemGetErrorText,Safe_FromString(Itm->ErrorText.c_str()));
MkGet(AcquireItemGetFileSize,Py_BuildValue("i",Itm->FileSize));
MkGet(AcquireItemGetID,Py_BuildValue("i",Itm));
MkGet(AcquireItemGetIsTrusted,Py_BuildValue("i",Itm->IsTrusted()));
MkGet(AcquireItemGetLocal,Py_BuildValue("i",Itm->Local));
MkGet(AcquireItemGetStatus,Py_BuildValue("i",Itm->Status));

// Constants
MkGet(AcquireItemGetStatIdle,Py_BuildValue("i", pkgAcquire::Item::StatIdle));
MkGet(AcquireItemGetStatFetching,Py_BuildValue("i", pkgAcquire::Item::StatFetching));
MkGet(AcquireItemGetStatDone,Py_BuildValue("i", pkgAcquire::Item::StatDone));
MkGet(AcquireItemGetStatError,Py_BuildValue("i", pkgAcquire::Item::StatError));
MkGet(AcquireItemGetStatAuthError,Py_BuildValue("i", pkgAcquire::Item::StatAuthError));
#undef MkGet

static PyGetSetDef AcquireItemGetSet[] = {
    {"complete",AcquireItemGetComplete},
    {"desc_uri",AcquireItemGetDescURI},
    {"destfile",AcquireItemGetDestFile},
    {"error_text",AcquireItemGetErrorText},
    {"filesize",AcquireItemGetFileSize},
    {"id",AcquireItemGetID},
    {"is_trusted",AcquireItemGetIsTrusted},
    {"local",AcquireItemGetLocal},
    {"status",AcquireItemGetStatus},
    {"stat_idle",AcquireItemGetStatIdle},
    {"stat_fetching",AcquireItemGetStatFetching},
    {"stat_done",AcquireItemGetStatDone},
    {"stat_error",AcquireItemGetStatError},
    {"stat_auth_error",AcquireItemGetStatAuthError},
#ifdef COMPAT_0_7
    {"Complete",AcquireItemGetComplete},
    {"DescURI",AcquireItemGetDescURI},
    {"DestFile",AcquireItemGetDestFile},
    {"ErrorText",AcquireItemGetErrorText},
    {"FileSize",AcquireItemGetFileSize},
    {"ID",AcquireItemGetID},
    {"IsTrusted",AcquireItemGetIsTrusted},
    {"Local",AcquireItemGetLocal},
    {"Status",AcquireItemGetStatus},
    {"StatIdle",AcquireItemGetStatIdle},
    {"StatFetching",AcquireItemGetStatFetching},
    {"StatDone",AcquireItemGetStatDone},
    {"StatError",AcquireItemGetStatError},
    {"StatAuthError",AcquireItemGetStatAuthError},
#endif
    {}
};



static PyObject *AcquireItemRepr(PyObject *Self)
{
   pkgAcquire::Item *Itm = acquireitem_tocpp(Self);
   if (Itm == 0)
      return 0;
   char S[300];
   snprintf(S,sizeof(S),"<%s object: "
			"Status: %i Complete: %i Local: %i IsTrusted: %i "
	                "FileSize: %lu DestFile:'%s' "
                        "DescURI: '%s' ID:%lu ErrorText: '%s'>",
        Self->ob_type->tp_name,
	    Itm->Status, Itm->Complete, Itm->Local, Itm->IsTrusted(),
	    Itm->FileSize, Itm->DestFile.c_str(), Itm->DescURI().c_str(),
	    Itm->ID,Itm->ErrorText.c_str());
   return PyString_FromString(S);
}

static void AcquireItemDealloc(PyObject *self) {
   pkgAcquire::Item *file = GetCpp<pkgAcquire::Item*>(self);
   PyAcquireObject *owner = (PyAcquireObject *)GetOwner<pkgAcquire::Item*>(self);

   // Simply deallocate the object if we have no owner.
   if (owner == NULL) {
       CppOwnedDeallocPtr<pkgAcquire::Item*>(self);
       return;
   }
   vector<PyAcquireItemObject *> &items = owner->items;
   bool DeletePtr = !((CppPyObject<pkgAcquire::Item*> *)self)->NoDelete;

   // Cleanup the other objects as well...
   for (vector<PyAcquireItemObject *>::iterator I = items.begin();
        I != items.end(); I++) {
      // If it is the current object, remove it from the vector.
      if ((*I) == self) {
        items.erase(I);
        I--; // erase() moved it one forward, move back
      }
      // If we delete the object below, set all other pointers to it to NULL,
      // and remove them from the vector.
      else if (DeletePtr && (*I)->Object == file) {
        if ((*I) != self)
            (*I)->Object = NULL;
        items.erase(I);
        I--; // erase() moved it one forward, move back
      }
   }
#ifdef ALLOC_DEBUG
   std::cerr << "ITEMS: " << items.size() << "\n";
#endif
   CppOwnedDeallocPtr<pkgAcquire::Item*>(self);
}



PyTypeObject PyAcquireItem_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.AcquireItem",         // tp_name
   sizeof(CppOwnedPyObject<pkgAcquire::Item*>),   // tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   AcquireItemDealloc,                  // tp_dealloc
   0,                                   // tp_print
   0,                                   // tp_getattr
   0,                                   // tp_setattr
   0,                                   // tp_compare
   AcquireItemRepr,                     // 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
   "AcquireItem Object",                // tp_doc
   0,                                   // tp_traverse
   0,                                   // tp_clear
   0,                                   // tp_richcompare
   0,                                   // tp_weaklistoffset
   0,                                   // tp_iter
   0,                                   // tp_iternext
   0,                                   // tp_methods
   0,                                   // tp_members
   AcquireItemGetSet,                   // tp_getset
};



static PyObject *PkgAcquireRun(PyObject *Self,PyObject *Args)
{
   pkgAcquire *fetcher = GetCpp<pkgAcquire*>(Self);

   int pulseInterval = 500000;
   if (PyArg_ParseTuple(Args, "|i", &pulseInterval) == 0)
      return 0;

   pkgAcquire::RunResult run = fetcher->Run(pulseInterval);

   return HandleErrors(Py_BuildValue("i",run));
}

static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args)
{
   pkgAcquire *fetcher = GetCpp<pkgAcquire*>(Self);

   if (PyArg_ParseTuple(Args, "") == 0)
      return 0;

   fetcher->Shutdown();

   vector<PyAcquireItemObject *> items = ((PyAcquireObject *)Self)->items;
   for (vector<PyAcquireItemObject *>::iterator I = items.begin();
        I != items.end(); I++)
        (*I)->Object = NULL;

   Py_INCREF(Py_None);
   return HandleErrors(Py_None);
}

static PyMethodDef PkgAcquireMethods[] =
{
   {"run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"},
   {"shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"},
   #ifdef COMPAT_0_7
   {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"},
   {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"},
   #endif
   {}
};

#define fetcher (GetCpp<pkgAcquire*>(Self))
static PyObject *PkgAcquireGetTotalNeeded(PyObject *Self,void*) {
   return Py_BuildValue("d", fetcher->TotalNeeded());
}
static PyObject *PkgAcquireGetFetchNeeded(PyObject *Self,void*) {
   return Py_BuildValue("d", fetcher->FetchNeeded());
}
static PyObject *PkgAcquireGetPartialPresent(PyObject *Self,void*) {
      return Py_BuildValue("d", fetcher->PartialPresent());
}
#undef fetcher

static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure)
{
    PyObject *List = PyList_New(0);
    pkgAcquire *Owner = GetCpp<pkgAcquire*>(self);
    CppOwnedPyObject<pkgAcquire::Worker*> *PyWorker = NULL;
    for(pkgAcquire::Worker *Worker = Owner->WorkersBegin();
        Worker != 0; Worker = Owner->WorkerStep(Worker)) {
        PyWorker = CppOwnedPyObject_NEW<pkgAcquire::Worker*>(self,&PyAcquireWorker_Type, Worker);
        PyWorker->NoDelete = true;
        PyList_Append(List, PyWorker);
    }
    return List;
}
static PyObject *PkgAcquireGetItems(PyObject *Self,void*)
{
   pkgAcquire *fetcher = GetCpp<pkgAcquire*>(Self);
   PyObject *List = PyList_New(0);
   for (pkgAcquire::ItemIterator I = fetcher->ItemsBegin();
        I != fetcher->ItemsEnd(); I++)
   {
      PyAcquireItemObject *Obj;
      Obj = CppOwnedPyObject_NEW<pkgAcquire::Item*>(Self,&PyAcquireItem_Type,*I);
      Obj->NoDelete = true;
      PyList_Append(List,Obj);
      ((PyAcquireObject *)Self)->items.push_back(Obj);
      Py_DECREF(Obj);
   }
   return List;
}
// some constants
static PyObject *PkgAcquireGetResultContinue(PyObject *Self,void*) {
      return Py_BuildValue("i", pkgAcquire::Continue);
}
static PyObject *PkgAcquireGetResultFailed(PyObject *Self,void*) {
      return Py_BuildValue("i", pkgAcquire::Failed);
}
static PyObject *PkgAcquireGetResultCancelled(PyObject *Self,void*) {
      return Py_BuildValue("i", pkgAcquire::Cancelled);
}

static PyGetSetDef PkgAcquireGetSet[] = {
    {"fetch_needed",PkgAcquireGetFetchNeeded},
    {"items",PkgAcquireGetItems},
    {"workers",PkgAcquireGetWorkers},
    {"partial_present",PkgAcquireGetPartialPresent},
    {"result_cancelled",PkgAcquireGetResultCancelled},
    {"result_continue",PkgAcquireGetResultContinue},
    {"result_failed",PkgAcquireGetResultFailed},
    {"total_needed",PkgAcquireGetTotalNeeded},
    #ifdef COMPAT_0_7
    {"FetchNeeded",PkgAcquireGetFetchNeeded},
    {"Items",PkgAcquireGetItems},
    {"PartialPresent",PkgAcquireGetPartialPresent},
    {"ResultCancelled",PkgAcquireGetResultCancelled},
    {"ResultContinue",PkgAcquireGetResultContinue},
    {"ResultFailed",PkgAcquireGetResultFailed},
    {"TotalNeeded",PkgAcquireGetTotalNeeded},
    #endif
    {}
};

static PyObject *PkgAcquireNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) {
   pkgAcquire *fetcher;

   PyObject *pyFetchProgressInst = NULL;
   char *kwlist[] = {"progress", 0};
   if (PyArg_ParseTupleAndKeywords(Args,kwds,"|O",kwlist,&pyFetchProgressInst) == 0)
      return 0;

   if (pyFetchProgressInst != NULL) {
      // FIXME: memleak?
      PyFetchProgress *progress = new PyFetchProgress();
      progress->setCallbackInst(pyFetchProgressInst);
      fetcher = new pkgAcquire(progress);
   } else {
      fetcher = new pkgAcquire();
   }

   CppPyObject<pkgAcquire*> *FetcherObj =
	   CppPyObject_NEW<pkgAcquire*>(type, fetcher);

   return FetcherObj;
}

static char *doc_PkgAcquire = "Acquire(progress) -> Acquire() object.\n\n"
    "Create a new acquire object. The parameter *progress* can be used to\n"
    "specify a apt.progress.FetchProgress() object, which will display the\n"
    "progress of the fetching.";

PyTypeObject PyAcquire_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.Acquire",                   // tp_name
   sizeof(PyAcquireObject),             // tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   CppDeallocPtr<pkgAcquire*>,          // 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),
   doc_PkgAcquire,                      // tp_doc
   0,                                   // tp_traverse
   0,                                   // tp_clear
   0,                                   // tp_richcompare
   0,                                   // tp_weaklistoffset
   0,                                   // tp_iter
   0,                                   // tp_iternext
   PkgAcquireMethods,                   // tp_methods
   0,                                   // tp_members
   PkgAcquireGetSet,                    // 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
   PkgAcquireNew,                       // tp_new
};

#ifdef COMPAT_0_7
PyObject *GetAcquire(PyObject *Self,PyObject *Args)
{
    PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetAcquire() is deprecated."
                 " Please see apt_pkg.Acquire() for the replacement.", 1);
    return PkgAcquireNew(&PyAcquire_Type,Args,0);
}
#endif

static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject * kwds)
{
   PyObject *pyfetcher;
   char *uri, *md5, *descr, *shortDescr, *destDir, *destFile;
   int size = 0;
   uri = md5 = descr = shortDescr = destDir = destFile = "";

   char * kwlist[] = {"owner","uri", "md5", "size", "descr", "short_descr",
                      "destdir", "destfile", NULL};

   if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist,
				   &PyAcquire_Type, &pyfetcher, &uri, &md5,
				   &size, &descr, &shortDescr, &destDir, &destFile) == 0)
      return 0;

   pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyfetcher);
   pkgAcqFile *af = new pkgAcqFile(fetcher,  // owner
				   uri, // uri
				   md5,  // md5
				   size,   // size
				   descr, // descr
				   shortDescr,
				   destDir,
				   destFile); // short-desc
   CppOwnedPyObject<pkgAcqFile*> *AcqFileObj = CppOwnedPyObject_NEW<pkgAcqFile*>(pyfetcher, type);
   AcqFileObj->Object = af;
   ((PyAcquireObject *)pyfetcher)->items.push_back((PyAcquireItemObject *)AcqFileObj);


   return AcqFileObj;
}


static char *doc_PkgAcquireFile =
    "AcquireFile(owner, uri[, md5, size, descr, short_descr, destdir,"
    "destfile]) -> New AcquireFile() object\n\n"
    "The parameter *owner* refers to an apt_pkg.Acquire() object. You can use\n"
    "*destdir* OR *destfile* to specify the destination directory/file.";

PyTypeObject PyAcquireFile_Type =
{
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
   "apt_pkg.AcquireFile",                // tp_name
   sizeof(CppOwnedPyObject<pkgAcqFile*>),// tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   AcquireItemDealloc,                  // 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 |
    Py_TPFLAGS_HAVE_GC),
   doc_PkgAcquireFile,                  // tp_doc
   CppOwnedTraverse<pkgAcqFile*>,       // tp_traverse
   CppOwnedClear<pkgAcqFile*>,          // tp_clear
   0,                                   // tp_richcompare
   0,                                   // tp_weaklistoffset
   0,                                   // tp_iter
   0,                                   // tp_iternext
   0,                                   // tp_methods
   0,                                   // tp_members
   0,                   // tp_getset
   &PyAcquireItem_Type,                    // tp_base
   0,                                   // tp_dict
   0,                                   // tp_descr_get
   0,                                   // tp_descr_set
   0,                                   // tp_dictoffset
   0,                                   // tp_init
   0,                                   // tp_alloc
   PkgAcquireFileNew,                   // tp_new
};

#ifdef COMPAT_0_7
char *doc_GetPkgAcqFile =
"GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n";
PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds)
{
   PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is "
                "deprecated. Please see apt_pkg.AcquireFile() for the "
                "replacement", 1);
   PyObject *pyfetcher;
   char *uri, *md5, *descr, *shortDescr, *destDir, *destFile;
   int size = 0;
   uri = md5 = descr = shortDescr = destDir = destFile = "";

   char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr",
                      "destDir", "destFile", NULL};

   if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist,
				   &PyAcquire_Type, &pyfetcher, &uri, &md5,
				   &size, &descr, &shortDescr, &destDir, &destFile) == 0)
      return 0;

   pkgAcquire *fetcher = GetCpp<pkgAcquire*>(pyfetcher);
   pkgAcqFile *af = new pkgAcqFile(fetcher,  // owner
				   uri, // uri
				   md5,  // md5
				   size,   // size
				   descr, // descr
				   shortDescr,
				   destDir,
				   destFile); // short-desc
   CppPyObject<pkgAcqFile*> *AcqFileObj =   CppPyObject_NEW<pkgAcqFile*>(&PyAcquireFile_Type);
   AcqFileObj->Object = af;
   AcqFileObj->NoDelete = true;

   return AcqFileObj;
}
#endif