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/pms-test-suite:master commit in: PMSTestSuite/pm/, PMSTestSuite/
Date: Wed, 15 Jun 2011 16:14:42 +0000 (UTC)	[thread overview]
Message-ID: <c2f6c681873303539a272422908edc9888249e86.mgorny@gentoo> (raw)

commit:     c2f6c681873303539a272422908edc9888249e86
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 15 14:40:56 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Jun 15 15:20:20 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=c2f6c681

Start implementing a new PM API.

The new PM API allows queueing packages before running the actual
operation (merge/unmerge).

---
 PMSTestSuite/cli.py          |    3 +-
 PMSTestSuite/pm/__init__.py  |   67 +++++++++++++++++++++++++++++++++++-------
 PMSTestSuite/pm/pkgcorepm.py |   17 ++--------
 PMSTestSuite/pm/portagepm.py |   17 ++--------
 4 files changed, 66 insertions(+), 38 deletions(-)

diff --git a/PMSTestSuite/cli.py b/PMSTestSuite/cli.py
index 5820ec7..6f98225 100644
--- a/PMSTestSuite/cli.py
+++ b/PMSTestSuite/cli.py
@@ -142,7 +142,7 @@ class PMSTestSuiteCLI(object):
 			pkgs = self.package_queue
 			self.package_queue = []
 
-		gobject.child_watch_add(self.pm.merge_async(pkgs),
+		gobject.child_watch_add(self.pm._spawn_merge(pkgs).pid,
 				self.merge_done)
 
 	def main(self, argv):
@@ -164,6 +164,7 @@ class PMSTestSuiteCLI(object):
 		if installedcpvs:
 			print('-> Unmerging already-merged test ebuilds...')
 			self.pm.unmerge(installedcpvs)
+			self.pm.commit()
 			installedcpvs = self.pm.lookup_vardb(self.cpvs)
 			if installedcpvs:
 				print('Failed to unmerge the following test ebuilds:')

diff --git a/PMSTestSuite/pm/__init__.py b/PMSTestSuite/pm/__init__.py
index c58deaa..3172a1d 100644
--- a/PMSTestSuite/pm/__init__.py
+++ b/PMSTestSuite/pm/__init__.py
@@ -10,6 +10,10 @@ True
 '...'
 """
 
+class PackageManagerOps:
+	merge = 0
+	unmerge = 1
+
 class PackageManager(object):
 	"""
 	Base class for various package managers support.
@@ -17,6 +21,8 @@ class PackageManager(object):
 
 	pm_options = []
 	repo_paths = []
+	pkg_queue = []
+	_current_op = None
 
 	@property
 	def name(self):
@@ -69,25 +75,64 @@ class PackageManager(object):
 		"""
 		raise NotImplementedError('Please override the get_repository() method.')
 
+	@property
+	def op(self):
+		return self._current_op
+
+	@op.setter
+	def op(self, op):
+		if self._current_op is not None:
+			if self._current_op == op:
+				return
+			raise Exception('Please commit the pending operation first.')
+		self._current_op = op
+
+	@op.deleter
+	def op(self):
+		self._current_op = None
+		self.pkg_queue = []
+
 	def merge(self, cpvs):
 		"""
-		Run PM to merge <cpvs>.
-
-		Returns True if PM run successfully, False otherwise. Please note that
-		this return code may not have anything to do with ebuilds actually
-		getting merged.
+		Queue merging <cpvs> (either a list or a string).
 		"""
-		raise NotImplementedError('Please override the merge() method.')
+		self.op = PackageManagerOps.merge
+		self.pkg_queue.extend(cpvs)
 
 	def unmerge(self, cpvs):
 		"""
-		Run PM to unmerge <cpvs>.
+		Queue unmerging <cpvs> (either a list or a string).
+		"""
+		self.op = PackageManagerOps.unmerge
+		self.pkg_queue.extend(cpvs)
+
+	def _spawn_merge(self, pkgs):
+		"""
+		Spawn PM to perform merge of <pkgs>. Returns a subprocess.
+		"""
+		raise NotImplementedError('Please override _spawn_merge()')
+
+	def _spawn_unmerge(self, pkgs):
+		"""
+		Spawn PM to perform unmerge of <pkgs>. Returns a subprocess.
+		"""
+		raise NotImplementedError('Please override _spawn_unmerge()')
 
-		Returns True if PM run successfully, False otherwise. Please note that
-		this return code may not have anything to do with ebuilds actually
-		getting removed.
+	def commit(self):
 		"""
-		raise NotImplementedError('Please override the unmerge() method.')
+		Perform queued operations, starting PM multiple times if necessary.
+		Block execution until done.
+		"""
+
+		if self.op == PackageManagerOps.merge:
+			subp = self._spawn_merge(self.pkg_queue)
+		elif self.op == PackageManagerOps.unmerge:
+			subp = self._spawn_unmerge(self.pkg_queue)
+		else:
+			raise AssertionError('PackageManager.op unmatched')
+
+		subp.wait()
+		del self.op
 
 	def lookup_vardb(self, cpvs):
 		"""

diff --git a/PMSTestSuite/pm/pkgcorepm.py b/PMSTestSuite/pm/pkgcorepm.py
index 7e85cc1..a29f1bd 100644
--- a/PMSTestSuite/pm/pkgcorepm.py
+++ b/PMSTestSuite/pm/pkgcorepm.py
@@ -45,20 +45,11 @@ class PkgCorePM(PortagePM):
 				+ self.common_pmerge_opts + opts + self.pm_options
 				+ ['=%s' % cpv for cpv in cpvs])
 
