From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/portagepm/
Date: Fri, 15 Jul 2011 08:39:54 +0000 (UTC) [thread overview]
Message-ID: <d96f83f3a431c47a8c025e8978d07b5970ecf0ee.mgorny@gentoo> (raw)
commit: d96f83f3a431c47a8c025e8978d07b5970ecf0ee
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 07:11:20 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 08:37:33 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=d96f83f3
Portage: use match() / xmatch() for faster Atom matching.
---
gentoopm/portagepm/repo.py | 112 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 111 insertions(+), 1 deletions(-)
diff --git a/gentoopm/portagepm/repo.py b/gentoopm/portagepm/repo.py
index 87d8edc..c8e55f5 100644
--- a/gentoopm/portagepm/repo.py
+++ b/gentoopm/portagepm/repo.py
@@ -5,9 +5,14 @@
import os.path
+import portage.exception as pe
+from portage.versions import catsplit
+
from gentoopm.basepm.repo import PMRepositoryDict, PMEbuildRepository, \
PMRepository
-from gentoopm.portagepm.pkg import PortageCPV, PortageDBCPV, PortagePackageSet
+from gentoopm.portagepm.atom import PortageAtom, CompletePortageAtom
+from gentoopm.portagepm.pkg import PortageCPV, PortageDBCPV, PortagePackageSet, \
+ PortageFilteredPackageSet
class PortageRepoDict(PMRepositoryDict):
def __iter__(self):
@@ -29,6 +34,38 @@ class PortageRepoDict(PMRepositoryDict):
def __init__(self, portdbapi):
self._dbapi = portdbapi
+class PortageFilteredDBRepo(PortageFilteredPackageSet):
+ def __init__(self, repo, atom):
+ self._dbapi = repo._dbapi
+ self._atom = atom._atom
+
+ @property
+ def _stringified_atom(self):
+ a = str(self._atom)
+ return a.replace('null/', '')
+
+ def __iter__(self):
+ a = self._stringified_atom
+ try:
+ it = self._dbapi.match(a)
+ except pe.AmbiguousPackageName as e:
+ for pkgcand in e.args[0]:
+ for p in PortageHackedFilteredDBRepo(self, pkgcand):
+ yield p
+ else:
+ for p in it:
+ yield PortageDBCPV(p, self._dbapi)
+
+class PortageHackedFilteredDBRepo(PortageFilteredDBRepo):
+ def __init__(self, repo, pkgcand):
+ cat = catsplit(pkgcand)[0]
+ self._atom = str(repo._atom).replace('null/', '%s/' % cat)
+ self._dbapi = repo._dbapi
+
+ @property
+ def _stringified_atom(self):
+ return self._atom
+
class PortDBRepository(PortagePackageSet, PMRepository):
def __init__(self, dbapi):
self._dbapi = dbapi
@@ -37,6 +74,77 @@ class PortDBRepository(PortagePackageSet, PMRepository):
for p in self._dbapi.cpv_all(): # XXX
yield PortageDBCPV(p, self._dbapi)
+ _filtered_subclass = PortageFilteredDBRepo
+ def filter(self, *args, **kwargs):
+ newargs = []
+ filt = None
+ for a in args:
+ if isinstance(a, basestring):
+ a = PortageAtom(a)
+ if isinstance(a, CompletePortageAtom) and filt is None:
+ filt = a
+ else:
+ newargs.append(a)
+
+ pset = self
+ if filt:
+ pset = self._filtered_subclass(pset, filt)
+ if newargs or kwargs:
+ pset = PortageFilteredPackageSet(pset, newargs, kwargs)
+ return pset
+
+class PortageFilteredRepo(PortageFilteredDBRepo):
+ def __init__(self, repo, atom):
+ PortageFilteredDBRepo.__init__(self, repo, atom)
+ self._name = repo.name
+ self._path = repo.path
+ self._prio = repo._repo.priority
+
+ def __iter__(self):
+ if self._atom.repo is not None:
+ if self._atom.repo != self._name:
+ return
+ a = self._stringified_atom
+ else:
+ a = '%s::%s' % (self._stringified_atom, self._name)
+
+ try:
+ it = self._dbapi.xmatch("match-all", a)
+ except pe.AmbiguousPackageName as e:
+ for pkgcand in e.args[0]:
+ for p in PortageHackedFilteredRepo(self, pkgcand):
+ yield p
+ else:
+ for p in it:
+ yield PortageCPV(p, self._dbapi, self._path, self._prio)
+
+class PortageHackedAtom(object):
+ def __init__(self, s, repo):
+ self._s = s
+ self._repo = repo
+
+ @property
+ def repo(self):
+ return self._repo
+
+ def __str__(self):
+ return self._s
+
+class PortageHackedFilteredRepo(PortageFilteredRepo):
+ def __init__(self, repo, pkgcand):
+ cat = catsplit(pkgcand)[0]
+ self._atom = PortageHackedAtom(
+ str(repo._atom).replace('null/', '%s/' % cat),
+ repo._atom.repo)
+ self._dbapi = repo._dbapi
+ self._path = repo._path
+ self._prio = repo._prio
+ self._name = repo._name
+
+ @property
+ def _stringified_atom(self):
+ return str(self._atom)
+
class PortageRepository(PortDBRepository, PMEbuildRepository):
def __init__(self, repo_obj, portdbapi):
self._repo = repo_obj
@@ -49,6 +157,8 @@ class PortageRepository(PortDBRepository, PMEbuildRepository):
for p in self._dbapi.cp_list(cp, mytree = path):
yield PortageCPV(p, self._dbapi, path, prio)
+ _filtered_subclass = PortageFilteredRepo
+
@property
def name(self):
return self._repo.name
next reply other threads:[~2011-07-15 8:40 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-15 8:39 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-02-16 10:13 [gentoo-commits] proj/gentoopm:master commit in: gentoopm/portagepm/ Michał Górny
2013-02-03 19:40 Michał Górny
2012-12-10 17:52 Michał Górny
2011-08-15 7:57 Michał Górny
2011-08-14 14:22 Michał Górny
2011-08-12 7:28 Michał Górny
2011-07-28 16:24 Michał Górny
2011-07-28 16:24 Michał Górny
2011-07-27 16:04 Michał Górny
2011-07-27 8:26 Michał Górny
2011-07-26 17:30 Michał Górny
2011-07-26 17:18 Michał Górny
2011-07-25 17:06 Michał Górny
2011-07-21 8:47 Michał Górny
2011-07-21 8:47 Michał Górny
2011-07-20 9:41 Michał Górny
2011-07-19 20:53 Michał Górny
2011-07-19 20:53 Michał Górny
2011-07-19 20:53 Michał Górny
2011-07-19 20:53 Michał Górny
2011-07-15 13:32 Michał Górny
2011-07-15 12:34 Michał Górny
2011-07-14 14:05 Michał Górny
2011-07-14 13:31 Michał Górny
2011-07-10 22:17 Michał Górny
2011-07-10 22:17 Michał Górny
2011-07-10 22:17 Michał Górny
2011-07-08 7:18 Michał Górny
2011-07-07 9:51 Michał Górny
2011-07-06 20:54 Michał Górny
2011-07-06 16:03 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d96f83f3a431c47a8c025e8978d07b5970ecf0ee.mgorny@gentoo \
--to=mgorny@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox