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 1SaZP9-0005od-HR for garchives@archives.gentoo.org; Fri, 01 Jun 2012 21:29:09 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9CC7EE01C5; Fri, 1 Jun 2012 21:28:30 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 7263BE01C5 for ; Fri, 1 Jun 2012 21:28:30 +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 91D921B4048 for ; Fri, 1 Jun 2012 21:28:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 94473E5434 for ; Fri, 1 Jun 2012 21:28:26 +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: <1338567419.2ff1d2399d0d6fb40823546170295f24105d7189.bacher09@gentoo> Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/ X-VCS-Repository: proj/gentoo-packages X-VCS-Files: gpackages/libs/herds.py X-VCS-Directories: gpackages/libs/ X-VCS-Committer: bacher09 X-VCS-Committer-Name: Slava Bacherikov X-VCS-Revision: 2ff1d2399d0d6fb40823546170295f24105d7189 X-VCS-Branch: master Date: Fri, 1 Jun 2012 21:28:26 +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: 3a7b0d0e-59b7-441d-baf6-df2c3ea93a9a X-Archives-Hash: 4eade46aa4d3d903fcb69c6638d1e69d commit: 2ff1d2399d0d6fb40823546170295f24105d7189 Author: Slava Bacherikov bacher09 org> AuthorDate: Fri Jun 1 16:16:59 2012 +0000 Commit: Slava Bacherikov bacherikov org ua> CommitDate: Fri Jun 1 16:16:59 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoo-packag= es.git;a=3Dcommit;h=3D2ff1d239 Layer for work with herds. --- gpackages/libs/herds.py | 51 +++++++++++++++++++++++++++++++++++++++++= ++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/gpackages/libs/herds.py b/gpackages/libs/herds.py new file mode 100644 index 0000000..c123814 --- /dev/null +++ b/gpackages/libs/herds.py @@ -0,0 +1,51 @@ +try: + import xml.etree.cElementTree as etree +except (ImportError, SystemError): + import xml.etree.ElementTree as etree + + +def _gen_func(name): + return lambda self: getattr(self, name) + +class AbstarctXmlObject(object): + attrs =3D () + =20 + def __new__(cls, *args, **kwargs): + for val in cls.attrs: + setattr(cls, val, property(_gen_func('_'+val))) + ins =3D super(AbstarctXmlObject, cls).__new__(cls, *args, **kwar= gs)=20 + #attrs =3D getattr(ins, 'attrs') + return ins + =20 + def __init__(self, xml_object): + for val in self.attrs: + obj_xml =3D xml_object.find(val)=20 + setattr(self, '_' + val, None) + if obj_xml is not None: + setattr(self, '_' + val, obj_xml.text) + +class Maintainer(AbstarctXmlObject): + attrs =3D ('name', 'email', 'role') + +class Herd(AbstarctXmlObject): + # create name, email and description property + attrs =3D ('name', 'email', 'description') + + def __init__(self, xml_object): + super(Herd, self).__init__(xml_object)=20 + self._iter_maintainer =3D xml_object.iterfind('maintainer') + + def iter_mainteiner(self): + for maintainer_tree in self._iter_maintainer: + yield Maintainer(maintainer_tree) + + +class Herds(object): + def __init__(self, herd_path=3D'/usr/portage/metadata/herds.xml'): + self._herd_path =3D herd_path + self._herd_parse =3D etree.parse(herd_path) + self._iter_herd =3D self._herd_parse.iterfind('herd') + + def iter_herd(self): + for herd_tree in self._iter_herd: + yield Herd(herd_tree)