summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt/package.py9
-rw-r--r--debian/changelog6
-rw-r--r--debian/control4
-rw-r--r--doc/examples/desc.py25
-rw-r--r--python/cache.cc69
5 files changed, 110 insertions, 3 deletions
diff --git a/apt/package.py b/apt/package.py
index c870c325..0c451e4e 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -151,6 +151,9 @@ class Package(object):
""" Return the short description (one line summary) """
if not self._lookupRecord():
return ""
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ desc_iter = ver.TranslatedDescription
+ self._records.Lookup(desc_iter.FileList.pop(0))
return self._records.ShortDesc
summary = property(summary)
@@ -158,8 +161,12 @@ class Package(object):
""" Return the formated long description """
if not self._lookupRecord():
return ""
+ # get the translated description
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ desc_iter = ver.TranslatedDescription
+ self._records.Lookup(desc_iter.FileList.pop(0))
desc = ""
- for line in string.split(self._records.LongDesc, "\n"):
+ for line in string.split(unicode(self._records.LongDesc,"utf-8"),"\n"):
tmp = string.strip(line)
if tmp == ".":
desc += "\n"
diff --git a/debian/changelog b/debian/changelog
index 73adccba..603c06b7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+python-apt (0.6.19ubuntu3) edgy; urgency=low
+
+ * merged ddtp support
+
+ -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 14 Aug 2006 16:25:51 +0200
+
python-apt (0.6.19ubuntu2) edgy; urgency=low
* tightened build-deps on latest apt
diff --git a/debian/control b/debian/control
index e2f97b78..765c3914 100644
--- a/debian/control
+++ b/debian/control
@@ -3,9 +3,9 @@ Section: python
Priority: optional
Maintainer: APT Development Team <deity@lists.debian.org>
Uploaders: Matt Zimmerman <mdz@debian.org>, Michael Vogt <mvo@debian.org>
-Standards-Version: 3.6.2.0
+Standards-Version: 3.7.2
XS-Python-Version: all
-Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.6.45), apt-utils, python-all-dev, python-central
+Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.6.45ubuntu3), apt-utils, python-all-dev, python-central
Package: python-apt
Architecture: any
diff --git a/doc/examples/desc.py b/doc/examples/desc.py
new file mode 100644
index 00000000..87b9473b
--- /dev/null
+++ b/doc/examples/desc.py
@@ -0,0 +1,25 @@
+
+import apt_pkg
+
+apt_pkg.init()
+
+apt_pkg.Config.Set("APT::Acquire::Translation","de")
+
+cache = apt_pkg.GetCache()
+depcache = apt_pkg.GetDepCache(cache)
+
+pkg = cache["gcc"]
+cand = depcache.GetCandidateVer(pkg)
+print cand
+
+desc = cand.TranslatedDescription
+print desc
+print desc.FileList
+(f,index) = desc.FileList.pop(0)
+
+records = apt_pkg.GetPkgRecords(cache)
+records.Lookup((f,index))
+desc = records.LongDesc
+print len(desc)
+print desc
+
diff --git a/python/cache.cc b/python/cache.cc
index 174423c2..15b63b35 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -443,6 +443,69 @@ PyTypeObject PackageType =
0, // tp_hash
};
/*}}}*/
+// Description Class /*{{{*/
+// ---------------------------------------------------------------------
+static PyObject *DescriptionAttr(PyObject *Self,char *Name)
+{
+ pkgCache::DescIterator &Desc = GetCpp<pkgCache::DescIterator>(Self);
+ PyObject *Owner = GetOwner<pkgCache::DescIterator>(Self);
+
+ if (strcmp("LanguageCode",Name) == 0)
+ return PyString_FromString(Desc.LanguageCode());
+ else if (strcmp("md5",Name) == 0)
+ return Safe_FromString(Desc.md5());
+ else if (strcmp("FileList",Name) == 0)
+ {
+ /* The second value in the tuple is the index of the VF item. If the
+ user wants to request a lookup then that number will be used.
+ Maybe later it can become an object. */
+ PyObject *List = PyList_New(0);
+ for (pkgCache::DescFileIterator I = Desc.FileList(); I.end() == false; I++)
+ {
+ PyObject *DescFile;
+ PyObject *Obj;
+ DescFile = CppOwnedPyObject_NEW<pkgCache::PkgFileIterator>(Owner,&PackageFileType,I.File());
+ Obj = Py_BuildValue("Nl",DescFile,I.Index());
+ PyList_Append(List,Obj);
+ Py_DECREF(Obj);
+ }
+ return List;
+ }
+ PyErr_SetString(PyExc_AttributeError,Name);
+ return 0;
+}
+
+static PyObject *DescriptionRepr(PyObject *Self)
+{
+ pkgCache::DescIterator &Desc = GetCpp<pkgCache::DescIterator>(Self);
+
+ char S[300];
+ snprintf(S,sizeof(S),
+ "<pkgCache::Description object: language_code:'%s' md5:'%s' ",
+ Desc.LanguageCode(), Desc.md5());
+ return PyString_FromString(S);
+}
+
+PyTypeObject DescriptionType =
+{
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, // ob_size
+ "pkgCache::DescIterator", // tp_name
+ sizeof(CppOwnedPyObject<pkgCache::DescIterator>), // tp_basicsize
+ 0, // tp_itemsize
+ // Methods
+ CppOwnedDealloc<pkgCache::DescIterator>, // tp_dealloc
+ 0, // tp_print
+ DescriptionAttr, // tp_getattr
+ 0, // tp_setattr
+ 0, // tp_compare
+ DescriptionRepr, // tp_repr
+ 0, // tp_as_number
+ 0, // tp_as_sequence
+ 0, // tp_as_mapping
+ 0, // tp_hash
+};
+ /*}}}*/
// Version Class /*{{{*/
// ---------------------------------------------------------------------
@@ -571,6 +634,11 @@ static PyObject *VersionAttr(PyObject *Self,char *Name)
return PyString_FromString(Ver.PriorityType());
else if (strcmp("Downloadable", Name) == 0)
return Py_BuildValue("b", Ver.Downloadable());
+ else if (strcmp("TranslatedDescription", Name) == 0) {
+ return CppOwnedPyObject_NEW<pkgCache::DescIterator>(Owner,
+ &DescriptionType,
+ Ver.TranslatedDescription());
+ }
#if 0 // FIXME: enable once pkgSourceList is stored somewhere
else if (strcmp("IsTrusted", Name) == 0)
{
@@ -625,6 +693,7 @@ PyTypeObject VersionType =
};
/*}}}*/
+
// PackageFile Class /*{{{*/
// ---------------------------------------------------------------------
static PyObject *PackageFileAttr(PyObject *Self,char *Name)