File: indexfile.cc

package info (click to toggle)
python-apt 0.7.7.1%2Bnmu1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,276 kB
  • ctags: 930
  • sloc: cpp: 4,126; python: 3,108; makefile: 52
file content (92 lines) | stat: -rw-r--r-- 3,009 bytes parent folder | download
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
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
// $Id: indexfile.cc,v 1.2 2003/12/26 17:04:22 mdz Exp $
/* ######################################################################

   pkgIndexFile - Wrapper for the pkgIndexFilefunctions

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

#include <apt-pkg/indexfile.h>

#include <Python.h>

static PyObject *PackageIndexFileArchiveURI(PyObject *Self,PyObject *Args)
{   
   pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
   char *path;

   if (PyArg_ParseTuple(Args, "s",&path) == 0)
      return 0;

   return HandleErrors(Safe_FromString(File->ArchiveURI(path).c_str()));
}

static PyMethodDef PackageIndexFileMethods[] = 
{
   {"ArchiveURI",PackageIndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"},
   {}
};


static PyObject *PackageIndexFileAttr(PyObject *Self,char *Name)
{
   pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
   if (strcmp("Label",Name) == 0)
      return Safe_FromString(File->GetType()->Label);
   else if (strcmp("Describe",Name) == 0)
      return Safe_FromString(File->Describe().c_str());
   else if (strcmp("Exists",Name) == 0)
      return Py_BuildValue("i",(File->Exists()));
   else if (strcmp("HasPackages",Name) == 0)
      return Py_BuildValue("i",(File->HasPackages()));
   else if (strcmp("Size",Name) == 0)
      return Py_BuildValue("i",(File->Size()));
   else if (strcmp("IsTrusted",Name) == 0)
      return Py_BuildValue("i",(File->IsTrusted()));
   
   return Py_FindMethod(PackageIndexFileMethods,Self,Name);
}

static PyObject *PackageIndexFileRepr(PyObject *Self)
{
   pkgIndexFile *File = GetCpp<pkgIndexFile*>(Self);
   
   char S[1024];
   snprintf(S,sizeof(S),"<pkIndexFile object: "
			"Label:'%s' Describe='%s' Exists='%i' "
	                "HasPackages='%i' Size='%i'  "
 	                "IsTrusted='%i' ArchiveURI='%s'>",
	    File->GetType()->Label,  File->Describe().c_str(), File->Exists(), 
	    File->HasPackages(), File->Size(),
            File->IsTrusted(), File->ArchiveURI("").c_str());
   return PyString_FromString(S);
}

PyTypeObject PackageIndexFileType =
{
   PyObject_HEAD_INIT(&PyType_Type)
   0,			                // ob_size
   "pkgIndexFile",         // tp_name
   sizeof(CppOwnedPyObject<pkgIndexFile*>),   // tp_basicsize
   0,                                   // tp_itemsize
   // Methods
   CppOwnedDealloc<pkgIndexFile*>,          // tp_dealloc
   0,                                   // tp_print
   PackageIndexFileAttr,                     // tp_getattr
   0,                                   // tp_setattr
   0,                                   // tp_compare
   PackageIndexFileRepr,                     // tp_repr
   0,                                   // tp_as_number
   0,		                        // tp_as_sequence
   0,			                // tp_as_mapping
   0,                                   // tp_hash
};