From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SeVvo-0001PZ-62 for garchives@archives.gentoo.org; Tue, 12 Jun 2012 18:35:08 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3B8A6E058A; Tue, 12 Jun 2012 18:34:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id F06EFE058A for ; Tue, 12 Jun 2012 18:34:50 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 0E8071B4038 for ; Tue, 12 Jun 2012 18:34:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id A5FBFE543A for ; Tue, 12 Jun 2012 18:34:47 +0000 (UTC) From: "Slava Bacherikov" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Slava Bacherikov" Message-ID: <1339505112.ad5103886839a96fa67b7108140b2d6350b19040.bacher09@gentoo> Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/ X-VCS-Repository: proj/gentoo-packages X-VCS-Files: gpackages/libs/porttree.py X-VCS-Directories: gpackages/libs/ X-VCS-Committer: bacher09 X-VCS-Committer-Name: Slava Bacherikov X-VCS-Revision: ad5103886839a96fa67b7108140b2d6350b19040 X-VCS-Branch: master Date: Tue, 12 Jun 2012 18:34:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 0807b302-c103-48d0-b0e9-e1bd689a5fc7 X-Archives-Hash: b329b63580a4ff62d0523e4606389493 commit: ad5103886839a96fa67b7108140b2d6350b19040 Author: Slava Bacherikov bacher09 org> AuthorDate: Tue Jun 12 12:45:12 2012 +0000 Commit: Slava Bacherikov bacherikov org ua> CommitDate: Tue Jun 12 12:45:12 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoo-packag= es.git;a=3Dcommit;h=3Dad510388 Get category description from category metadata --- gpackages/libs/porttree.py | 42 ++++++++++++++++++++++++++++++++++++++= +++- 1 files changed, 41 insertions(+), 1 deletions(-) diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py index 6beac52..47d766a 100644 --- a/gpackages/libs/porttree.py +++ b/gpackages/libs/porttree.py @@ -14,6 +14,12 @@ from generic import ToStrMixin, file_sha1, file_mtime,= cached_property, \ from use_info import get_uses_info, get_local_uses_info import os =20 +#XML +try: + import xml.etree.cElementTree as etree +except (ImportError, SystemError): + import xml.etree.ElementTree as etree + # Validators from django.core.validators import URLValidator, validate_email=20 from django.core.exceptions import ValidationError @@ -180,6 +186,11 @@ class Portage(object): for tree_name in self.tree_order: yield PortTree(tree_dict[tree_name], tree_name) =20 + def iter_categories(self): + for tree in self.iter_trees(): + for category in tree.iter_categories(): + yield category + def iter_packages(self): for tree in self.iter_trees(): for package in tree.iter_packages(): @@ -263,11 +274,31 @@ class PortTree(ToStrMixin): self.porttree_path, 'profiles/use.local.desc') =20 +class CategoryMetadata(object): + + def __init__(self, metadata_path): + self._metadata_xml =3D etree.parse(metadata_path) + self._descrs =3D {} + self._parse_descrs() + + def _parse_descrs(self): + for descr_xml in self._metadata_xml.iterfind('longdescription'): + lang =3D descr_xml.attrib.get('lang', 'en') + self._descrs[lang] =3D descr_xml.text + + @property + def descrs(self): + return self._descrs + + @property + def default_descr(self): + return self._descrs.get('en') + =20 class Category(ToStrMixin): "Represent category of portage tree as object" =20 - __slots__ =3D ('porttree', 'category') + __slots__ =3D ('porttree', 'category', '_cache') =20 def __init__(self, porttree, category): """Args: @@ -276,6 +307,7 @@ class Category(ToStrMixin): """ self.porttree =3D porttree self.category =3D category + self._cache =3D {} =20 def iter_packages(self): packages =3D listdir(self.porttree.porttree + '/'+ self.category= , @@ -298,6 +330,14 @@ class Category(ToStrMixin): return os.path.join(self.porttree.porttree_path, self.category) =20 @property + def metadata_path(self): + return os.path.join(self.category_path, 'metadata.xml') + + @cached_property + def metadata(self): + return CategoryMetadata(self.metadata_path) + + @property def porttree_path(self): return self.porttree.porttree =20