summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlava Bacherikov2012-06-23 18:34:16 (GMT)
committerSlava Bacherikov2012-06-23 18:34:16 (GMT)
commit8af7afacb90d8b7e787e986110ed7947dee53115 (patch)
tree819bb81a214ace23d4c76e2f481b614e47acbc09
parentcffe07358db18dcead5bca370b03945ae304349e (diff)
Changes in package_metadata, not it not requre gentoolkit
-rw-r--r--gpackages/libs/package_info/generic_metadata/herds.py4
-rw-r--r--gpackages/libs/package_info/generic_metadata/package_metadata.py70
-rw-r--r--gpackages/libs/package_info/mixins.py12
3 files changed, 65 insertions, 21 deletions
diff --git a/gpackages/libs/package_info/generic_metadata/herds.py b/gpackages/libs/package_info/generic_metadata/herds.py
index dd698dd..25e738a 100644
--- a/gpackages/libs/package_info/generic_metadata/herds.py
+++ b/gpackages/libs/package_info/generic_metadata/herds.py
@@ -35,7 +35,7 @@ class Maintainer(AbstractXmlObject, ToStrMixin):
- email -- maintainer email
- role -- maintainer role
"""
- attrs = ('name', 'email', 'role')
+ attrs = ('name', 'email', 'role', 'description')
def __init__(self, *args, **kwargs):
super(Maintainer, self).__init__(*args, **kwargs)
@@ -116,7 +116,7 @@ class Herds(ToStrMixin):
defaultdict(list) with maintainer object as key, and list of herds
as value.
Example:
- {'<Maintainers example@gentoo.org>': ['mozilla','base'], ...}
+ {'<Maintainer example@gentoo.org>': ['mozilla','base'], ...}
"""
if self._maintainers_dict is not None:
return self._maintainers_dict
diff --git a/gpackages/libs/package_info/generic_metadata/package_metadata.py b/gpackages/libs/package_info/generic_metadata/package_metadata.py
index e89d387..704a590 100644
--- a/gpackages/libs/package_info/generic_metadata/package_metadata.py
+++ b/gpackages/libs/package_info/generic_metadata/package_metadata.py
@@ -1,23 +1,65 @@
from __future__ import absolute_import
-from gentoolkit.metadata import MetaData
from ..generic import ToStrMixin
+#XML
+from .my_etree import etree
+# Maintainers
+from .herds import Maintainer
-class FakeMetaData(ToStrMixin):
+class PackageMetaData(ToStrMixin):
- def herds(self):
- return []
+ def __init__(self, metadata_path):
+ self._metadata_path = metadata_path
+ self.descr = {'en': None}
+ self._herds = ()
+ self._maintainers = ()
+ try:
+ self._metadata_xml = etree.parse(metadata_path)
+ except IOError:
+ pass
+ else:
+ self._parse_all()
- def maintainers(self):
- return []
+ def _parse_all(self):
+ self._parse_herds()
+ self._parse_description()
+ self._parse_maintainers()
+
+ def _parse_herds(self):
+ herd_set = set()
+ for herd in self._metadata_xml.iterfind('herd'):
+ herd_set.add(herd.text)
+ self._herds = tuple(herd_set)
+
+ def _parse_description(self):
+ for descr in self._metadata_xml.iterfind('longdescription'):
+ lang = descr.attrib.get('lang', 'en')
+ self.descr[lang] = descr.text
+
+ def iter_mainteiner(self):
+ for maintainer_tree in self._metadata_xml.iterfind('maintainer'):
+ yield Maintainer(maintainer_tree)
+
+ def _parse_maintainers(self):
+ maintainers = set()
+ for maintainer in self.iter_mainteiner():
+ maintainers.add(maintainer)
+ self._maintainers = tuple(maintainers)
+
+ @property
+ def description(self):
+ return self.descr['en']
def descriptions(self):
- return []
+ return self.descr.values()
+
+ def descriptions_dict(self):
+ return self.descr
+
+ def herds(self):
+ return self._herds
+
+ def maintainers(self):
+ return self._maintainers
def __unicode__(self):
- return 'fake'
-
-def PackageMetaData(path):
- try:
- return MetaData(path)
- except IOError:
- return FakeMetaData()
+ return self._metadata_path
diff --git a/gpackages/libs/package_info/mixins.py b/gpackages/libs/package_info/mixins.py
index eedd1d7..92188ed 100644
--- a/gpackages/libs/package_info/mixins.py
+++ b/gpackages/libs/package_info/mixins.py
@@ -149,13 +149,15 @@ class PackageBaseMixin(ToStrMixin):
def descriptions(self):
return self.metadata.descriptions()
- @property
+ @cached_property
def description(self):
"Return first description in package metadata.xml"
- if len(self.descriptions)>0:
- return self.descriptions[0]
- else:
- return None
+ return self.metadata.description
+
+ @cached_property
+ def descriptions_dict(self):
+ return self.metadata.descriptions_dict()
+
@property
def cp(self):
raise NotImplementedError