public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: gentoopm/portagepm/, gentoopm/paludispm/
Date: Thu,  7 Jul 2011 15:55:55 +0000 (UTC)	[thread overview]
Message-ID: <0411159cece7017e714c2ba8298b0962f1a7be88.mgorny@gentoo> (raw)

commit:     0411159cece7017e714c2ba8298b0962f1a7be88
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jul  7 15:56:34 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jul  7 15:56:34 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=0411159c

Support creating atoms in portage & paludis.

---
 gentoopm/paludispm/__init__.py |    4 ++--
 gentoopm/paludispm/atom.py     |   20 ++++++++++++++++++--
 gentoopm/portagepm/__init__.py |    4 ++--
 gentoopm/portagepm/atom.py     |   27 +++++++++++++++++++++++++--
 4 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/gentoopm/paludispm/__init__.py b/gentoopm/paludispm/__init__.py
index 3a70297..060eb2b 100644
--- a/gentoopm/paludispm/__init__.py
+++ b/gentoopm/paludispm/__init__.py
@@ -3,7 +3,7 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
-import paludis
+import functools, paludis
 
 from gentoopm.basepm import PackageManager
 from gentoopm.paludispm.atom import PaludisAtom
@@ -30,4 +30,4 @@ class PaludisPM(PackageManager):
 
 	@property
 	def Atom(self):
-		return PaludisAtom
+		return functools.partial(PaludisAtom, pm = self)

diff --git a/gentoopm/paludispm/atom.py b/gentoopm/paludispm/atom.py
index 541470a..5e1949d 100644
--- a/gentoopm/paludispm/atom.py
+++ b/gentoopm/paludispm/atom.py
@@ -3,7 +3,23 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
+import paludis
+
 from gentoopm.basepm.atom import PMAtom
 
-class PkgCoreAtom(PMAtom):
-	pass
+class PaludisAtom(PMAtom):
+	def __init__(self, s, pm):
+		try:
+			self._atom = paludis.parse_user_package_dep_spec(
+					s, pm._env,
+					paludis.UserPackageDepSpecOptions(),
+					paludis.Filter.All())
+		except (paludis.BadVersionOperatorError, paludis.PackageDepSpecError):
+			raise ValueError('Incorrect atom: %s' % s)
+		except paludis.AmbiguousPackageNameError:
+			raise KeyError('Ambiguous atom: %s' % s)
+		except paludis.NoSuchPackageError:
+			raise KeyError('Unable to expand atom: %s' % s)
+
+	def __contains__(self, pkg):
+		raise NotImplementedError('Direct atom matching not implemented in Paludis')

diff --git a/gentoopm/portagepm/__init__.py b/gentoopm/portagepm/__init__.py
index 2ee6bf9..4b1887a 100644
--- a/gentoopm/portagepm/__init__.py
+++ b/gentoopm/portagepm/__init__.py
@@ -3,7 +3,7 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
-import os
+import functools, os
 from portage import create_trees
 
 from gentoopm.basepm import PackageManager
@@ -32,4 +32,4 @@ class PortagePM(PackageManager):
 
 	@property
 	def Atom(self):
-		return PortageAtom
+		return functools.partial(PortageAtom, pm = self)

diff --git a/gentoopm/portagepm/atom.py b/gentoopm/portagepm/atom.py
index 541470a..5c5ca69 100644
--- a/gentoopm/portagepm/atom.py
+++ b/gentoopm/portagepm/atom.py
@@ -3,7 +3,30 @@
 # (c) 2011 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 2-clause BSD license.
 
+import portage.exception as pe
+from portage.dbapi.dep_expand import dep_expand
+from portage.dep import Atom, match_from_list
+from portage.versions import catsplit
+
 from gentoopm.basepm.atom import PMAtom
 
-class PkgCoreAtom(PMAtom):
-	pass
+class PortageAtom(PMAtom):
+	def __init__(self, s, pm):
+		try:
+			a = dep_expand(s, mydb = pm._portdb,
+					settings = pm._portdb.settings)
+		except pe.AmbiguousPackageName:
+			raise KeyError('Ambiguous atom: %s' % s)
+		except pe.InvalidAtom:
+			raise ValueError('Incorrect atom: %s' % s)
+
+		if catsplit(a.cp)[0] == 'null':
+			raise KeyError('Unable to expand atom: %s' % s)
+		self._atom = a
+
+	def __contains__(self, pkg):
+		# SLOT matching requires metadata so delay it.
+		if not match_from_list(self._atom, [pkg.id]):
+			return False
+		return not self._atom.slot \
+				or self._atom.slot == pkg.metadata.SLOT



             reply	other threads:[~2011-07-07 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-07 15:55 Michał Górny [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-07-16 22:55 [gentoo-commits] proj/gentoopm:master commit in: gentoopm/portagepm/, gentoopm/paludispm/ Michał Górny
2011-07-23  9:27 Michał Górny
2011-08-13  9:17 Michał Górny
2011-08-13 10:54 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=0411159cece7017e714c2ba8298b0962f1a7be88.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