* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-05-28 17:00 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-05-28 17:00 UTC (permalink / raw
To: gentoo-commits
commit: 339c39cf65cf554514ea5865c91deb6c3a7c90ce
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon May 28 15:51:12 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon May 28 15:51:12 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=339c39cf
Add name property.
---
gpackages/libs/porttree.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index c10995f..a2ff2a1 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -146,6 +146,10 @@ class Package(ToStrMixin):
def package_path(self):
return os.path.join(self.category.porttree.porttree_path, self.package)
+ @property
+ def name(self):
+ return self.package.split('/')[1]
+
manifest_path = property(_file_path('Manifest'))
changelog_path = property(_file_path('ChangeLog'))
manifest_sha1 = property(_file_hash('manifest_path'))
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-05-29 13:38 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-05-29 13:38 UTC (permalink / raw
To: gentoo-commits
commit: f747541be80d425bee895c28e6a9268a49aab9ce
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue May 29 12:57:34 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue May 29 12:57:34 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=f747541b
Fix bug in licenses property
---
gpackages/libs/porttree.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 96cbe0b..475a642 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -210,7 +210,7 @@ class Ebuild(ToStrMixin):
@property
def licenses(self):
- return filter(_license_filter, self.license)
+ return filter(_license_filter, self.license.split())
@property
def ebuild_path(self):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-05-29 21:34 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-05-29 21:34 UTC (permalink / raw
To: gentoo-commits
commit: cfec6827730879bf843ef4f9c4e176a01c6a46de
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue May 29 17:37:26 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue May 29 17:37:26 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=cfec6827
Fix bug in get_keywords
---
gpackages/libs/porttree.py | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index c50b74d..a54ef12 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -12,6 +12,8 @@ BINDB = portage.db[portage.root]["bintree"].dbapi
PORTDB = portage.db[portage.root]["porttree"].dbapi
VARDB = portage.db[portage.root]["vartree"].dbapi
+ARCHES = PORTDB.settings["PORTAGE_ARCHLIST"].split()
+
_license_filter = lambda x: False if x.startswith('|') or x.startswith('(') or \
x.endswith('?') or x.startswith(')') \
else True
@@ -174,7 +176,7 @@ class Ebuild(ToStrMixin):
def get_keywords(self):
l = []
- for keyword in self.iter_keyworkds():
+ for keyword in self.iter_keywords():
l.append(keyword)
return l
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-05-31 15:28 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-05-31 15:28 UTC (permalink / raw
To: gentoo-commits
commit: 2cc54c310d4bf1ffc6ce0904f10559ad16bd2672
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu May 31 14:42:05 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu May 31 14:42:05 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=2cc54c31
Fix bug with bad keywords.
---
gpackages/libs/porttree.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 160aa6b..2c45249 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -178,9 +178,13 @@ class Ebuild(ToStrMixin):
self.package = package
self.ebuild = ebuild
self.package_object = PackageInfo(ebuild)
+
+ @property
+ def keywords(self):
+ return self.package_object.environment("KEYWORDS", prefer_vdb = False)
def iter_keywords(self):
- keywords = self.package_object.environment("KEYWORDS").split()
+ keywords = self.keywords.split()
for keyword in keywords:
yield Keyword(keyword)
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-05-31 15:28 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-05-31 15:28 UTC (permalink / raw
To: gentoo-commits
commit: 671230a8b3eb3b6fbae4dea2061b9e82c7fc2dec
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu May 31 15:28:21 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu May 31 15:28:21 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=671230a8
Litle change in API
---
gpackages/libs/porttree.py | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 2c45249..bfd4859 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -80,6 +80,10 @@ class Keyword(ToStrMixin):
def __unicode__(self):
return self.status_repr[self.status] + self.name
+ @property
+ def arch(self):
+ return self.name
+
class Portage(object):
@@ -180,11 +184,15 @@ class Ebuild(ToStrMixin):
self.package_object = PackageInfo(ebuild)
@property
- def keywords(self):
+ def keywords_env(self):
return self.package_object.environment("KEYWORDS", prefer_vdb = False)
+
+ @property
+ def keywords(self):
+ return list(frozenset(self.keywords_env.split()))
def iter_keywords(self):
- keywords = self.keywords.split()
+ keywords = self.keywords
for keyword in keywords:
yield Keyword(keyword)
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-01 21:28 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-01 21:28 UTC (permalink / raw
To: gentoo-commits
commit: 2ff1d2399d0d6fb40823546170295f24105d7189
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Fri Jun 1 16:16:59 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Fri Jun 1 16:16:59 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=2ff1d239
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 = ()
+
+ def __new__(cls, *args, **kwargs):
+ for val in cls.attrs:
+ setattr(cls, val, property(_gen_func('_'+val)))
+ ins = super(AbstarctXmlObject, cls).__new__(cls, *args, **kwargs)
+ #attrs = getattr(ins, 'attrs')
+ return ins
+
+ def __init__(self, xml_object):
+ for val in self.attrs:
+ obj_xml = xml_object.find(val)
+ setattr(self, '_' + val, None)
+ if obj_xml is not None:
+ setattr(self, '_' + val, obj_xml.text)
+
+class Maintainer(AbstarctXmlObject):
+ attrs = ('name', 'email', 'role')
+
+class Herd(AbstarctXmlObject):
+ # create name, email and description property
+ attrs = ('name', 'email', 'description')
+
+ def __init__(self, xml_object):
+ super(Herd, self).__init__(xml_object)
+ self._iter_maintainer = 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='/usr/portage/metadata/herds.xml'):
+ self._herd_path = herd_path
+ self._herd_parse = etree.parse(herd_path)
+ self._iter_herd = self._herd_parse.iterfind('herd')
+
+ def iter_herd(self):
+ for herd_tree in self._iter_herd:
+ yield Herd(herd_tree)
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-01 21:28 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-01 21:28 UTC (permalink / raw
To: gentoo-commits
commit: 08e1a509346904e4ac6146511d1f5f342455e551
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Fri Jun 1 16:16:38 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Fri Jun 1 16:16:38 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=08e1a509
Add metadata access.
---
gpackages/libs/porttree.py | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index d8b3da3..3faa150 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -5,6 +5,7 @@ from portage.exception import PortageException, FileNotFound, InvalidAtom, \
InvalidDependString, InvalidPackageName
from gentoolkit.package import Package as PackageInfo
+from gentoolkit.metadata import MetaData
from datetime import datetime
import hashlib
import os
@@ -163,6 +164,7 @@ class Package(ToStrMixin):
def __init__(self, category, package):
self.category = category
self.package = package
+ self._metadata = None
def iter_ebuilds(self):
ebuilds = PORTDB.cp_list(self.package, mytree=self.category.porttree.porttree)
@@ -176,6 +178,12 @@ class Package(ToStrMixin):
def package_path(self):
return os.path.join(self.category.porttree.porttree_path, self.package)
+ @property
+ def metadata(self):
+ if self._metadata is None:
+ self._metadata = MetaData( self.metadata_path)
+ return self._metadata
+
mtime = property(_file_mtime("package_path"))
@property
@@ -184,12 +192,16 @@ class Package(ToStrMixin):
manifest_path = property(_file_path('Manifest'))
changelog_path = property(_file_path('ChangeLog'))
+ metadata_path = property(_file_path('metadata.xml'))
+
#Hashes
manifest_sha1 = property(_file_hash('manifest_path'))
changelog_sha1 = property(_file_hash('changelog_path'))
+ metadata_sha1 = property(_file_hash('metadata_path'))
# Modify times
manifest_mtime = property(_file_mtime("manifest_path"))
changelog_mtime = property(_file_mtime("changelog_path"))
+ metadata_mtime = property(_file_mtime("metadata_path"))
class Ebuild(ToStrMixin):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-02 16:04 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-02 16:04 UTC (permalink / raw
To: gentoo-commits
commit: b236cb55afe0279395efa3bfee797a6cbdb7963b
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sat Jun 2 15:53:56 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sat Jun 2 15:53:56 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=b236cb55
Litle optimization with slots
---
gpackages/libs/porttree.py | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 6ed2629..0a5b0fc 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -55,6 +55,8 @@ class ToStrMixin(object):
return '<%s %s>' % (type(self).__name__, self.__str__())
class Use(ToStrMixin):
+ __slots__ = ('name',)
+
def __init__(self, name):
if name.startswith('+') or name.startswith('-'):
name = name[1:]
@@ -75,6 +77,7 @@ class Use(ToStrMixin):
class Keyword(ToStrMixin):
+ __slots__ = ('name', 'status')
status_repr = ['','~','-']
def __init__(self, name, status = 0):
@@ -135,6 +138,8 @@ class PortTree(ToStrMixin):
class Category(ToStrMixin):
+
+ __slots__ = ('porttree', 'category')
def __init__(self, porttree, category):
self.porttree = porttree
@@ -161,6 +166,9 @@ class Category(ToStrMixin):
class Package(ToStrMixin):
+
+ __slots__ = ('category', 'package', '_metadata')
+
def __init__(self, category, package):
self.category = category
self.package = package
@@ -205,6 +213,9 @@ class Package(ToStrMixin):
class Ebuild(ToStrMixin):
+
+ __slots__ = ('package', 'ebuild', 'package_object')
+
def __init__(self, package, ebuild):
self.package = package
self.ebuild = ebuild
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-03 13:19 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-03 13:19 UTC (permalink / raw
To: gentoo-commits
commit: 578144075b13c6e755525dd8565d706baf7d7bff
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sun Jun 3 12:46:18 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sun Jun 3 12:46:18 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=57814407
Changes in herds layer.
---
gpackages/libs/herds.py | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/gpackages/libs/herds.py b/gpackages/libs/herds.py
index b1e596b..02d2782 100644
--- a/gpackages/libs/herds.py
+++ b/gpackages/libs/herds.py
@@ -29,6 +29,11 @@ class AbstarctXmlObject(object):
class Maintainer(AbstarctXmlObject, ToStrMixin):
attrs = ('name', 'email', 'role')
+ def __init__(self, *args, **kwargs):
+ super(Maintainer, self).__init__(*args, **kwargs)
+ if self._email is not None:
+ self._email = self._email.lower()
+
def __eq__(self, other):
return self.email == other.email
@@ -47,21 +52,31 @@ class Herd(AbstarctXmlObject, ToStrMixin):
def __init__(self, xml_object):
super(Herd, self).__init__(xml_object)
- self._iter_maintainer = xml_object.iterfind('maintainer')
+ self._xml_object = xml_object
+
+ def __eq__(self, other):
+ return self.name == other.name
+
+ def __ne__(self, other):
+ return self.name != other.name
+
+ def __hash__(self):
+ return hash(self.name)
def iter_mainteiner(self):
- for maintainer_tree in self._iter_maintainer:
+ for maintainer_tree in self._xml_object.iterfind('maintainer'):
yield Maintainer(maintainer_tree)
def __unicode__(self):
return self.name
-class Herds(object):
+class Herds(ToStrMixin):
def __init__(self, herd_path='/usr/portage/metadata/herds.xml'):
self._herd_path = herd_path
self._herd_parse = etree.parse(herd_path)
self._herds_dict = None
+ self._maintainers_dict = None
def iter_herd(self):
for herd_tree in self._herd_parse.iterfind('herd'):
@@ -77,9 +92,15 @@ class Herds(object):
return res
def get_maintainers_with_hers(self):
+ if self._maintainers_dict is not None:
+ return self._maintainers_dict
herd_dict = self.get_herds_indict()
maintainer_dict = defaultdict(list)
for herd in herd_dict.itervalues():
for maintainer in herd.iter_mainteiner():
maintainer_dict[maintainer].append(herd.name)
+ self._maintainers_dict = maintainer_dict
return maintainer_dict
+
+ def __unicode__(self):
+ return self._herd_path
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-03 13:19 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-03 13:19 UTC (permalink / raw
To: gentoo-commits
commit: 50d5fdbe69872b2bf509cf9c8a9efb4845bd924c
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sat Jun 2 19:24:17 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sat Jun 2 19:24:17 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=50d5fdbe
Changes in libs for working with portage tree.
---
gpackages/libs/generic.py | 8 ++++++++
gpackages/libs/herds.py | 42 ++++++++++++++++++++++++++++++++++++++----
gpackages/libs/porttree.py | 8 +-------
3 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
new file mode 100644
index 0000000..7fe9cc8
--- /dev/null
+++ b/gpackages/libs/generic.py
@@ -0,0 +1,8 @@
+
+class ToStrMixin(object):
+ def __str__(self):
+ return unicode(self).encode('utf-8')
+
+ def __repr__(self):
+ return '<%s %s>' % (type(self).__name__, self.__str__())
+
diff --git a/gpackages/libs/herds.py b/gpackages/libs/herds.py
index c123814..b1e596b 100644
--- a/gpackages/libs/herds.py
+++ b/gpackages/libs/herds.py
@@ -3,6 +3,8 @@ try:
except (ImportError, SystemError):
import xml.etree.ElementTree as etree
+from collections import defaultdict
+from generic import ToStrMixin
def _gen_func(name):
return lambda self: getattr(self, name)
@@ -24,10 +26,22 @@ class AbstarctXmlObject(object):
if obj_xml is not None:
setattr(self, '_' + val, obj_xml.text)
-class Maintainer(AbstarctXmlObject):
+class Maintainer(AbstarctXmlObject, ToStrMixin):
attrs = ('name', 'email', 'role')
-class Herd(AbstarctXmlObject):
+ def __eq__(self, other):
+ return self.email == other.email
+
+ def __ne__(self, other):
+ return self.email != other.email
+
+ def __hash__(self):
+ return hash(self.email)
+
+ def __unicode__(self):
+ return self.email
+
+class Herd(AbstarctXmlObject, ToStrMixin):
# create name, email and description property
attrs = ('name', 'email', 'description')
@@ -39,13 +53,33 @@ class Herd(AbstarctXmlObject):
for maintainer_tree in self._iter_maintainer:
yield Maintainer(maintainer_tree)
+ def __unicode__(self):
+ return self.name
+
class Herds(object):
def __init__(self, herd_path='/usr/portage/metadata/herds.xml'):
self._herd_path = herd_path
self._herd_parse = etree.parse(herd_path)
- self._iter_herd = self._herd_parse.iterfind('herd')
+ self._herds_dict = None
def iter_herd(self):
- for herd_tree in self._iter_herd:
+ for herd_tree in self._herd_parse.iterfind('herd'):
yield Herd(herd_tree)
+
+ def get_herds_indict(self):
+ if self._herds_dict is not None:
+ return self._herds_dict
+ res = {}
+ for herd in self.iter_herd():
+ res[herd.name] = herd
+ self._herds_dict = res
+ return res
+
+ def get_maintainers_with_hers(self):
+ herd_dict = self.get_herds_indict()
+ maintainer_dict = defaultdict(list)
+ for herd in herd_dict.itervalues():
+ for maintainer in herd.iter_mainteiner():
+ maintainer_dict[maintainer].append(herd.name)
+ return maintainer_dict
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 0a5b0fc..3f1f1f6 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -6,6 +6,7 @@ from portage.exception import PortageException, FileNotFound, InvalidAtom, \
from gentoolkit.package import Package as PackageInfo
from gentoolkit.metadata import MetaData
+from generic import ToStrMixin
from datetime import datetime
import hashlib
import os
@@ -47,13 +48,6 @@ def file_mtime(file_path):
else:
return None
-class ToStrMixin(object):
- def __str__(self):
- return unicode(self).encode('utf-8')
-
- def __repr__(self):
- return '<%s %s>' % (type(self).__name__, self.__str__())
-
class Use(ToStrMixin):
__slots__ = ('name',)
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-03 16:19 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-03 16:19 UTC (permalink / raw
To: gentoo-commits
commit: 0589e7d67f07e81f1971e972b046cf8e14d37adf
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sun Jun 3 16:14:52 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sun Jun 3 16:14:52 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=0589e7d6
Iter categories in alphabetic order.
---
gpackages/libs/porttree.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 3f1f1f6..8bee3dd 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -110,7 +110,7 @@ class PortTree(ToStrMixin):
self.porttree = porttree # TODO: it should be read-only
def iter_categories(self):
- for category in PORTDB.settings.categories:
+ for category in sorted(PORTDB.settings.categories):
yield Category(self, category)
def iter_packages(self):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-03 19:34 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-03 19:34 UTC (permalink / raw
To: gentoo-commits
commit: 5d48506679f27c041450088918e4357366cc4c24
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sun Jun 3 18:44:47 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sun Jun 3 18:44:47 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=5d485066
Add module to colect use flag info.
---
gpackages/libs/use_info.py | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/gpackages/libs/use_info.py b/gpackages/libs/use_info.py
new file mode 100644
index 0000000..faa95ef
--- /dev/null
+++ b/gpackages/libs/use_info.py
@@ -0,0 +1,32 @@
+import re
+from collections import defaultdict
+
+USES_RE = r'(?P<use>[^#].*) - (?P<description>.*)'
+USES_DESC_RE = r'^%s$' % USES_RE
+USES_LOCAL_DESC_RE = r'^(?P<package>[^#].*):%s$' % USES_RE
+
+use_re = re.compile(USES_DESC_RE)
+use_local_re = re.compile(USES_LOCAL_DESC_RE)
+
+def _get_info(filename, re_string, modify_function, res_var = {}):
+ use_desc = open(filename, 'r').read()
+ uses_desc = use_desc.split("\n")
+ res_dict = res_var
+ for use_str in uses_desc:
+ res_match = re_string.match(use_str)
+ if res_match is not None:
+ modify_function(res_dict, res_match.groupdict())
+
+ return res_dict
+
+def get_uses_info(filename = '/usr/portage/profiles/use.desc'):
+ def action(res_dict, match):
+ res_dict[match['use']] = match['description']
+
+ return _get_info(filename, use_re, action)
+
+def get_local_uses_info(filename = '/usr/portage/profiles/use.local.desc'):
+ def action(res_dict, match):
+ res_dict[match['use']][match['package']] = match['description']
+
+ return _get_info(filename, use_local_re, action, defaultdict(dict))
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-04 16:16 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-04 16:16 UTC (permalink / raw
To: gentoo-commits
commit: 7cdf9ea4302dd6999d481abc252d87a26590ae7a
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 4 16:16:20 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 4 16:16:20 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=7cdf9ea4
Fix typo in herds.py
---
gpackages/libs/herds.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/herds.py b/gpackages/libs/herds.py
index 02d2782..89574a2 100644
--- a/gpackages/libs/herds.py
+++ b/gpackages/libs/herds.py
@@ -9,7 +9,7 @@ from generic import ToStrMixin
def _gen_func(name):
return lambda self: getattr(self, name)
-class AbstarctXmlObject(object):
+class AbstractXmlObject(object):
attrs = ()
def __new__(cls, *args, **kwargs):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-04 16:16 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-04 16:16 UTC (permalink / raw
To: gentoo-commits
commit: fdf39f15710d6bf978ed97ffe0fc80404cf5448c
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 4 16:07:13 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 4 16:07:13 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=fdf39f15
Check if category exists in repo.
---
gpackages/libs/porttree.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index e1a7dcc..9b5bb9b 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -111,7 +111,8 @@ class PortTree(ToStrMixin):
def iter_categories(self):
for category in sorted(PORTDB.settings.categories):
- yield Category(self, category)
+ if os.path.isdir(os.path.join(self.porttree_path, category)):
+ yield Category(self, category)
def iter_packages(self):
for category in self.iter_categories():
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-04 22:18 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-04 22:18 UTC (permalink / raw
To: gentoo-commits
commit: 4a9e85eab23a8d0c4e64d0658637a7d85db7b0ae
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 4 22:18:28 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 4 22:18:28 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=4a9e85ea
Add some docstrings.
---
gpackages/libs/generic.py | 3 +++
gpackages/libs/herds.py | 28 +++++++++++++++++++++++++++-
gpackages/libs/porttree.py | 14 +++++++++++++-
gpackages/libs/use_info.py | 19 +++++++++++++++++++
4 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index 7fe9cc8..dc15a65 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -1,5 +1,8 @@
class ToStrMixin(object):
+ """Abstract class for inheritence, allow add simple `__str__` and `__repr__`
+ methods
+ """
def __str__(self):
return unicode(self).encode('utf-8')
diff --git a/gpackages/libs/herds.py b/gpackages/libs/herds.py
index 70ce071..7626d03 100644
--- a/gpackages/libs/herds.py
+++ b/gpackages/libs/herds.py
@@ -10,6 +10,10 @@ def _gen_func(name):
return lambda self: getattr(self, name)
class AbstractXmlObject(object):
+ """Abstract class for iheritance,
+ dynamicly generate properties by `attrs` param
+ each generated param return value of `_` + property name variable.
+ """
attrs = ()
def __new__(cls, *args, **kwargs):
@@ -20,6 +24,7 @@ class AbstractXmlObject(object):
return ins
def __init__(self, xml_object):
+ "Set internal value for each value in attrs parameter"
for val in self.attrs:
obj_xml = xml_object.find(val)
setattr(self, '_' + val, None)
@@ -27,6 +32,12 @@ class AbstractXmlObject(object):
setattr(self, '_' + val, obj_xml.text)
class Maintainer(AbstractXmlObject, ToStrMixin):
+ """Have 3 atributes:
+
+ - name -- maintainer name
+ - email -- maintainer email
+ - role -- maintainer role
+ """
attrs = ('name', 'email', 'role')
def __init__(self, *args, **kwargs):
@@ -47,6 +58,11 @@ class Maintainer(AbstractXmlObject, ToStrMixin):
return self.email
class Herd(AbstractXmlObject, ToStrMixin):
+ """Have 3 atributes:
+ - name -- herd name
+ - email -- herd email
+ - description -- herd description
+ """
# create name, email and description property
attrs = ('name', 'email', 'description')
@@ -72,7 +88,8 @@ class Herd(AbstractXmlObject, ToStrMixin):
class Herds(ToStrMixin):
- def __init__(self, herd_path='/usr/portage/metadata/herds.xml'):
+ "Object that represent herds.xml file "
+ def __init__(self, herd_path = '/usr/portage/metadata/herds.xml'):
self._herd_path = herd_path
self._herd_parse = etree.parse(herd_path)
self._herds_dict = None
@@ -83,6 +100,9 @@ class Herds(ToStrMixin):
yield Herd(herd_tree)
def get_herds_indict(self):
+ """Returns:
+ dict with herd name as key and herd object as value
+ """
if self._herds_dict is not None:
return self._herds_dict
res = {}
@@ -92,6 +112,12 @@ class Herds(ToStrMixin):
return res
def get_maintainers_with_herds(self):
+ """Returns:
+ defaultdict(list) with maintainer object as key, and list of herds
+ as value.
+ Example:
+ {'<Maintainers example@gentoo.org>': ['mozilla','base'], ...}
+ """
if self._maintainers_dict is not None:
return self._maintainers_dict
herd_dict = self.get_herds_indict()
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 9b5bb9b..0bf329b 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -49,9 +49,13 @@ def file_mtime(file_path):
return None
class Use(ToStrMixin):
+ "Represend Use flag as object"
__slots__ = ('name',)
def __init__(self, name):
+ """Args:
+ name -- name of use flag, may start with + or -
+ """
if name.startswith('+') or name.startswith('-'):
name = name[1:]
self.name = name
@@ -69,12 +73,19 @@ class Use(ToStrMixin):
return hash(self.name)
-
class Keyword(ToStrMixin):
__slots__ = ('name', 'status')
status_repr = ['','~','-']
def __init__(self, name, status = 0):
+ """Args:
+ name -- name of keyword, it may start with ~ or -, if so than
+ status will be auto seting.
+ status -- status of keyword: 0 - stable,
+ 1 - utested '~',
+ 2 - unstable '-'
+ Also may get by name parameter.
+ """
if name.startswith('~'):
name = name[1:]
status = 1
@@ -89,6 +100,7 @@ class Keyword(ToStrMixin):
@property
def arch(self):
+ "Return arch name"
return self.name
diff --git a/gpackages/libs/use_info.py b/gpackages/libs/use_info.py
index faa95ef..b45cda7 100644
--- a/gpackages/libs/use_info.py
+++ b/gpackages/libs/use_info.py
@@ -20,12 +20,31 @@ def _get_info(filename, re_string, modify_function, res_var = {}):
return res_dict
def get_uses_info(filename = '/usr/portage/profiles/use.desc'):
+ """Args:
+ filename -- full path to use.desc file
+ Returns:
+ dict with use flag as key, and description as value
+ Example:
+ {'doc': 'Doc description', ...}
+ Notice:
+ In portage public api `get_use_flag_dict`
+ """
def action(res_dict, match):
res_dict[match['use']] = match['description']
return _get_info(filename, use_re, action)
def get_local_uses_info(filename = '/usr/portage/profiles/use.local.desc'):
+ """Args:
+ filename -- full path to use.local.desc file
+ Returns:
+ defaultdict(dict) with use flag as first key, package name as second
+ key, and description as value
+ Example:
+ {'api': {'app-emulation/xen-tools': 'Use descr', ...} , ...}
+ Notice:
+ In portage public api `get_use_flag_dict`
+ """
def action(res_dict, match):
res_dict[match['use']][match['package']] = match['description']
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-05 15:49 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-05 15:49 UTC (permalink / raw
To: gentoo-commits
commit: 5b7efed420bdcf338f5743614bcd1ebfc3a4bc4f
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 5 12:27:20 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 5 12:27:20 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=5b7efed4
Add caching propertys
---
gpackages/libs/porttree.py | 67 ++++++++++++++++++++++++++-----------------
1 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 0bf329b..6781d4e 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -48,6 +48,24 @@ def file_mtime(file_path):
else:
return None
+class cached_property(object):
+ def __init__(self, func, name = None):
+ self.func = func
+ if name is None:
+ name = func.__name__
+ self.__name__ = name
+ self.__module__ = func.__module__
+
+ def __get__(self, inst, owner):
+ try:
+ value = inst._cache[self.__name__]
+ except (KeyError, AttributeError):
+ value = self.func(inst)
+ if not hasattr(inst, '_cache'):
+ inst._cache = {}
+ inst._cache[self.__name__] = value
+ return value
+
class Use(ToStrMixin):
"Represend Use flag as object"
__slots__ = ('name',)
@@ -174,13 +192,12 @@ class Category(ToStrMixin):
class Package(ToStrMixin):
- __slots__ = ('category', 'package', '_metadata', '_changelog')
+ __slots__ = ('category', 'package', '_cache')
def __init__(self, category, package):
self.category = category
self.package = package
- self._metadata = None
- self._changelog = None
+ self._cache = {}
def iter_ebuilds(self):
ebuilds = PORTDB.cp_list(self.package, mytree=self.category.porttree.porttree)
@@ -194,11 +211,9 @@ class Package(ToStrMixin):
def package_path(self):
return os.path.join(self.category.porttree.porttree_path, self.package)
- @property
+ @cached_property
def metadata(self):
- if self._metadata is None:
- self._metadata = MetaData( self.metadata_path)
- return self._metadata
+ return MetaData( self.metadata_path)
mtime = property(_file_mtime("package_path"))
@@ -211,30 +226,28 @@ class Package(ToStrMixin):
metadata_path = property(_file_path('metadata.xml'))
#Hashes
- manifest_sha1 = property(_file_hash('manifest_path'))
- changelog_sha1 = property(_file_hash('changelog_path'))
- metadata_sha1 = property(_file_hash('metadata_path'))
+ manifest_sha1 = cached_property(_file_hash('manifest_path'), name = 'manifest_sha1')
+ changelog_sha1 = cached_property(_file_hash('changelog_path'), name = 'changelog_sha1')
+ metadata_sha1 = cached_property(_file_hash('metadata_path'), name = 'metadata_sha1')
# Modify times
manifest_mtime = property(_file_mtime("manifest_path"))
changelog_mtime = property(_file_mtime("changelog_path"))
metadata_mtime = property(_file_mtime("metadata_path"))
- @property
+ @cached_property
def changelog(self):
- if self._changelog is not None:
- return self._changelog
- self._changelog = open(self.changelog_path,'r').read()
- return self._changelog
+ return open(self.changelog_path,'r').read()
class Ebuild(ToStrMixin):
- __slots__ = ('package', 'ebuild', 'package_object')
+ __slots__ = ('package', 'ebuild', 'package_object', '_cache')
def __init__(self, package, ebuild):
self.package = package
self.ebuild = ebuild
self.package_object = PackageInfo(ebuild)
+ self._cache = {}
@property
def keywords_env(self):
@@ -270,7 +283,7 @@ class Ebuild(ToStrMixin):
return l
#Could be faster
- @property
+ @cached_property
def is_masked(self):
return self.package_object.is_masked()
@@ -290,22 +303,22 @@ class Ebuild(ToStrMixin):
def ebuild_path(self):
return self.package_object.ebuild_path()
- homepage_val = property(_ebuild_environment('HOMEPAGE'))
- license = property(_ebuild_environment('LICENSE'))
- description = property(_ebuild_environment('DESCRIPTION'))
- eapi = property(_ebuild_environment('EAPI'))
- slot = property(_ebuild_environment('SLOT'))
+ homepage_val = cached_property(_ebuild_environment('HOMEPAGE'), name = 'homepage_val')
+ license = cached_property(_ebuild_environment('LICENSE'), name = 'license')
+ description = cached_property(_ebuild_environment('DESCRIPTION'), name = 'description')
+ eapi = cached_property(_ebuild_environment('EAPI'), name = 'eapi')
+ slot = cached_property(_ebuild_environment('SLOT'), name = 'slot')
- @property
+ @cached_property
def homepages(self):
return self.homepage_val.split()
- @property
+ @cached_property
def homepage(self):
return self.homepages[0] if len(self.homepages)>=1 else ''
- @property
+ @cached_property
def licenses(self):
return filter(_license_filter, self.license.split())
@@ -313,8 +326,8 @@ class Ebuild(ToStrMixin):
def ebuild_path(self):
return self.package_object.ebuild_path()
- sha1 = property(_file_hash("ebuild_path"))
- mtime = property(_file_mtime("ebuild_path"))
+ sha1 = cached_property(_file_hash("ebuild_path"), name = 'sha1')
+ mtime = cached_property(_file_mtime("ebuild_path"), name = 'mtime')
def __unicode__(self):
return self.ebuild
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-05 15:49 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-05 15:49 UTC (permalink / raw
To: gentoo-commits
commit: ef8e618691ad6b42bc52ebdfe86c064d03f34464
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 5 15:11:31 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 5 15:11:31 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=ef8e6186
Move some code to generic.py
---
gpackages/libs/generic.py | 35 ++++++++++++++++++++++++
gpackages/libs/porttree.py | 62 +++++++++++++++++---------------------------
2 files changed, 59 insertions(+), 38 deletions(-)
diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index dc15a65..ed08d93 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -1,3 +1,6 @@
+import os.path
+import hashlib
+from datetime import datetime
class ToStrMixin(object):
"""Abstract class for inheritence, allow add simple `__str__` and `__repr__`
@@ -9,3 +12,35 @@ class ToStrMixin(object):
def __repr__(self):
return '<%s %s>' % (type(self).__name__, self.__str__())
+
+def file_sha1(file_path):
+ sha1 = 'NULL'
+ if os.path.exists(file_path):
+ f = open(file_path, 'r')
+ sha1 = hashlib.sha1(f.read()).hexdigest()
+ f.close()
+ return sha1
+
+def file_mtime(file_path):
+ if os.path.exists(file_path):
+ return datetime.fromtimestamp(os.path.getmtime(file_path))
+ else:
+ return None
+
+class cached_property(object):
+ def __init__(self, func, name = None):
+ self.func = func
+ if name is None:
+ name = func.__name__
+ self.__name__ = name
+ self.__module__ = func.__module__
+
+ def __get__(self, inst, owner):
+ try:
+ value = inst._cache[self.__name__]
+ except (KeyError, AttributeError):
+ value = self.func(inst)
+ if not hasattr(inst, '_cache'):
+ inst._cache = {}
+ inst._cache[self.__name__] = value
+ return value
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 6781d4e..f18387b 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -6,9 +6,7 @@ from portage.exception import PortageException, FileNotFound, InvalidAtom, \
from gentoolkit.package import Package as PackageInfo
from gentoolkit.metadata import MetaData
-from generic import ToStrMixin
-from datetime import datetime
-import hashlib
+from generic import ToStrMixin, file_sha1, file_mtime, cached_property
import os
BINDB = portage.db[portage.root]["bintree"].dbapi
@@ -34,37 +32,6 @@ def _file_mtime(attr):
def _ebuild_environment(name):
return lambda self: self.package_object.environment(name)
-def file_sha1(file_path):
- sha1 = 'NULL'
- if os.path.exists(file_path):
- f = open(file_path, 'r')
- sha1 = hashlib.sha1(f.read()).hexdigest()
- f.close()
- return sha1
-
-def file_mtime(file_path):
- if os.path.exists(file_path):
- return datetime.fromtimestamp(os.path.getmtime(file_path))
- else:
- return None
-
-class cached_property(object):
- def __init__(self, func, name = None):
- self.func = func
- if name is None:
- name = func.__name__
- self.__name__ = name
- self.__module__ = func.__module__
-
- def __get__(self, inst, owner):
- try:
- value = inst._cache[self.__name__]
- except (KeyError, AttributeError):
- value = self.func(inst)
- if not hasattr(inst, '_cache'):
- inst._cache = {}
- inst._cache[self.__name__] = value
- return value
class Use(ToStrMixin):
"Represend Use flag as object"
@@ -92,6 +59,7 @@ class Use(ToStrMixin):
class Keyword(ToStrMixin):
+ "Represend ebuild Keyword as object"
__slots__ = ('name', 'status')
status_repr = ['','~','-']
@@ -135,8 +103,12 @@ class Portage(object):
class PortTree(ToStrMixin):
+ "Represent portage tree as object"
def __init__(self, porttree = '/usr/portage'):
+ """Args:
+ porttree -- full path to portage tree as str
+ """
self.porttree = porttree # TODO: it should be read-only
def iter_categories(self):
@@ -159,14 +131,20 @@ class PortTree(ToStrMixin):
@property
def porttree_path(self):
+ "Full path to portage tree"
return self.porttree
class Category(ToStrMixin):
+ "Represent category of portage tree as object"
__slots__ = ('porttree', 'category')
def __init__(self, porttree, category):
+ """Args:
+ porttree -- PortTree object
+ category -- category name as str
+ """
self.porttree = porttree
self.category = category
@@ -187,10 +165,12 @@ class Category(ToStrMixin):
@property
def category_path(self):
+ "Full path to category"
return os.path.join(self.porttree.porttree_path, self.category)
class Package(ToStrMixin):
+ "Represent package as object"
__slots__ = ('category', 'package', '_cache')
@@ -215,6 +195,10 @@ class Package(ToStrMixin):
def metadata(self):
return MetaData( self.metadata_path)
+ @property
+ def cp(self):
+ return self.package
+
mtime = property(_file_mtime("package_path"))
@property
@@ -240,6 +224,7 @@ class Package(ToStrMixin):
class Ebuild(ToStrMixin):
+ "Represent ebuild as object"
__slots__ = ('package', 'ebuild', 'package_object', '_cache')
@@ -297,10 +282,12 @@ class Ebuild(ToStrMixin):
@property
def fullversion(self):
+ "Version with revision"
return self.package_object.fullversion
@property
def ebuild_path(self):
+ "Full path to ebuild"
return self.package_object.ebuild_path()
homepage_val = cached_property(_ebuild_environment('HOMEPAGE'), name = 'homepage_val')
@@ -311,21 +298,20 @@ class Ebuild(ToStrMixin):
@cached_property
def homepages(self):
+ "List of homepages"
return self.homepage_val.split()
@cached_property
def homepage(self):
+ "First homepage in list"
return self.homepages[0] if len(self.homepages)>=1 else ''
@cached_property
def licenses(self):
+ "List of licenses used in ebuild"
return filter(_license_filter, self.license.split())
- @property
- def ebuild_path(self):
- return self.package_object.ebuild_path()
-
sha1 = cached_property(_file_hash("ebuild_path"), name = 'sha1')
mtime = cached_property(_file_mtime("ebuild_path"), name = 'mtime')
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-05 20:48 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-05 20:48 UTC (permalink / raw
To: gentoo-commits
commit: a6a33725de7805677a1d86a5c6f9d2d18eb13915
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 5 17:20:45 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 5 17:20:45 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=a6a33725
Changes for PEP8
---
gpackages/libs/porttree.py | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index f18387b..e4a3359 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -180,7 +180,8 @@ class Package(ToStrMixin):
self._cache = {}
def iter_ebuilds(self):
- ebuilds = PORTDB.cp_list(self.package, mytree=self.category.porttree.porttree)
+ ebuilds = PORTDB.cp_list(self.package,
+ mytree = self.category.porttree.porttree)
for ebuild in ebuilds:
yield Ebuild(self ,ebuild)
@@ -210,9 +211,12 @@ class Package(ToStrMixin):
metadata_path = property(_file_path('metadata.xml'))
#Hashes
- manifest_sha1 = cached_property(_file_hash('manifest_path'), name = 'manifest_sha1')
- changelog_sha1 = cached_property(_file_hash('changelog_path'), name = 'changelog_sha1')
- metadata_sha1 = cached_property(_file_hash('metadata_path'), name = 'metadata_sha1')
+ manifest_sha1 = cached_property(_file_hash('manifest_path'),
+ name = 'manifest_sha1')
+ changelog_sha1 = cached_property(_file_hash('changelog_path'),
+ name = 'changelog_sha1')
+ metadata_sha1 = cached_property(_file_hash('metadata_path'),
+ name = 'metadata_sha1')
# Modify times
manifest_mtime = property(_file_mtime("manifest_path"))
changelog_mtime = property(_file_mtime("changelog_path"))
@@ -290,11 +294,16 @@ class Ebuild(ToStrMixin):
"Full path to ebuild"
return self.package_object.ebuild_path()
- homepage_val = cached_property(_ebuild_environment('HOMEPAGE'), name = 'homepage_val')
- license = cached_property(_ebuild_environment('LICENSE'), name = 'license')
- description = cached_property(_ebuild_environment('DESCRIPTION'), name = 'description')
- eapi = cached_property(_ebuild_environment('EAPI'), name = 'eapi')
- slot = cached_property(_ebuild_environment('SLOT'), name = 'slot')
+ homepage_val = cached_property(_ebuild_environment('HOMEPAGE'),
+ name = 'homepage_val')
+ license = cached_property(_ebuild_environment('LICENSE'),
+ name = 'license')
+ description = cached_property(_ebuild_environment('DESCRIPTION'),
+ name = 'description')
+ eapi = cached_property(_ebuild_environment('EAPI'),
+ name = 'eapi')
+ slot = cached_property(_ebuild_environment('SLOT'),
+ name = 'slot')
@cached_property
def homepages(self):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-05 21:46 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-05 21:46 UTC (permalink / raw
To: gentoo-commits
commit: d986533d1aee9e79a33da4aeac2508fc946e69e0
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 5 21:45:57 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 5 21:45:57 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=d986533d
Changes in layer over portage
---
gpackages/libs/porttree.py | 62 ++++++++++++++++++++++++++++++++++++++++---
gpackages/libs/use_info.py | 2 +
2 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index fe2c9cf..5a4da3a 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -7,6 +7,7 @@ from portage.exception import PortageException, FileNotFound, InvalidAtom, \
from gentoolkit.package import Package as PackageInfo
from gentoolkit.metadata import MetaData
from generic import ToStrMixin, file_sha1, file_mtime, cached_property
+from use_info import get_uses_info, get_local_uses_info
import os
BINDB = portage.db[portage.root]["bintree"].dbapi
@@ -33,6 +34,13 @@ def _ebuild_environment(name):
return lambda self: self.package_object.environment(name)
+def _get_info_by_func(func, path1, path2):
+ path = os.path.join(path1, path2)
+ try:
+ return func(path)
+ except IOError:
+ return None
+
class Use(ToStrMixin):
"Represend Use flag as object"
__slots__ = ('name',)
@@ -89,27 +97,59 @@ class Keyword(ToStrMixin):
"Return arch name"
return self.name
+def _gen_all_use(func, iterator):
+ use_g = iterator
+ use_all_dict = next(use_g)
+ for use_dict in use_g:
+ if use_dict is not None:
+ func(use_all_dict, use_dict)
+ return use_all_dict
class Portage(object):
def iter_trees(self):
- for tree in PORTDB.porttrees:
- yield PortTree(tree)
+ tree_dict = PORTDB.repositories.treemap
+ for tree_name in PORTDB.repositories.prepos_order:
+ yield PortTree(tree_dict[tree_name], tree_name)
+
+ def iter_packages():
+ for tree in self.iter_trees():
+ for package in tree.iter_package():
+ yield package
def iter_ebuilds():
for tree in self.iter_trees():
for ebuild in tree.iter_ebuilds():
yield ebuild
+ def iter_use_desc(self):
+ for tree in self.iter_trees():
+ yield tree.use_desc
+
+ def iter_use_local_desc(self):
+ for tree in self.iter_trees():
+ yield tree.use_local_desc
+
+ def get_all_use_desc(self):
+ return _gen_all_use(lambda x,y: x.update(y), self.iter_use_desc())
+
+ def get_all_use_local_desc(self):
+ def action(all_dict, use_dict):
+ for key, value in use_dict.iteritems():
+ all_dict[key].update(value)
+
+ return _gen_all_use(action, self.iter_use_local_desc())
+
class PortTree(ToStrMixin):
"Represent portage tree as object"
- def __init__(self, porttree = '/usr/portage'):
+ def __init__(self, tree_path = '/usr/portage', name = 'main'):
"""Args:
- porttree -- full path to portage tree as str
+ tree_path -- full path to portage tree as str
"""
- self.porttree = porttree # TODO: it should be read-only
+ self.porttree = tree_path
+ self.name = name
def iter_categories(self):
for category in sorted(PORTDB.settings.categories):
@@ -134,6 +174,18 @@ class PortTree(ToStrMixin):
"Full path to portage tree"
return self.porttree
+ @cached_property
+ def use_desc(self):
+ return _get_info_by_func(get_uses_info,
+ self.porttree_path,
+ 'profiles/use.desc')
+
+ @cached_property
+ def use_local_desc(self):
+ return _get_info_by_func(get_local_uses_info,
+ self.porttree_path,
+ 'profiles/use.local.desc')
+
class Category(ToStrMixin):
"Represent category of portage tree as object"
diff --git a/gpackages/libs/use_info.py b/gpackages/libs/use_info.py
index b45cda7..c89dfe6 100644
--- a/gpackages/libs/use_info.py
+++ b/gpackages/libs/use_info.py
@@ -1,6 +1,8 @@
import re
from collections import defaultdict
+__all__ = ('get_uses_info', 'get_local_uses_info')
+
USES_RE = r'(?P<use>[^#].*) - (?P<description>.*)'
USES_DESC_RE = r'^%s$' % USES_RE
USES_LOCAL_DESC_RE = r'^(?P<package>[^#].*):%s$' % USES_RE
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-06 22:48 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-06 22:48 UTC (permalink / raw
To: gentoo-commits
commit: 36caba23fa7a8a9ceb05170d8acbc0e9b61d3c6c
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jun 6 22:48:35 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jun 6 22:48:35 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=36caba23
Fix typo
---
gpackages/libs/porttree.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index dec4867..8e8bb83 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -141,7 +141,7 @@ class Portage(object):
def iter_packages(self):
for tree in self.iter_trees():
- for package in tree.iter_package():
+ for package in tree.iter_packages():
yield package
def iter_ebuilds(self):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-07 22:48 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-07 22:48 UTC (permalink / raw
To: gentoo-commits
commit: ff8c32e541a7c5482417ed909fb14ced2920a4c3
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Jun 7 19:52:19 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Jun 7 19:52:19 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=ff8c32e5
Add more docstrings to porttree.py
---
gpackages/libs/porttree.py | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 8e8bb83..3bb6b6b 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -195,7 +195,7 @@ class PortTree(ToStrMixin):
yield ebuild
def __unicode__(self):
- return self.porttree
+ return self.name
@property
def porttree_path(self):
@@ -280,6 +280,7 @@ class Package(ToStrMixin):
@cached_property
def metadata(self):
+ "Return `MetaData` object that represent package metadata.xml file"
try:
return MetaData( self.metadata_path)
except IOError:
@@ -317,6 +318,7 @@ class Package(ToStrMixin):
@property
def description(self):
+ "Return first description in package metadata.xml"
if len(self.descriptions)>0:
return self.descriptions[0]
else:
@@ -324,6 +326,7 @@ class Package(ToStrMixin):
@cached_property
def changelog(self):
+ "Return ChangeLog content"
return file_get_content(self.changelog_path)
@@ -344,6 +347,7 @@ class Ebuild(ToStrMixin):
@property
def is_valid(self):
+ "Check if ebuild is valid"
try:
self.package_object.environment("EAPI")
except errors.GentoolkitFatalError:
@@ -357,6 +361,7 @@ class Ebuild(ToStrMixin):
return list(set(self.keywords_env.split()))
def iter_keywords(self):
+ "Iterate over keywords, yields Keyword object"
keywords = self.keywords
for keyword in keywords:
yield Keyword(keyword)
@@ -372,6 +377,7 @@ class Ebuild(ToStrMixin):
def iter_uses(self):
+ "Iterator over all uses, yiels `Use` object"
for use in self.get_uses_names():
yield Use(use)
@@ -388,10 +394,12 @@ class Ebuild(ToStrMixin):
@property
def version(self):
+ "Ebuild version"
return self.package_object.version
@property
def revision(self):
+ "Ebuild revision"
return self.package_object.revision
@property
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-07 22:48 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-07 22:48 UTC (permalink / raw
To: gentoo-commits
commit: 0157fd160bb40c5039308d1947f2b9620e467514
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Jun 7 22:48:08 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Jun 7 22:48:08 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=0157fd16
Add droping repeating keyword in porttree
---
gpackages/libs/porttree.py | 42 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 3bb6b6b..af7b513 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -1,3 +1,5 @@
+from functools import total_ordering
+from collections import defaultdict
import portage
from portage.util.listdir import listdir
from portage.dep import Atom
@@ -74,15 +76,15 @@ class Use(ToStrMixin):
return self.name
def __eq__(self, other):
- self.name == other.name
+ return self.name == other.name
def __ne__(self, other):
- self.name != other.name
+ return self.name != other.name
def __hash__(self):
return hash(self.name)
-
+@total_ordering
class Keyword(ToStrMixin):
"Represend ebuild Keyword as object"
__slots__ = ('name', 'status')
@@ -109,11 +111,42 @@ class Keyword(ToStrMixin):
def __unicode__(self):
return self.status_repr[self.status] + self.name
+ def __hash__(self):
+ return hash((self.name, self.status))
+
+ def is_same(self, other):
+ return self.name == other.name
+
+ def is_higer(self, other):
+ return self.status < other.status
+
+ def is_lower(self, other):
+ return self.status > other.status
+
+ def __eq__(self, other):
+ return (self.arch, self.status) == (other.arch, other.status)
+
+ def __lt__(self, other):
+ return (self.status, self.arch) > (other.status, other.arch)
+
@property
def arch(self):
"Return arch name"
return self.name
+class KeywordsSet(set):
+ def __init__(self, init_list):
+ start = defaultdict(list)
+ for item in init_list:
+ start[item.arch].append(item)
+
+ to_create = []
+ for item in start.itervalues():
+ item.sort(reverse = True)
+ if len(item)>=1:
+ to_create.append(item[0])
+ super(KeywordsSet, self).__init__(to_create)
+
def _gen_all_use(func, iterator):
use_g = iterator
use_all_dict = next(use_g)
@@ -372,6 +405,9 @@ class Ebuild(ToStrMixin):
l.append(keyword)
return l
+ def get_uniq_keywords(self):
+ return KeywordsSet(self.get_keywords)
+
def get_uses_names(self):
return self.package_object.environment("IUSE").split()
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-07 22:48 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-07 22:48 UTC (permalink / raw
To: gentoo-commits
commit: 46d86e941ef13ea688ed96072bae6e924d758157
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Jun 7 22:12:01 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Jun 7 22:12:01 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=46d86e94
Litle bugfix for some objects.
---
gpackages/libs/generic.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index 0629ed6..6d330e0 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -33,7 +33,7 @@ class StrThatIgnoreCase(unicode):
def __init__(self, value):
super(StrThatIgnoreCase, self).__init__(value)
- self._forcmp = value.lower()
+ self._forcmp = self.lower()
def __hash__(self):
return hash(self._forcmp)
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-09 18:19 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-09 18:19 UTC (permalink / raw
To: gentoo-commits
commit: 7a67e6580f068b9c7d356625198f61652cf3f70d
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sat Jun 9 11:05:52 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sat Jun 9 11:05:52 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=7a67e658
Add __all__ to porttree.py
---
gpackages/libs/porttree.py | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index af7b513..b5037cf 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -14,6 +14,8 @@ from generic import ToStrMixin, file_sha1, file_mtime, cached_property, \
from use_info import get_uses_info, get_local_uses_info
import os
+__all__ = ('Portage','PortTree', 'Category', 'Package', 'Ebuild')
+
BINDB = portage.db[portage.root]["bintree"].dbapi
PORTDB = portage.db[portage.root]["porttree"].dbapi
VARDB = portage.db[portage.root]["vartree"].dbapi
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-09 18:19 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-09 18:19 UTC (permalink / raw
To: gentoo-commits
commit: 189113dafa353390092cd35c087f8ff57ab2798a
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sat Jun 9 10:33:20 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sat Jun 9 10:33:20 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=189113da
Fix bug
---
gpackages/libs/generic.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index 6d330e0..f1751b0 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -19,10 +19,10 @@ def get_from_kwargs_and_del(list_what, kwargs):
list_what = (list_what, )
for item in list_what:
if item in kwargs:
- ret_list.append(v)
+ ret_list.append(kwargs[item])
else:
ret_list.append(None)
- del_from_dict(ret_list, kwargs)
+ del_from_dict(list_what, kwargs)
if len(ret_list)==1:
return ret_list[0]
else:
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-10 17:51 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-10 17:51 UTC (permalink / raw
To: gentoo-commits
commit: bdc9a42234f5f4e8f6877437f185cebb3036014d
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sun Jun 10 17:07:04 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sun Jun 10 17:07:04 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=bdc9a422
Change exception type in porttree
---
gpackages/libs/porttree.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index b5037cf..e71a806 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -167,7 +167,7 @@ class Portage(object):
if tree_name in self.treemap:
return PortTree(self.treemap[tree_name], tree_name)
else:
- raise AttributeError
+ raise ValueError
def iter_trees(self):
tree_dict = self.treemap
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-12 18:34 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-12 18:34 UTC (permalink / raw
To: gentoo-commits
commit: 09c5d76cec81accff270fa33ba09e4092103ae85
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 11 22:22:58 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 11 22:22:58 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=09c5d76c
Add methods that always return uniq list to porttree
---
gpackages/libs/porttree.py | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index effb144..b5b90d8 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -416,7 +416,7 @@ class Ebuild(ToStrMixin):
return l
def get_uniq_keywords(self):
- return KeywordsSet(self.get_keywords)
+ return KeywordsSet(self.get_keywords())
def get_uses_names(self):
return self.package_object.environment("IUSE").split()
@@ -433,6 +433,9 @@ class Ebuild(ToStrMixin):
l.append(use)
return l
+ def get_uniq_uses(self):
+ return frozenset(self.get_uses())
+
#Could be faster
@cached_property
def is_masked(self):
@@ -478,6 +481,9 @@ class Ebuild(ToStrMixin):
ret_list.append(StrThatIgnoreCase(ho))
return ret_list
+ def get_uniq_homepages(self):
+ return frozenset(self.homepages)
+
@cached_property
def homepage(self):
"First homepage in list"
@@ -493,6 +499,9 @@ class Ebuild(ToStrMixin):
ret_list.append(StrThatIgnoreCase(lic))
return ret_list
+ def get_uniq_licenses(self):
+ return frozenset(self.licenses)
+
sha1 = cached_property(_file_hash("ebuild_path"), name = 'sha1')
mtime = cached_property(_file_mtime("ebuild_path"), name = 'mtime')
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-12 18:34 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-12 18:34 UTC (permalink / raw
To: gentoo-commits
commit: ad5103886839a96fa67b7108140b2d6350b19040
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 12 12:45:12 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 12 12:45:12 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=ad510388
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
+#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
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)
+ 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')
+class CategoryMetadata(object):
+
+ def __init__(self, metadata_path):
+ self._metadata_xml = etree.parse(metadata_path)
+ self._descrs = {}
+ self._parse_descrs()
+
+ def _parse_descrs(self):
+ for descr_xml in self._metadata_xml.iterfind('longdescription'):
+ lang = descr_xml.attrib.get('lang', 'en')
+ self._descrs[lang] = descr_xml.text
+
+ @property
+ def descrs(self):
+ return self._descrs
+
+ @property
+ def default_descr(self):
+ return self._descrs.get('en')
+
class Category(ToStrMixin):
"Represent category of portage tree as object"
- __slots__ = ('porttree', 'category')
+ __slots__ = ('porttree', 'category', '_cache')
def __init__(self, porttree, category):
"""Args:
@@ -276,6 +307,7 @@ class Category(ToStrMixin):
"""
self.porttree = porttree
self.category = category
+ self._cache = {}
def iter_packages(self):
packages = listdir(self.porttree.porttree + '/'+ self.category,
@@ -298,6 +330,14 @@ class Category(ToStrMixin):
return os.path.join(self.porttree.porttree_path, self.category)
@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
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-14 19:10 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-14 19:10 UTC (permalink / raw
To: gentoo-commits
commit: 0d1cacdb7f1b863dba7c7110aaf03e59c3169f7f
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Jun 14 18:14:02 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Jun 14 18:14:02 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=0d1cacdb
Fix bug in categories metadata
---
gpackages/libs/porttree.py | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index c33c159..0e4f352 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -275,9 +275,13 @@ class CategoryMetadata(ToStrMixin):
def __init__(self, metadata_path):
self._metadata_path = metadata_path
- self._metadata_xml = etree.parse(metadata_path)
self._descrs = {}
- self._parse_descrs()
+ try:
+ self._metadata_xml = etree.parse(metadata_path)
+ except IOError:
+ pass
+ else:
+ self._parse_descrs()
def _parse_descrs(self):
for descr_xml in self._metadata_xml.iterfind('longdescription'):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-18 21:26 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-18 21:26 UTC (permalink / raw
To: gentoo-commits
commit: 2a28d1f1ff674b2fdfe2cdbab28cd9e19e58635f
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 18 15:18:29 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 18 16:37:36 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=2a28d1f1
Add repo info layer
---
gpackages/libs/repo_info.py | 93 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/gpackages/libs/repo_info.py b/gpackages/libs/repo_info.py
new file mode 100644
index 0000000..4deee56
--- /dev/null
+++ b/gpackages/libs/repo_info.py
@@ -0,0 +1,93 @@
+# Layman API
+from layman.api import LaymanAPI
+layman_api = LaymanAPI()
+
+# Validators
+from validators import validate_url, validate_email, ValidationError
+
+__all__ = ('TreeMetadata',)
+
+def _gen_funct(name):
+ func = lambda self: self._dct.get(name)
+ func.__name__ = name
+ return func
+
+class TreeMetadataMetaclass(type):
+
+ def __init__(cls, name, bases, dct):
+ super(TreeMetadataMetaclass, cls).__init__(name, bases, dct)
+ for v in cls.simple_attrs:
+ setattr(cls, v, property(_gen_funct(v)))
+
+class TreeMetadata(object):
+ __metaclass__ = TreeMetadataMetaclass
+
+ simple_attrs = ( 'name', 'description', 'supported', 'owner_name',
+ 'official', 'irc'
+ )
+ statuses = {'official': 0, 'unofficial': 1}
+ qualities = {'stable': 0 , 'testing': 1, 'experimental': 2}
+
+ def __init__(self, repo_name, dct = None):
+ if dct is None:
+ dct = self._get_info(repo_name)
+
+ self._dct = dct
+
+ def _get_info(self, repo_name):
+ if repo_name != 'gentoo':
+ return layman_api.get_all_info(repo_name)[repo_name]
+ else:
+ return {'name': 'gentoo',
+ 'description': 'Gentoo main repository',
+ 'supported': True,
+ 'owner_name': None,
+ 'owner_email': None,
+ 'official': True,
+ 'irc': None,
+ 'homepage': 'http://gentoo.org/',
+ 'quality': 'stable',
+ 'status': 'official',
+ 'feeds': [],
+ }
+
+ @property
+ def int_status(self):
+ return self.statuses.get(self._dct['status'], 1)
+
+ @property
+ def homepage(self):
+ homepage = self._dct.get('homepage')
+ try:
+ validate_url(homepage)
+ except ValidationError:
+ return None
+ else:
+ return homepage
+
+ @property
+ def owner_email(self):
+ email = self._dct.get('owner_email')
+ try:
+ validate_email(email)
+ except ValidationError:
+ return None
+ else:
+ return email
+
+ @property
+ def feeds(self):
+ ret = []
+ for feed in self._dct.get('feeds', ()):
+ try:
+ validate_url(feed)
+ except ValidationError:
+ pass
+ else:
+ ret.append(feed)
+ return ret
+
+ @property
+ def int_quality(self):
+ return self.qualities.get(self._dct['quality'], 2)
+
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-18 21:26 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-18 21:26 UTC (permalink / raw
To: gentoo-commits
commit: 17490f6c41099108f5f5d7280044ddd1accfde08
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 18 15:18:09 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 18 15:18:09 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=17490f6c
Move validators to module
---
gpackages/libs/porttree.py | 5 +----
gpackages/libs/validators.py | 7 +++++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 0e4f352..995ef91 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -18,10 +18,7 @@ import os
from my_etree import etree
# Validators
-from django.core.validators import URLValidator, validate_email
-from django.core.exceptions import ValidationError
-
-validate_url = URLValidator()
+from validators import validate_url, validate_url, ValidationError
__all__ = ('Portage','PortTree', 'Category', 'Package', 'Ebuild')
diff --git a/gpackages/libs/validators.py b/gpackages/libs/validators.py
new file mode 100644
index 0000000..d86e7b8
--- /dev/null
+++ b/gpackages/libs/validators.py
@@ -0,0 +1,7 @@
+# Validators
+from django.core.validators import URLValidator, validate_email
+from django.core.exceptions import ValidationError
+
+validate_url = URLValidator()
+
+__all__ = ('validate_email', 'validate_url', 'ValidationError')
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-18 21:26 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-18 21:26 UTC (permalink / raw
To: gentoo-commits
commit: 34849f4bb9114c2921de17b5cd587353e8aa602a
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 18 21:25:55 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 18 21:25:55 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=34849f4b
Add repo_name checking
---
gpackages/libs/repo_info.py | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/gpackages/libs/repo_info.py b/gpackages/libs/repo_info.py
index cce3d4f..ac4b744 100644
--- a/gpackages/libs/repo_info.py
+++ b/gpackages/libs/repo_info.py
@@ -87,6 +87,7 @@ class TreeMetadata(ToStrMixin):
qualities = {'stable': 0 , 'testing': 1, 'experimental': 2}
def __init__(self, repo_name, dct = None):
+ repo_name = self._find_real_repo_name(repo_name)
self.repo_name = repo_name
if dct is None:
@@ -94,10 +95,24 @@ class TreeMetadata(ToStrMixin):
self._dct = dct
+ def _find_real_repo_name(self, repo_name):
+ gen_str = 'gentoo-'
+
+ if repo_name == 'gentoo':
+ return repo_name
+ elif layman_api.is_repo(repo_name):
+ return repo_name
+ elif layman_api.is_repo(gen_str + repo_name):
+ return gen_str + repo_name
+ elif repo_name.startswith(gen_str) and \
+ layman_api.is_repo(repo_name[len(gen_str):]):
+
+ return repo_name[len(gen_str):]
+
+ return None
+
def _get_info(self, repo_name):
- if repo_name != 'gentoo':
- return layman_api.get_all_info(repo_name)[repo_name]
- else:
+ if repo_name == 'gentoo':
return {'name': 'gentoo',
'description': 'Gentoo main repository',
'supported': True,
@@ -111,6 +126,12 @@ class TreeMetadata(ToStrMixin):
'feeds': [],
'sources': [],
}
+ elif repo_name is None:
+ return {'name': 'none',
+ 'description': None,
+ }
+ else:
+ return layman_api.get_all_info(repo_name)[repo_name]
@property
def int_status(self):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-20 23:23 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-20 23:23 UTC (permalink / raw
To: gentoo-commits
commit: ddba123a5a29de786959a5a548b89991738cb2fe
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jun 20 12:50:53 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jun 20 12:50:53 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=ddba123a
Refactor porttree
---
gpackages/libs/generic.py | 8 ++++-
gpackages/libs/porttree.py | 64 ++++++++++++++++++++++++--------------------
2 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index 409ec09..b8312c4 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -3,9 +3,13 @@ import hashlib
import types
from datetime import datetime
-__all__ = ('StrThatIgnoreCase', 'ToStrMixin', 'file_get_content', 'file_sha1', \
- 'file_mtime', 'cached_property' )
+__all__ = ('StrThatIgnoreCase', 'ToStrMixin', 'file_get_content', 'file_sha1',\
+ 'file_mtime', 'cached_property', 'iter_over_gen', 'lofstr_to_ig')
+def iter_over_gen(iterat, name):
+ for obj in iterat:
+ for item in getattr(obj, name)():
+ yield item
def del_from_dict(what_list, dict_todel):
for item in what_list:
if item in dict_todel:
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 75812ab..637e198 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -10,7 +10,9 @@ from gentoolkit.package import Package as PackageInfo
from gentoolkit.metadata import MetaData
from gentoolkit import errors
from generic import ToStrMixin, file_sha1, file_mtime, cached_property, \
- file_get_content, StrThatIgnoreCase, lofstr_to_ig
+ file_get_content, StrThatIgnoreCase, lofstr_to_ig, \
+ iter_over_gen
+
from use_info import get_uses_info, get_local_uses_info
import os
@@ -166,7 +168,27 @@ def _gen_all_use(func, iterator):
func(use_all_dict, use_dict)
return use_all_dict
-class Portage(object):
+
+def gen_generator_over_gen(gen_name, name):
+ return lambda self: iter_over_gen(getattr(self, gen_name)(), name)
+
+class IteratorAddMetaclass(type):
+
+ def __init__(cls, name, bases, dct):
+ super(IteratorAddMetaclass, cls).__init__(name, bases, dct)
+ for name in cls.generator_names:
+ setattr(cls, name, gen_generator_over_gen(cls.main_iterator, name))
+
+class AutoGeneratorMixin(object):
+
+ __metaclass__ = IteratorAddMetaclass
+ generator_names = ()
+ #main_iterator = 'generator_name'
+
+class Portage(ToStrMixin, AutoGeneratorMixin):
+
+ generator_names = ('iter_categories', 'iter_packages', 'iter_ebuilds')
+ main_iterator = 'iter_trees'
def __init__(self):
self.treemap = PORTDB.repositories.treemap
@@ -183,21 +205,6 @@ class Portage(object):
for tree_name in self.tree_order:
yield PortTree(tree_dict[tree_name], tree_name)
- 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():
- yield package
-
- def iter_ebuilds(self):
- for tree in self.iter_trees():
- for ebuild in tree.iter_ebuilds():
- yield ebuild
-
def iter_use_desc(self):
for tree in self.iter_trees():
yield tree.use_desc
@@ -224,9 +231,15 @@ class Portage(object):
def dict_repos(self):
return self.treemap
+ def __unicode__(self):
+ return u'portage'
+
-class PortTree(ToStrMixin):
+class PortTree(ToStrMixin, AutoGeneratorMixin):
"Represent portage tree as object"
+
+ main_iterator = 'iter_categories'
+ generator_names = ('iter_packages', 'iter_ebuilds')
def __init__(self, tree_path = '/usr/portage', name = 'main'):
"""Args:
@@ -241,16 +254,6 @@ class PortTree(ToStrMixin):
if os.path.isdir(os.path.join(self.porttree_path, category)):
yield Category(self, category)
- def iter_packages(self):
- for category in self.iter_categories():
- for package in category.iter_packages():
- yield package
-
- def iter_ebuilds(self):
- for package in self.iter_packages():
- for ebuild in package.iter_ebuilds():
- yield ebuild
-
def __unicode__(self):
return self.name
@@ -304,10 +307,13 @@ class CategoryMetadata(ToStrMixin):
return unicode(self._metadata_path)
-class Category(ToStrMixin):
+class Category(ToStrMixin, AutoGeneratorMixin):
"Represent category of portage tree as object"
__slots__ = ('porttree', 'category', '_cache')
+
+ main_iterator = 'iter_packages'
+ generator_names = ('iter_ebuilds', )
def __init__(self, porttree, category):
"""Args:
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-20 23:23 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-20 23:23 UTC (permalink / raw
To: gentoo-commits
commit: b178ac66b1bb8bba1cf5037076ca401784a19be5
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jun 20 17:28:48 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jun 20 17:28:48 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=b178ac66
Add basic pkgcore layer
---
gpackages/libs/pkgcore_porttree.py | 147 ++++++++++++++++++++++++++++++++++++
gpackages/libs/porttree.py | 4 +-
2 files changed, 149 insertions(+), 2 deletions(-)
diff --git a/gpackages/libs/pkgcore_porttree.py b/gpackages/libs/pkgcore_porttree.py
new file mode 100644
index 0000000..ac15e2f
--- /dev/null
+++ b/gpackages/libs/pkgcore_porttree.py
@@ -0,0 +1,147 @@
+from pkgcore.config import load_config
+from pkgcore.ebuild.repository import UnconfiguredTree, SlavedTree
+from pkgcore.util.repo_utils import get_raw_repos, get_virtual_repos
+from pkgcore.ebuild.atom import atom
+
+from generic import ToStrMixin
+
+from porttree import AutoGeneratorMixin
+
+import os.path
+
+
+class Portage(AutoGeneratorMixin):
+
+ generator_names = ('iter_categories', 'iter_packages', 'iter_ebuilds')
+ main_iterator = 'iter_trees'
+
+ def __init__(self):
+ self._config = load_config()
+ self._domains = self._config.domain
+ self._set_default_domain('livefs domain')
+ self._get_repos()
+
+ def _set_default_domain(self, domain_name):
+ domain = None
+ try:
+ domain = self._domains[domain_name]
+ except KeyError:
+ raise ValueError("Bad domain name - '%s'" % domain_name)
+ finally:
+ self._domain = domain
+
+ def _get_repos(self):
+ repo_dict = {}
+ repo_list = []
+ repos = get_virtual_repos(get_raw_repos(self._domain.repos), False)
+ for repo in repos:
+ if isinstance(repo, UnconfiguredTree) or isinstance(repo, SlavedTree):
+ repo_dict[repo.repo_id] = repo
+ repo_list.append(repo)
+ repo_list.reverse()
+ self.repo_list = repo_list
+ self.repo_dict = repo_dict
+
+ def iter_trees(self):
+ for tree in self.repo_list:
+ yield PortTree(tree)
+
+ def get_tree_by_name(self, tree_name):
+ if tree_name in self.repo_dict:
+ return PortTree(self.tree_dict[tree_name])
+ else:
+ raise ValueError
+
+class PortTree(ToStrMixin, AutoGeneratorMixin):
+
+ generator_names = ('iter_packages', 'iter_ebuilds')
+ main_iterator = 'iter_categories'
+
+ def __init__(self, repo_obj):
+ self._repo_obj = repo_obj
+ self.name = repo_obj.repo_id
+ self.categories = sorted(repo_obj.categories)
+
+ def iter_categories(self):
+ for category in self.categories:
+ yield Category(category, self)
+
+ @property
+ def porttree_path(self):
+ "Full path to portage tree"
+ return self._repo_obj.location
+
+ def __unicode__(self):
+ return self.name
+
+ @property
+ def _packages(self):
+ return self._repo_obj.packages
+
+ def _itermatch(self, res):
+ return self._repo_obj.itermatch(res)
+
+ @property
+ def _versions(self):
+ return self._repo_obj.versions
+
+class Category(ToStrMixin, AutoGeneratorMixin):
+
+ generator_names = ('iter_ebuilds', )
+ main_iterator = 'iter_packages'
+
+ def __init__(self, category_name, repo_obj):
+ self._repo_obj = repo_obj
+ self.name = category_name
+
+ def iter_packages(self):
+ for package_name in self._get_packages_names():
+ yield Package(package_name, self)
+
+ @property
+ def category_path(self):
+ "Full path to category"
+ return os.path.join(self.porttree_path, self.category)
+
+ def _get_packages_names(self):
+ return self._repo_obj._packages[self.name]
+
+ def _get_ebuilds_names_by_name(self, package_name):
+ return self._repo_obj._versions[(self.name, package_name)]
+
+ def __unicode__(self):
+ return self.name
+
+class Package(ToStrMixin):
+
+ def __init__(self, package_name, category_obj):
+ self.name = package_name
+ self.category_obj = category_obj
+
+ def iter_ebuilds(self):
+ for ebuild in self.category_obj._repo_obj._itermatch(atom(self.cp)):
+ yield Ebuild(ebuild, self)
+
+ def __unicode__(self):
+ return self.cp
+
+ def _get_ebuilds_versions(self):
+ return self.category_obj._get_ebuilds_names_by_name(self.name)
+
+ @property
+ def cp(self):
+ return '%s/%s' % (self.category_obj.name, self.name)
+
+
+class Ebuild(ToStrMixin):
+
+ def __init__(self, ebuild, package_obj):
+ self._ebuild = ebuild
+ self.package_obj = package_obj
+
+ def __unicode__(self):
+ return self.cpv
+
+ @property
+ def cpv(self):
+ return self._ebuild.cpvstr
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 637e198..8adb502 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -342,7 +342,7 @@ class Category(ToStrMixin, AutoGeneratorMixin):
@property
def category_path(self):
"Full path to category"
- return os.path.join(self.porttree.porttree_path, self.category)
+ return os.path.join(self.porttree_path, self.category)
@property
def metadata_path(self):
@@ -380,7 +380,7 @@ class Package(ToStrMixin):
yield ebuild_obj
def __unicode__(self):
- return '%s' % self.package
+ return unicode(self.cp)
@property
def package_path(self):
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/
@ 2012-06-20 23:23 Slava Bacherikov
0 siblings, 0 replies; 35+ messages in thread
From: Slava Bacherikov @ 2012-06-20 23:23 UTC (permalink / raw
To: gentoo-commits
commit: 8e5aaa4fd9b8b9a5ff4ff6aebedb1b60d49d1408
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jun 20 23:23:30 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jun 20 23:23:30 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=8e5aaa4f
Divide porttree to mixins
---
gpackages/libs/category_metadata.py | 49 ++++++
gpackages/libs/generic_objects.py | 92 ++++++++++
gpackages/libs/mixins.py | 194 +++++++++++++++++++++
gpackages/libs/porttree.py | 317 +++--------------------------------
4 files changed, 356 insertions(+), 296 deletions(-)
diff --git a/gpackages/libs/category_metadata.py b/gpackages/libs/category_metadata.py
new file mode 100644
index 0000000..a834895
--- /dev/null
+++ b/gpackages/libs/category_metadata.py
@@ -0,0 +1,49 @@
+from generic import ToStrMixin
+#XML
+from my_etree import etree
+
+__all__ = ('CategoryMetadata', )
+
+class CategoryMetadata(ToStrMixin):
+
+ def __init__(self, metadata_path):
+ self._metadata_path = metadata_path
+ self._descrs = {}
+ try:
+ self._metadata_xml = etree.parse(metadata_path)
+ except IOError:
+ pass
+ else:
+ self._parse_descrs()
+
+ def _parse_descrs(self):
+ for descr_xml in self._metadata_xml.iterfind('longdescription'):
+ lang = descr_xml.attrib.get('lang', 'en')
+ self._descrs[lang] = descr_xml.text
+
+ @property
+ def descrs(self):
+ return self._descrs
+
+ @property
+ def default_descr(self):
+ return self._descrs.get('en')
+
+ def __unicode__(self):
+ return unicode(self._metadata_path)
+
+
+class FakeMetaData(ToStrMixin):
+
+ def herds(self):
+ return []
+
+ def maintainers(self):
+ return []
+
+ def descriptions(self):
+ return []
+
+ def __unicode__(self):
+ return 'fake'
+
diff --git a/gpackages/libs/generic_objects.py b/gpackages/libs/generic_objects.py
new file mode 100644
index 0000000..1e82d3a
--- /dev/null
+++ b/gpackages/libs/generic_objects.py
@@ -0,0 +1,92 @@
+from generic import StrThatIgnoreCase, ToStrMixin
+from functools import total_ordering
+from collections import defaultdict
+
+__all__ = ('Use', 'Keyword', 'KeywordsSet')
+
+class Use(ToStrMixin):
+ "Represend Use flag as object"
+ __slots__ = ('name',)
+
+ def __init__(self, name):
+ """Args:
+ name -- name of use flag, may start with + or -
+ """
+ if name.startswith('+') or name.startswith('-'):
+ name = name[1:]
+ self.name = StrThatIgnoreCase(name)
+
+ def __unicode__(self):
+ return self.name
+
+ def __eq__(self, other):
+ return self.name == other.name
+
+ def __ne__(self, other):
+ return self.name != other.name
+
+ def __hash__(self):
+ return hash(self.name)
+
+@total_ordering
+class Keyword(ToStrMixin):
+ "Represend ebuild Keyword as object"
+ __slots__ = ('name', 'status')
+ status_repr = ['','~','-']
+
+ def __init__(self, name, status = 0):
+ """Args:
+ name -- name of keyword, it may start with ~ or -, if so than
+ status will be auto seting.
+ status -- status of keyword: 0 - stable,
+ 1 - utested '~',
+ 2 - unstable '-'
+ Also may get by name parameter.
+ """
+ if name.startswith('~'):
+ name = name[1:]
+ status = 1
+ elif name.startswith('-'):
+ name = name[1:]
+ status = 2
+ self.name = name
+ self.status = status
+
+ def __unicode__(self):
+ return self.status_repr[self.status] + self.name
+
+ def __hash__(self):
+ return hash((self.name, self.status))
+
+ def is_same(self, other):
+ return self.name == other.name
+
+ def is_higer(self, other):
+ return self.status < other.status
+
+ def is_lower(self, other):
+ return self.status > other.status
+
+ def __eq__(self, other):
+ return (self.arch, self.status) == (other.arch, other.status)
+
+ def __lt__(self, other):
+ return (self.status, self.arch) > (other.status, other.arch)
+
+ @property
+ def arch(self):
+ "Return arch name"
+ return self.name
+
+class KeywordsSet(set):
+ def __init__(self, init_list):
+ start = defaultdict(list)
+ for item in init_list:
+ start[item.arch].append(item)
+
+ to_create = []
+ for item in start.itervalues():
+ item.sort(reverse = True)
+ if len(item)>=1:
+ to_create.append(item[0])
+ super(KeywordsSet, self).__init__(to_create)
diff --git a/gpackages/libs/mixins.py b/gpackages/libs/mixins.py
new file mode 100644
index 0000000..3c35a3c
--- /dev/null
+++ b/gpackages/libs/mixins.py
@@ -0,0 +1,194 @@
+from generic import ToStrMixin, file_sha1, file_mtime, cached_property, \
+ file_get_content, iter_over_gen
+
+from use_info import get_uses_info, get_local_uses_info
+# Repo info
+from repo_info import TreeMetadata
+import os.path
+
+def _file_path(file_name):
+ return lambda self: os.path.join(self.package_path, file_name)
+
+def _file_hash(attr):
+ return lambda self: file_sha1(getattr(self, attr))
+
+def _file_mtime(attr):
+ return lambda self: file_mtime(getattr(self, attr))
+
+
+def gen_generator_over_gen(gen_name, name):
+ return lambda self: iter_over_gen(getattr(self, gen_name)(), name)
+
+class IteratorAddMetaclass(type):
+
+ def __init__(cls, name, bases, dct):
+ super(IteratorAddMetaclass, cls).__init__(name, bases, dct)
+ for name in cls.generator_names:
+ setattr(cls, name, gen_generator_over_gen(cls.main_iterator, name))
+
+class AutoGeneratorMixin(object):
+
+ __metaclass__ = IteratorAddMetaclass
+ generator_names = ()
+ #main_iterator = 'generator_name'
+
+
+class PortageBaseMixin(ToStrMixin):
+ def iter_use_desc(self):
+ for tree in self.iter_trees():
+ yield tree.use_desc
+
+ def iter_use_local_desc(self):
+ for tree in self.iter_trees():
+ yield tree.use_local_desc
+
+ def get_all_use_desc(self):
+ return _gen_all_use(lambda x,y: x.update(y), self.iter_use_desc())
+
+ def get_all_use_local_desc(self):
+ def action(all_dict, use_dict):
+ for key, value in use_dict.iteritems():
+ all_dict[key].update(value)
+
+ return _gen_all_use(action, self.iter_use_local_desc())
+
+ def __unicode__(self):
+ return u'portage'
+
+class PortageIteratorMixin(AutoGeneratorMixin):
+ main_iterator = 'iter_trees'
+ generator_names = ('iter_categories', 'iter_packages', 'iter_ebuilds')
+
+class PortTreeBaseMixin(ToStrMixin):
+
+ @cached_property
+ def metadata(self):
+ return TreeMetadata(self.name)
+
+ @cached_property
+ def use_desc(self):
+ return _get_info_by_func(get_uses_info,
+ self.porttree_path,
+ 'profiles/use.desc')
+
+ @cached_property
+ def use_local_desc(self):
+ return _get_info_by_func(get_local_uses_info,
+ self.porttree_path,
+ 'profiles/use.local.desc')
+
+ def __unicode__(self):
+ return self.name
+
+class PortTreeIteratorMixin(AutoGeneratorMixin):
+ main_iterator = 'iter_categories'
+ generator_names = ('iter_packages', 'iter_ebuilds')
+
+class MetaDataPath(object):
+
+ @property
+ def metadata_path(self):
+ raise NotImplementedError
+
+class CategoryBaseMixin(ToStrMixin):
+
+ @property
+ def metadata_path(self):
+ return os.path.join(self.category_path, 'metadata.xml')
+
+ @cached_property
+ def metadata_sha1(self):
+ return file_sha1(self.metadata_path)
+
+ @cached_property
+ def metadata(self):
+ return CategoryMetadata(self.metadata_path)
+
+ def __unicode__(self):
+ return self.name
+
+class CategoryIteratorMixin(AutoGeneratorMixin):
+ main_iterator = 'iter_packages'
+ generator_names = ('iter_ebuilds', )
+
+class PackageBaseMixin(ToStrMixin, MetaDataPath):
+
+ @cached_property
+ def metadata(self):
+ "Return `MetaData` object that represent package metadata.xml file"
+ try:
+ return MetaData( self.metadata_path)
+ except IOError:
+ return FakeMetaData()
+
+ @cached_property
+ def descriptions(self):
+ return self.metadata.descriptions()
+
+ @property
+ def description(self):
+ "Return first description in package metadata.xml"
+ if len(self.descriptions)>0:
+ return self.descriptions[0]
+ else:
+ return None
+ @property
+ def cp(self):
+ raise NotImplementedError
+
+ def __unicode__(self):
+ return unicode(self.cp)
+
+class PackageFilesMixin(object):
+ #Paths
+ manifest_path = property(_file_path('Manifest'))
+ changelog_path = property(_file_path('ChangeLog'))
+ metadata_path = property(_file_path('metadata.xml'))
+
+ #Hashes
+ manifest_sha1 = cached_property(_file_hash('manifest_path'),
+ name = 'manifest_sha1')
+ changelog_sha1 = cached_property(_file_hash('changelog_path'),
+ name = 'changelog_sha1')
+ metadata_sha1 = cached_property(_file_hash('metadata_path'),
+ name = 'metadata_sha1')
+
+ # Modify times
+ manifest_mtime = property(_file_mtime("manifest_path"))
+ changelog_mtime = property(_file_mtime("changelog_path"))
+ metadata_mtime = property(_file_mtime("metadata_path"))
+
+ mtime = property(_file_mtime("package_path"))
+
+ @cached_property
+ def changelog(self):
+ "Return ChangeLog content"
+ return file_get_content(self.changelog_path)
+
+class EbuildBaseMixin(ToStrMixin):
+
+ sha1 = cached_property(_file_hash("ebuild_path"), name = 'sha1')
+ mtime = cached_property(_file_mtime("ebuild_path"), name = 'mtime')
+
+ @property
+ def cpv(self):
+ raise NotImplementedError
+
+ def __unicode__(self):
+ return unicode(self.cpv)
+
+#Main mixins
+class PortageMixin(PortageBaseMixin, PortageIteratorMixin):
+ pass
+
+class PortTreeMixin(PortTreeBaseMixin, PortTreeIteratorMixin):
+ pass
+
+class CategoryMixin(CategoryBaseMixin, CategoryIteratorMixin):
+ pass
+
+class PackageMixin(PackageBaseMixin, PackageFilesMixin):
+ pass
+
+class EbuildMixin(EbuildBaseMixin):
+ pass
diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 8adb502..74a6e6e 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -1,5 +1,3 @@
-from functools import total_ordering
-from collections import defaultdict
import portage
from portage.util.listdir import listdir
from portage.dep import Atom
@@ -9,21 +7,21 @@ from portage.exception import PortageException, FileNotFound, InvalidAtom, \
from gentoolkit.package import Package as PackageInfo
from gentoolkit.metadata import MetaData
from gentoolkit import errors
-from generic import ToStrMixin, file_sha1, file_mtime, cached_property, \
- file_get_content, StrThatIgnoreCase, lofstr_to_ig, \
- iter_over_gen
+from generic import cached_property, lofstr_to_ig
-from use_info import get_uses_info, get_local_uses_info
-import os
+import os.path
-#XML
-from my_etree import etree
+#Generic objects
+from generic_objects import Use, Keyword, KeywordsSet
+
+#Mixins
+from mixins import PortageMixin, PortTreeMixin, CategoryMixin, PackageMixin, \
+ EbuildMixin
# Validators
from validators import validate_url, validate_url, ValidationError
-# Repo info
-from repo_info import TreeMetadata
+from category_metadata import CategoryMetadata, FakeMetaData
__all__ = ('Portage','PortTree', 'Category', 'Package', 'Ebuild')
@@ -37,16 +35,6 @@ _license_filter = lambda x: False if x.startswith('|') or x.startswith('(') or \
x.endswith('?') or x.startswith(')') \
else True
-def _file_path(file_name):
- return lambda self: os.path.join(self.package_path, file_name)
-
-
-def _file_hash(attr):
- return lambda self: file_sha1(getattr(self, attr))
-
-def _file_mtime(attr):
- return lambda self: file_mtime(getattr(self, attr))
-
def _ebuild_environment(name):
return lambda self: self.package_object.environment(name)
@@ -58,108 +46,6 @@ def _get_info_by_func(func, path1, path2):
except IOError:
return None
-class FakeMetaData(ToStrMixin):
-
- def herds(self):
- return []
-
- def maintainers(self):
- return []
-
- def descriptions(self):
- return []
-
- def __unicode__(self):
- return 'fake'
-
-
-class Use(ToStrMixin):
- "Represend Use flag as object"
- __slots__ = ('name',)
-
- def __init__(self, name):
- """Args:
- name -- name of use flag, may start with + or -
- """
- if name.startswith('+') or name.startswith('-'):
- name = name[1:]
- self.name = StrThatIgnoreCase(name)
-
- def __unicode__(self):
- return self.name
-
- def __eq__(self, other):
- return self.name == other.name
-
- def __ne__(self, other):
- return self.name != other.name
-
- def __hash__(self):
- return hash(self.name)
-
-@total_ordering
-class Keyword(ToStrMixin):
- "Represend ebuild Keyword as object"
- __slots__ = ('name', 'status')
- status_repr = ['','~','-']
-
- def __init__(self, name, status = 0):
- """Args:
- name -- name of keyword, it may start with ~ or -, if so than
- status will be auto seting.
- status -- status of keyword: 0 - stable,
- 1 - utested '~',
- 2 - unstable '-'
- Also may get by name parameter.
- """
- if name.startswith('~'):
- name = name[1:]
- status = 1
- elif name.startswith('-'):
- name = name[1:]
- status = 2
- self.name = name
- self.status = status
-
- def __unicode__(self):
- return self.status_repr[self.status] + self.name
-
- def __hash__(self):
- return hash((self.name, self.status))
-
- def is_same(self, other):
- return self.name == other.name
-
- def is_higer(self, other):
- return self.status < other.status
-
- def is_lower(self, other):
- return self.status > other.status
-
- def __eq__(self, other):
- return (self.arch, self.status) == (other.arch, other.status)
-
- def __lt__(self, other):
- return (self.status, self.arch) > (other.status, other.arch)
-
- @property
- def arch(self):
- "Return arch name"
- return self.name
-
-class KeywordsSet(set):
- def __init__(self, init_list):
- start = defaultdict(list)
- for item in init_list:
- start[item.arch].append(item)
-
- to_create = []
- for item in start.itervalues():
- item.sort(reverse = True)
- if len(item)>=1:
- to_create.append(item[0])
- super(KeywordsSet, self).__init__(to_create)
-
def _gen_all_use(func, iterator):
use_g = iterator
use_all_dict = next(use_g)
@@ -168,27 +54,7 @@ def _gen_all_use(func, iterator):
func(use_all_dict, use_dict)
return use_all_dict
-
-def gen_generator_over_gen(gen_name, name):
- return lambda self: iter_over_gen(getattr(self, gen_name)(), name)
-
-class IteratorAddMetaclass(type):
-
- def __init__(cls, name, bases, dct):
- super(IteratorAddMetaclass, cls).__init__(name, bases, dct)
- for name in cls.generator_names:
- setattr(cls, name, gen_generator_over_gen(cls.main_iterator, name))
-
-class AutoGeneratorMixin(object):
-
- __metaclass__ = IteratorAddMetaclass
- generator_names = ()
- #main_iterator = 'generator_name'
-
-class Portage(ToStrMixin, AutoGeneratorMixin):
-
- generator_names = ('iter_categories', 'iter_packages', 'iter_ebuilds')
- main_iterator = 'iter_trees'
+class Portage(PortageMixin):
def __init__(self):
self.treemap = PORTDB.repositories.treemap
@@ -205,24 +71,6 @@ class Portage(ToStrMixin, AutoGeneratorMixin):
for tree_name in self.tree_order:
yield PortTree(tree_dict[tree_name], tree_name)
- def iter_use_desc(self):
- for tree in self.iter_trees():
- yield tree.use_desc
-
- def iter_use_local_desc(self):
- for tree in self.iter_trees():
- yield tree.use_local_desc
-
- def get_all_use_desc(self):
- return _gen_all_use(lambda x,y: x.update(y), self.iter_use_desc())
-
- def get_all_use_local_desc(self):
- def action(all_dict, use_dict):
- for key, value in use_dict.iteritems():
- all_dict[key].update(value)
-
- return _gen_all_use(action, self.iter_use_local_desc())
-
@property
def list_repos(self):
return self.tree_order
@@ -231,16 +79,9 @@ class Portage(ToStrMixin, AutoGeneratorMixin):
def dict_repos(self):
return self.treemap
- def __unicode__(self):
- return u'portage'
-
-
-class PortTree(ToStrMixin, AutoGeneratorMixin):
+class PortTree(PortTreeMixin):
"Represent portage tree as object"
- main_iterator = 'iter_categories'
- generator_names = ('iter_packages', 'iter_ebuilds')
-
def __init__(self, tree_path = '/usr/portage', name = 'main'):
"""Args:
tree_path -- full path to portage tree as str
@@ -253,115 +94,48 @@ class PortTree(ToStrMixin, AutoGeneratorMixin):
for category in sorted(PORTDB.settings.categories):
if os.path.isdir(os.path.join(self.porttree_path, category)):
yield Category(self, category)
-
- def __unicode__(self):
- return self.name
@property
def porttree_path(self):
"Full path to portage tree"
return self.porttree
- @cached_property
- def metadata(self):
- return TreeMetadata(self.name)
-
- @cached_property
- def use_desc(self):
- return _get_info_by_func(get_uses_info,
- self.porttree_path,
- 'profiles/use.desc')
-
- @cached_property
- def use_local_desc(self):
- return _get_info_by_func(get_local_uses_info,
- self.porttree_path,
- 'profiles/use.local.desc')
-
-class CategoryMetadata(ToStrMixin):
-
- def __init__(self, metadata_path):
- self._metadata_path = metadata_path
- self._descrs = {}
- try:
- self._metadata_xml = etree.parse(metadata_path)
- except IOError:
- pass
- else:
- self._parse_descrs()
-
- def _parse_descrs(self):
- for descr_xml in self._metadata_xml.iterfind('longdescription'):
- lang = descr_xml.attrib.get('lang', 'en')
- self._descrs[lang] = descr_xml.text
-
- @property
- def descrs(self):
- return self._descrs
-
- @property
- def default_descr(self):
- return self._descrs.get('en')
-
- def __unicode__(self):
- return unicode(self._metadata_path)
-
-
-class Category(ToStrMixin, AutoGeneratorMixin):
+class Category(CategoryMixin):
"Represent category of portage tree as object"
__slots__ = ('porttree', 'category', '_cache')
- main_iterator = 'iter_packages'
- generator_names = ('iter_ebuilds', )
-
def __init__(self, porttree, category):
"""Args:
porttree -- PortTree object
category -- category name as str
"""
self.porttree = porttree
- self.category = category
+ self.name = category
self._cache = {}
def iter_packages(self):
- packages = listdir(self.porttree.porttree + '/'+ self.category,
+ packages = listdir(self.porttree.porttree + '/'+ self.name,
EmptyOnError=1, ignorecvs=1, dirsonly=1)
for package in packages:
try:
- atom = Atom(self.category + '/' + package)
+ atom = Atom(self.name + '/' + package)
except InvalidAtom:
continue
if atom != atom.cp:
continue
yield Package(self, atom)
- def __unicode__(self):
- return self.category
-
@property
def category_path(self):
"Full path to category"
- return os.path.join(self.porttree_path, self.category)
-
- @property
- def metadata_path(self):
- return os.path.join(self.category_path, 'metadata.xml')
-
- @cached_property
- def metadata_sha1(self):
- return file_sha1(self.metadata_path)
-
- @cached_property
- def metadata(self):
- return CategoryMetadata(self.metadata_path)
+ return os.path.join(self.porttree_path, self.name)
@property
def porttree_path(self):
return self.porttree.porttree
-
-class Package(ToStrMixin):
+class Package(PackageMixin):
"Represent package as object"
__slots__ = ('category', 'package', '_cache')
@@ -379,66 +153,20 @@ class Package(ToStrMixin):
if ebuild_obj.is_valid:
yield ebuild_obj
- def __unicode__(self):
- return unicode(self.cp)
-
@property
def package_path(self):
return os.path.join(self.category.porttree.porttree_path, self.package)
- @cached_property
- def metadata(self):
- "Return `MetaData` object that represent package metadata.xml file"
- try:
- return MetaData( self.metadata_path)
- except IOError:
- return FakeMetaData()
-
@property
def cp(self):
return self.package
- mtime = property(_file_mtime("package_path"))
-
@property
def name(self):
return self.package.split('/')[1]
- manifest_path = property(_file_path('Manifest'))
- changelog_path = property(_file_path('ChangeLog'))
- metadata_path = property(_file_path('metadata.xml'))
-
- #Hashes
- manifest_sha1 = cached_property(_file_hash('manifest_path'),
- name = 'manifest_sha1')
- changelog_sha1 = cached_property(_file_hash('changelog_path'),
- name = 'changelog_sha1')
- metadata_sha1 = cached_property(_file_hash('metadata_path'),
- name = 'metadata_sha1')
- # Modify times
- manifest_mtime = property(_file_mtime("manifest_path"))
- changelog_mtime = property(_file_mtime("changelog_path"))
- metadata_mtime = property(_file_mtime("metadata_path"))
-
- @cached_property
- def descriptions(self):
- return self.metadata.descriptions()
-
- @property
- def description(self):
- "Return first description in package metadata.xml"
- if len(self.descriptions)>0:
- return self.descriptions[0]
- else:
- return None
-
- @cached_property
- def changelog(self):
- "Return ChangeLog content"
- return file_get_content(self.changelog_path)
-
-class Ebuild(ToStrMixin):
+class Ebuild(EbuildMixin):
"Represent ebuild as object"
__slots__ = ('package', 'ebuild', 'package_object', '_cache')
@@ -572,9 +300,6 @@ class Ebuild(ToStrMixin):
def licenses(self):
return tuple(set(lofstr_to_ig(self._licenses)))
- sha1 = cached_property(_file_hash("ebuild_path"), name = 'sha1')
- mtime = cached_property(_file_mtime("ebuild_path"), name = 'mtime')
-
- def __unicode__(self):
- return self.ebuild
-
+ @property
+ def cpv(self):
+ return self.package
^ permalink raw reply related [flat|nested] 35+ messages in thread
end of thread, other threads:[~2012-06-20 23:24 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-05 20:48 [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/libs/ Slava Bacherikov
-- strict thread matches above, loose matches on Subject: below --
2012-06-20 23:23 Slava Bacherikov
2012-06-20 23:23 Slava Bacherikov
2012-06-20 23:23 Slava Bacherikov
2012-06-18 21:26 Slava Bacherikov
2012-06-18 21:26 Slava Bacherikov
2012-06-18 21:26 Slava Bacherikov
2012-06-14 19:10 Slava Bacherikov
2012-06-12 18:34 Slava Bacherikov
2012-06-12 18:34 Slava Bacherikov
2012-06-10 17:51 Slava Bacherikov
2012-06-09 18:19 Slava Bacherikov
2012-06-09 18:19 Slava Bacherikov
2012-06-07 22:48 Slava Bacherikov
2012-06-07 22:48 Slava Bacherikov
2012-06-07 22:48 Slava Bacherikov
2012-06-06 22:48 Slava Bacherikov
2012-06-05 21:46 Slava Bacherikov
2012-06-05 15:49 Slava Bacherikov
2012-06-05 15:49 Slava Bacherikov
2012-06-04 22:18 Slava Bacherikov
2012-06-04 16:16 Slava Bacherikov
2012-06-04 16:16 Slava Bacherikov
2012-06-03 19:34 Slava Bacherikov
2012-06-03 16:19 Slava Bacherikov
2012-06-03 13:19 Slava Bacherikov
2012-06-03 13:19 Slava Bacherikov
2012-06-02 16:04 Slava Bacherikov
2012-06-01 21:28 Slava Bacherikov
2012-06-01 21:28 Slava Bacherikov
2012-05-31 15:28 Slava Bacherikov
2012-05-31 15:28 Slava Bacherikov
2012-05-29 21:34 Slava Bacherikov
2012-05-29 13:38 Slava Bacherikov
2012-05-28 17:00 Slava Bacherikov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox