From 88c410f794c968cd5c50fd7e9838036e4207b88c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 3 Aug 2006 17:00:32 +0200 Subject: * basic ddtp support added --- doc/examples/desc.py | 25 +++++++++++++++++++ python/cache.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 doc/examples/desc.py 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(Self); + PyObject *Owner = GetOwner(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(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(Self); + + char S[300]; + snprintf(S,sizeof(S), + "), // tp_basicsize + 0, // tp_itemsize + // Methods + CppOwnedDealloc, // 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(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) -- cgit v1.2.3 From 7330eaf4b883bab1eb8d4b71784c2e60d56db82d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 3 Aug 2006 17:18:22 +0200 Subject: * apt/package.py: - make description return the correct descripton --- apt/package.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apt/package.py b/apt/package.py index 0d1145ea..e5de93f0 100644 --- a/apt/package.py +++ b/apt/package.py @@ -158,8 +158,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" -- cgit v1.2.3 From fd31f9b76508663d24c9a5684784cff18c235170 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 3 Aug 2006 17:25:57 +0200 Subject: * apt/package.py: - make shortDesc do the right thing too --- apt/package.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apt/package.py b/apt/package.py index e5de93f0..4e892082 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) -- cgit v1.2.3