-	def call_pmerge(self, *args, **kwargs):
-		p = self.spawn_pmerge(*args, **kwargs)
-		return p.wait()
+	def _spawn_merge(self, cpvs):
+		return self.spawn_pmerge(cpvs)
 
-	def merge(self, cpvs):
-		ret = self.call_pmerge(cpvs)
-		return ret == 0
-
-	def unmerge(self, cpvs):
-		ret = self.call_pmerge(cpvs, ['--unmerge'])
-		return ret == 0
-
-	def merge_async(self, cpvs):
-		return self.spawn_pmerge(cpvs).pid
+	def _spawn_unmerge(self, cpvs):
+		return self.spawn_pmerge(cpvs, ['--unmerge'])
 
 	def append_repository(self, repo):
 		raise NotImplementedError('PkgCorePM does not support adding repositories yet.')

diff --git a/PMSTestSuite/pm/portagepm.py b/PMSTestSuite/pm/portagepm.py
index 66310f4..7d6c6a5 100644
--- a/PMSTestSuite/pm/portagepm.py
+++ b/PMSTestSuite/pm/portagepm.py
@@ -57,20 +57,11 @@ class PortagePM(PackageManager):
 				+ ['=%s' % cpv for cpv in cpvs],
 				**kwargs)
 
-	def call_emerge(self, *args, **kwargs):
-		p = self.spawn_emerge(*args, **kwargs)
-		return p.wait()
+	def _spawn_merge(self, cpvs):
+		return self.spawn_emerge(cpvs)
 
-	def merge(self, cpvs):
-		ret = self.call_emerge(cpvs)
-		return ret == 0
-
-	def unmerge(self, cpvs):
-		ret = self.call_emerge(cpvs, ['--unmerge'])
-		return ret == 0
-
-	def merge_async(self, cpvs):
-		return self.spawn_emerge(cpvs).pid
+	def _spawn_unmerge(self, cpvs):
+		return self.spawn_emerge(cpvs, ['--unmerge'])
 
 	_vardb = None
 	_portdb = None



             reply	other threads:[~2011-06-15 16:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-15 16:14 Michał Górny [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-06-16 17:22 [gentoo-commits] proj/pms-test-suite:master commit in: PMSTestSuite/pm/, PMSTestSuite/ Michał Górny
2011-06-16 17:22 Michał Górny
2011-06-15 16:14 Michał Górny
2011-06-11  6:32 Michał Górny
2011-06-06  7:29 Michał Górny
2011-05-31 12:14 Michał Górny
2011-05-31 12:14 Michał Górny
2011-05-31  8:10 Michał Górny
2011-05-31  8:10 Michał Górny
2011-05-29 18:57 Michał Górny
2011-05-29 18:57 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=c2f6c681873303539a272422908edc9888249e86.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