public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
Date: Thu,  5 Jun 2014 22:09:12 +0000 (UTC)	[thread overview]
Message-ID: <1399426483.5df0c6b4892aa5ea2a98c59e56be34aac8ea3301.dywi@gentoo> (raw)

commit:     5df0c6b4892aa5ea2a98c59e56be34aac8ea3301
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed May  7 01:34:43 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed May  7 01:34:43 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=5df0c6b4

DepresInterface: push/pop pools, handle rule objects

---
 roverlay/interface/depres.py | 112 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 90 insertions(+), 22 deletions(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index c7ba95c..ae005e8 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -9,6 +9,7 @@
 import errno
 
 import roverlay.interface.generic
+import roverlay.interface.root
 
 
 import roverlay.depres.channels
@@ -29,7 +30,8 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    This class provides:
 
    * rule creation (from text/text files)
-   * manage dependency rule pools (stack-like discard_pool()/get_new_pool())
+   * manage dependency rule pools
+      (stack-like discard_pool()/get_[new_]pool(), pop_pool()/push_pool())
    * resolve dependencies:
    -> do_resolve(<deps>) for "raw" depres results
    -> resolve(<deps>) for generic purpose results (list of resolved deps)
@@ -43,9 +45,11 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
 
    GREEDY_DEPRES_CHANNEL    = roverlay.depres.channels.EbuildJobChannel
    NONGREEDY_DEPRES_CHANNEL = roverlay.depres.channels.NonGreedyDepresChannel
+   ROOT_INTERFACE_CLS       = roverlay.interface.root.RootInterface
+
 
    def __init__ ( self, parent_interface, greedy=None, want_tuple=False ):
-      """Initializes the depdency resolution interface.
+      """Initializes the dependency resolution interface.
 
       arguments:
       * parent_interface -- parent interface that provides shared functionality
@@ -179,6 +183,38 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
          return self.get_new_pool ( force=True )
    # --- end of get_pool (...) ---
 
+   def _add_pool ( self, pool ):
+      """Pushes a rule pool back to the poolstack, making it the topmost one.
+
+      Returns: None (implicit)
+
+      arguments:
+      * pool -- a dependency rule pool
+      """
+      self._pool_id += 1
+      try:
+         self._poolstack.append ( pool )
+      except:
+         self._pool_id -= 1
+         raise
+
+      self._update_resolver()
+   # --- end of _add_pool (...) ---
+
+   def push_pool ( self, pool ):
+      """Pushes a rule pool back to the poolstack, making it the topmost one.
+
+      Returns: topmost rule pool (should be the given pool)
+
+      arguments:
+      * pool -- a dependency rule pool
+      """
+      # COULDFIX: pool name possibly not unique when reinserting pools
+      assert isinstance ( pool, roverlay.depres.simpledeprule.pool.SimpleDependencyRulePool )
+      self._add_pool ( pool )
+      return self._poolstack[-1]
+   # --- end of push_pool (...) ---
+
    def get_new_pool ( self, force=False, with_deptype=DEFAULT_DEPTYPE ):
       """Creates a new pool, adds it to the pool stack and returns it.
 
@@ -188,36 +224,38 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       * with_deptype -- dependency type of the new pool (optional)
       """
       if force or not self._poolstack or not self._poolstack[-1].empty():
-         self._pool_id += 1
-         try:
-            pool = roverlay.depres.simpledeprule.pool.SimpleDependencyRulePool (
+         self._add_pool (
+            roverlay.depres.simpledeprule.pool.SimpleDependencyRulePool (
                "pool" + str ( self._pool_id ),
-               deptype_mask=DEFAULT_DEPTYPE
+               deptype_mask=with_deptype
             )
-            self.poolstack.append ( pool )
-         except:
-            self._pool_id -= 1
-            raise
-
-         self._update_resolver()
+         )
       # -- end if force or ...
       return self._poolstack[-1]
    # --- end of get_new_pool (...) ---
 
+   def pop_pool ( self ):
+      """Discards the topmost rule pool and returns it.
+
+      Returns: dependency rule pool or None (=no pool removed).
+      """
+      try:
+         pool = self._poolstack.pop()
+      except IndexError:
+         # poolstack is empty
+         return None
+
+      self._pool_id -= 1
+      assert self._pool_id >= -1, self._pool_id
+      return pool
+   # --- end of pop_pool (...) ---
+
    def discard_pool ( self ):
       """Discards the topmost rule pool.
 
       Returns: True if a pool has been removed, else False.
       """
-      try:
-         self._poolstack.pop()
-         self._pool_id -= 1
-         assert self._pool_id >= -1, self._pool_id
-         return True
-      except AssertionError:
-         raise
-      except:
-         return False
+      return self.pop_pool() is not None
    # --- end of discard_pool (...) ---
 
    def discard_pools ( self, count ):
@@ -310,6 +348,36 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       return True if ret is None else ret
    # --- end of load_rule_files (...) ---
 
+   def add_rule_objects ( self, rules ):
+      """Adds SimpleDependencyRule objects to the topmost rule pool.
+
+      update() has to be called manually.
+
+      Returns: True
+
+      arguments:
+      * rule_objects -- iterable containing dependency rules
+      """
+      pool = self.get_pool()
+      # pool validates the rules' type
+      for deprule in rules:
+         pool.add ( deprule )
+      return True
+   # --- end of add_rule_objects (...) ---
+
+   def add_rule_object ( self, rule ):
+      """Adds a single SimpleDependencyRule object to the topmost rule pool.
+
+      update() has to be called manually.
+
+      arguments:
+      * rule -- dependency rule
+      """
+      # the rule pool validates the rule's type
+      self.get_pool().add ( rule )
+      return True
+   # --- end of add_rule_object (...) ---
+
    def add_rule ( self, rule_str ):
       """Sends a text line to the rule parser.
 
@@ -395,7 +463,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
          return True
       except:
          if new_pool:
-            # this could discard (previosly) empty pools, too
+            # this could discard (previously) empty pools, too
             #  (side-effect of "optimizations" in get_new_pool())
             #
             self.discard_pool()


             reply	other threads:[~2014-06-05 22:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 22:09 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-06-05 22:09 [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/ André Erdmann
2013-08-20 21:46 André Erdmann
2013-07-24  9:54 André Erdmann
2013-07-24  9:54 André Erdmann
2013-07-24  9:54 André Erdmann
2013-07-23  7:51 André Erdmann
2013-07-23  7:51 André Erdmann
2013-07-18 19:25 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23  7:51 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-16 16:36 André Erdmann
2013-07-03 10:05 André Erdmann

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=1399426483.5df0c6b4892aa5ea2a98c59e56be34aac8ea3301.dywi@gentoo \
    --to=dywi@mailerd.de \
    --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