public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-03 10:05 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-03 10:05 UTC (permalink / raw
  To: gentoo-commits

commit:     0e181458fcfaf0bd1eaf993a47d09befa6d19fa6
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul  2 21:03:31 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul  2 21:03:31 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=0e181458

roverlay/interface: access subsystems more easily

roverlay/interface provides abstraction layers for certain roverlay modules.
Currently, it supports dependency resolution only.

---
 roverlay/interface/__init__.py |   0
 roverlay/interface/depres.py   | 249 +++++++++++++++++++++++++++++++++++++++++
 roverlay/interface/generic.py  |  75 +++++++++++++
 roverlay/interface/root.py     |  62 ++++++++++
 4 files changed, 386 insertions(+)

diff --git a/roverlay/interface/__init__.py b/roverlay/interface/__init__.py
new file mode 100644
index 0000000..e69de29

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
new file mode 100644
index 0000000..d416312
--- /dev/null
+++ b/roverlay/interface/depres.py
@@ -0,0 +1,249 @@
+# R overlay --
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+#import weakref
+
+import roverlay.interface.generic
+
+
+import roverlay.depres.channels
+import roverlay.depres.depresolver
+import roverlay.depres.deptype
+import roverlay.depres.simpledeprule.pool
+import roverlay.depres.simpledeprule.rules
+import roverlay.depres.simpledeprule.rulemaker
+
+DEFAULT_DEPTYPE = roverlay.depres.deptype.ALL
+
+class RuleSyntaxException ( Exception ):
+   pass
+
+class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
+
+   def __init__ ( self, parent_interface ):
+      super ( DepresInterface, self ).__init__ (
+         parent_interface=parent_interface
+      )
+
+      # set up the resolver
+      self._resolver = roverlay.depres.depresolver.DependencyResolver (
+         err_queue=self.err_queue
+      )
+      ## log everything
+      self._resolver.set_logmask ( -1 )
+      ## disable passing events to listeners
+      self._resolver.set_listenermask ( 0 )
+
+      # dependency rule pools (a set of rules) are organized in a FIFO
+      # structure that allows to create and delete new pools at runtime
+      self._poolstack = self._resolver.static_rule_pools
+      self._pool_id   = -1
+
+      self._parser = roverlay.depres.simpledeprule.rulemaker.SimpleRuleMaker()
+   # --- end of __init__ (...) ---
+
+   @property
+   def resolver ( self ):
+      return self._resolver
+
+   @property
+   def parser ( self ):
+      return self._parser
+
+   @property
+   def poolstack ( self ):
+      return self._poolstack
+
+   @property
+   def pool_id ( self ):
+      return self._pool_id
+
+   def _update_resolver ( self ):
+      # sort() should be called on a per-pool basis
+      self._resolver._reset_unresolvable()
+   # --- end of _update_resolver (...) ---
+
+   def close ( self ):
+      super ( DepresInterface, self ).close()
+      self._resolver.close()
+   # --- end of close (...) ---
+
+   def update ( self ):
+      super ( DepresInterface, self ).update()
+      if self._poolstack:
+         self._poolstack[-1].sort()
+      self._update_resolver()
+   # --- end of update (...) ---
+
+   def has_pool ( self ):
+      return self._poolstack
+   # --- end of has_pool (...) ---
+
+   def has_nonempty_pool ( self ):
+      return self._poolstack and not self._poolstack[-1].empty()
+   # --- end of has_nonempty_pool (...) ---
+
+   def get_pool ( self ):
+      if self._poolstack:
+         return self._poolstack[-1]
+      else:
+         return self.get_new_pool ( force=True )
+   # --- end of get_pool (...) ---
+
+   def get_new_pool ( self, force=False, with_deptype=DEFAULT_DEPTYPE ):
+      if force or not self._poolstack or not self._poolstack[-1].empty():
+         self._pool_id += 1
+         try:
+            pool = roverlay.depres.simpledeprule.pool.SimpleDependencyRulePool (
+               "pool" + str ( self._pool_id ),
+               deptype_mask=DEFAULT_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 discard_pool ( self ):
+      try:
+         self._poolstack.pop()
+         self._pool_id -= 1
+         assert self._pool_id >= -1
+         return True
+      except AssertionError:
+         raise
+      except:
+         return False
+   # --- end of discard_pool (...) ---
+
+   def discard_pools ( self, count ):
+      for i in range ( count ):
+         if not self.discard_pool():
+            return i
+      else:
+         return count
+   # --- end of discard_pools (...) ---
+
+   def discard_empty_pools ( self ):
+      removed = 0
+      while self._poolstack and self._poolstack[-1].empty():
+         if self.discard_pool():
+            removed += 1
+         else:
+            raise AssertionError (
+               "discard_pool() should succeed if topmost pool exists."
+            )
+      return removed
+   # --- end of discard_empty_pools (...) ---
+
+   def load_rules_from_config ( self ):
+      return self.load_rule_files (
+         self.config.get_or_fail ( "DEPRES.simple_rules.files" )
+      )
+   # --- end of load_rules_from_config (...) ---
+
+   def load_rule_files ( self, files_or_dirs ):
+      return self._resolver.get_reader().read ( files_or_dirs )
+   # --- end of load_rule_files (...) ---
+
+   def add_rule ( self, rule_str ):
+      if not self._parser.add ( rule_str ):
+         raise RuleSyntaxException ( rule_str )
+      return True
+   # --- end of add_rule (...) ---
+
+   def add_rules ( self, *rule_str_list ):
+      for rule_str in rule_str_list:
+         self.add_rule ( rule_str )
+      return True
+   # --- end of add_rules (...) ---
+
+   def add_rule_list ( self, rule_str_list ):
+      for rule_str in rule_str_list:
+         self.add_rule ( rule_str )
+      return True
+   # --- end of add_rule_list (...) ---
+
+   def compile_rules ( self, new_pool=False ):
+      rules    = self._parser.done()
+      destpool = self.get_new_pool() if new_pool else self.get_pool()
+
+      try:
+         # FIXME/COULDFIX: deptypes not supported here
+         for deptype, rule in rules:
+            destpool.rules.append ( rule )
+
+         if destpool.empty():
+            self.discard_empty_pools()
+         else:
+            destpool.sort()
+         self._update_resolver()
+         return True
+      except:
+         if new_pool:
+            # this could discard (previosly) empty pools, too
+            #  (side-effect of "optimizations" in get_new_pool())
+            #
+            self.discard_pool()
+         raise
+   # --- end of compile_rules (...) ---
+
+   def add_immediate_rule ( self, rule_str ):
+      return self.add_rule ( rule_str ) and self.compile_rules()
+   # --- end of add_immediate_rule (...) ---
+
+   def visualize_pool ( self ):
+      if self._poolstack:
+         return '\n'.join (
+            '\n'.join ( rule.export_rule() )
+               for rule in self._poolstack[-1].rules
+         )
+      else:
+         return ""
+   # --- end of visualize_pool (...) ---
+
+   def get_channel ( self, channel_name="channel" ):
+      channel = roverlay.depres.channels.EbuildJobChannel (
+         err_queue=self.err_queue, name=channel_name
+      )
+      self._resolver.register_channel ( channel )
+      return channel
+   # --- end of get_channel (...) ---
+
+   def do_resolve ( self, deps, with_deptype=DEFAULT_DEPTYPE ):
+      channel = self.get_channel()
+      # FIXME/COULDFIX: once again, hardcoded deptype
+      try:
+         channel.add_dependencies ( deps, with_deptype  )
+
+         channel_result = channel.satisfy_request (
+            close_if_unresolvable=False,
+            preserve_order=True
+         )
+      finally:
+         channel.close()
+
+      return channel_result
+   # --- end of do_resolve (...) ---
+
+   def resolve ( self, *deps, **kw ):
+      result = self.do_resolve ( deps, **kw )
+      return None if result is None else result [0]
+   # --- end of resolve (...) ---
+
+   def can_resolve ( self, *deps, **kw ):
+      return self.do_resolve ( deps, **kw ) is not None
+   # --- end of can_resolve (...) ---
+
+   def cannot_resolve ( self, *deps, **kw ):
+      return self.do_resolve ( deps, **kw ) is None
+   # --- end of cannot_resolve (...) ---
+
+# --- end of DepresInterface ---

diff --git a/roverlay/interface/generic.py b/roverlay/interface/generic.py
new file mode 100644
index 0000000..08806ea
--- /dev/null
+++ b/roverlay/interface/generic.py
@@ -0,0 +1,75 @@
+# R overlay --
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+#import weakref
+
+class RoverlayInterface ( object ):
+
+   def __init__ ( self ):
+      super ( RoverlayInterface, self ).__init__()
+      self._interfaces = dict()
+   # --- end of __init__ (...) ---
+
+   def close_interfaces ( self ):
+      if hasattr ( self, '_interfaces' ):
+         for iface in self._interfaces.values():
+            iface.close()
+   # --- end of close_interfaces (...) ---
+
+   def close ( self ):
+      self.close_interfaces()
+   # --- end of close (...) ---
+
+   def update ( self ):
+      pass
+   # --- end of update (...) ---
+
+   def attach_interface ( self, name, interface, close_detached=True ):
+      if name in self._interfaces:
+         self.detach ( name, close=close_detached )
+
+      self._interfaces [name] = interface
+      return interface
+   # --- end of attach_interface (...) ---
+
+   def detach_interface ( self, name, close=False ):
+      detached = self._interfaces [name]
+      if close:
+         detached.close()
+         return True
+      else:
+         return detached
+   # --- end of detach_interface (...) ---
+
+   def get_interface ( self, name ):
+      return self._interfaces [name]
+   # --- end of get_interface (...) ---
+
+   def has_interface ( self, name ):
+      return name and name in self._interfaces
+   # --- end of has_interface (...) ---
+
+   def __getattr__ ( self, name ):
+      if name [-10:] == '_interface':
+         iface_name = name [:-10]
+         if iface_name and iface_name in self._interfaces:
+            return self._interfaces [iface_name]
+
+      raise AttributeError ( name )
+   # --- end of __getattr__ (...) ---
+
+# --- end of RoverlayInterface ---
+
+class RoverlaySubInterface ( RoverlayInterface ):
+
+   def __init__ ( self, parent_interface ):
+      super ( RoverlaySubInterface, self ).__init__()
+      # weakref? (would require to explicitly keep "parent" instances around)
+      self.parent    = parent_interface
+      self.err_queue = parent_interface.err_queue
+      self.config    = parent_interface.config
+      self.logger    = parent_interface.logger
+   # --- end of __init__ (...) ---

diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
new file mode 100644
index 0000000..d500582
--- /dev/null
+++ b/roverlay/interface/root.py
@@ -0,0 +1,62 @@
+# R overlay --
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+import logging
+
+import roverlay
+import roverlay.errorqueue
+
+import roverlay.interface.generic
+
+# does nothing if already initialized
+roverlay.setup_initial_logger()
+
+class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
+
+   SPAWN_MAP = dict()
+
+   @classmethod
+   def register_interface ( my_cls, name, cls, force=False ):
+      if name and ( force or name not in my_cls.SPAWN_MAP ):
+         my_cls.SPAWN_MAP [name] = cls
+         return True
+      else:
+         return False
+   # --- end of register_interface (...) ---
+
+   def __init__ ( self,
+      config_file=None, config=None, additional_config=None
+   ):
+      super ( RootInterface, self ).__init__()
+      self.parent    = None
+      self.err_queue = roverlay.errorqueue.ErrorQueue()
+
+      if config is not None:
+         self.config = config
+      elif config_file is not None:
+         self.config = roverlay.load_config_file (
+            config_file, extraconf=additional_config
+         )
+      else:
+         raise Exception ( "config, config_file?" )
+
+      self.logger = logging.getLogger ( self.__class__.__name__ )
+   # --- end of __init__ (...) ---
+
+   def spawn_interface ( self, name ):
+      if self.has_interface ( name ):
+         return self.get_interface ( name )
+      else:
+         iface_cls = self.SPAWN_MAP.get ( name, None )
+         if iface_cls is None:
+            raise Exception (
+               "unknown interface identifier {!r}".format ( name )
+            )
+         else:
+            return self.attach_interface (
+               name, iface_cls ( parent_interface=self )
+            )
+   # --- end of spawn_interface (...) ---


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-16 16:36 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-16 16:36 UTC (permalink / raw
  To: gentoo-commits

commit:     07451ee1180548e6ed961142fb512a368a107e04
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jul 16 16:35:29 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jul 16 16:35:29 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=07451ee1

roverlay/interface: in-code documentation

---
 roverlay/interface/depres.py  | 186 +++++++++++++++++++++++++++++++++++++++++-
 roverlay/interface/generic.py |  68 +++++++++++++++
 roverlay/interface/root.py    |  50 ++++++++++++
 3 files changed, 303 insertions(+), 1 deletion(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index e16363c..181243f 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -1,4 +1,4 @@
-# R overlay --
+# R overlay -- dependency resolution interface
 # -*- coding: utf-8 -*-
 # Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
 # Distributed under the terms of the GNU General Public License;
@@ -22,8 +22,28 @@ class RuleSyntaxException ( Exception ):
    pass
 
 class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
+   """Interface to dependency resolution.
+
+   This class provides:
+
+   * rule creation (from text/text files)
+   * manage dependency rule pools (stack-like discard_pool()/get_new_pool())
+   * resolve dependencies:
+   -> do_resolve(<deps>) for "raw" depres results
+   -> resolve(<deps>) for generic purpose results (list of resolved deps)
+   -> can_resolve(<deps>)/cannot_resolve(<deps>) for checking whether a
+      dependency string can(not) be resolved
+
+   Note that this interface relies on a parent interface (RootInterface).
+   """
 
    def __init__ ( self, parent_interface ):
+      """Initializes the depdency resolution interface.
+
+      arguments:
+      * parent_interface -- parent interface that provides shared functionality
+                            like logging and config
+      """
       super ( DepresInterface, self ).__init__ (
          parent_interface=parent_interface
       )
@@ -47,32 +67,49 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
 
    @property
    def resolver ( self ):
+      """direct access to the resolver"""
       return self._resolver
 
    @property
    def parser ( self ):
+      """direct access to the rule parser"""
       return self._parser
 
    @property
    def poolstack ( self ):
+      """direct access to the dependency rule pool stack"""
       return self._poolstack
 
    @property
    def pool_id ( self ):
+      """Index of the topmost rule pool (-1 if no rule pool active)"""
       return self._pool_id
 
    def _update_resolver ( self ):
+      """Updates the resolver.
+
+      Returns: None (implicit)
+      """
       # sort() should be called on a per-pool basis
       self._resolver._reset_unresolvable()
    # --- end of _update_resolver (...) ---
 
    def close ( self ):
+      """Closes the dependency resolver and all subinterfaces.
+
+      Returns: self
+      """
       super ( DepresInterface, self ).close()
       self._resolver.close()
       return self
    # --- end of close (...) ---
 
    def update ( self ):
+      """Updates this interface, i.e. performs a "soft"-reload of the
+      resolver and sorts the topmost rule pool.
+
+      Returns: self
+      """
       super ( DepresInterface, self ).update()
       if self._poolstack:
          self._poolstack[-1].sort()
@@ -81,18 +118,32 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of update (...) ---
 
    def fixup_pool_id ( self ):
+      """Resets the pool id.
+
+      Does not need to be called manually.
+
+      Returns: None (implicit)
+      """
       self._pool_id = len ( self._poolstack ) - 1
    # --- end of fixup_pool_id (...) ---
 
    def has_pool ( self ):
+      """
+      Returns True if this interface has at least one rule pool, else False.
+      """
       return self._poolstack
    # --- end of has_pool (...) ---
 
    def has_nonempty_pool ( self ):
+      """
+      Returns True if the topmost rule pool of this interface exists
+      and is not empty.
+      """
       return self._poolstack and not self._poolstack[-1].empty()
    # --- end of has_nonempty_pool (...) ---
 
    def get_pool ( self ):
+      """Returns the topmost rule pool. Creates one if necessary."""
       if self._poolstack:
          return self._poolstack[-1]
       else:
@@ -100,6 +151,13 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of get_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.
+
+      arguments:
+      * force        -- if True: force creation of a new pool even if the
+                                 current one is empty
+      * 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:
@@ -118,6 +176,10 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of get_new_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
@@ -130,6 +192,13 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of discard_pool (...) ---
 
    def discard_pools ( self, count ):
+      """Discards up to <count> rule pools.
+
+      arguments:
+      * count -- number of rule pool to remove
+
+      Returns: number of rule pool that have been removed (<= count)
+      """
       for i in range ( count ):
          if not self.discard_pool():
             return i
@@ -138,6 +207,10 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of discard_pools (...) ---
 
    def discard_all_pools ( self ):
+      """Discards all rule pools.
+
+      Returns: number of removed rule pools
+      """
       i = 0
       while self.discard_pool():
          i += 1
@@ -145,6 +218,10 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of discard_all_pools (...) ---
 
    def discard_empty_pools ( self ):
+      """Discards rule pools until the topmost one is not empty.
+
+      Returns: number of removed rule pools
+      """
       removed = 0
       while self._poolstack and self._poolstack[-1].empty():
          if self.discard_pool():
@@ -157,6 +234,14 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of discard_empty_pools (...) ---
 
    def load_rules_from_config ( self, ignore_missing=False ):
+      """Loads all configured rule files into a new pool (or new pools).
+
+      arguments:
+      * ignore_missing -- if True: do not raise an Exception if
+                                   SIMPLE_RULE_FILE is not set in the config
+
+      Returns: True if rule files have been loaded, else False.
+      """
       if ignore_missing:
          rule_files = self.config.get ( "DEPRES.simple_rules.files", None )
          if rule_files:
@@ -170,30 +255,70 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of load_rules_from_config (...) ---
 
    def load_rule_files ( self, files_or_dirs ):
+      """Loads the given files into a new rule pool (or new pools).
+
+      Returns: True on success, else False
+      """
       ret = self._resolver.get_reader().read ( files_or_dirs )
       self.fixup_pool_id()
       return ret
    # --- end of load_rule_files (...) ---
 
    def add_rule ( self, rule_str ):
+      """Sends a text line to the rule parser.
+
+      arguments:
+      * rule_str -- text line
+
+      Returns: True
+
+      Raises: RuleSyntaxException if rule_str cannot be parsed
+
+      Note: rules have to be compiled via compile_rules() after adding
+            text lines
+      """
       if not self._parser.add ( rule_str ):
          raise RuleSyntaxException ( rule_str )
       return True
    # --- end of add_rule (...) ---
 
    def add_rules ( self, *rule_str_list ):
+      """Sends several text lines to the rule parser.
+      See add_rule() for details.
+
+      arguments:
+      * *rule_str_list --
+
+      Returns: True
+      """
       for rule_str in rule_str_list:
          self.add_rule ( rule_str )
       return True
    # --- end of add_rules (...) ---
 
    def add_rule_list ( self, rule_str_list ):
+      """Like add_rules(), but accepts a single list-like arg.
+      See add_rule()/add_rules() for details.
+
+      arguments:
+      * rule_str_list --
+
+      Returns: True
+      """
       for rule_str in rule_str_list:
          self.add_rule ( rule_str )
       return True
    # --- end of add_rule_list (...) ---
 
    def compile_rules ( self, new_pool=False ):
+      """Tells the rule parser to 'compile' rules. This converts the text
+      input into dependency rule objects, which are then added to a rule pool.
+
+      arguments:
+      * new_pool -- create a new pool for the compiled rules
+
+      Returns: True
+      """
       rules    = self._parser.done()
       destpool = self.get_new_pool() if new_pool else self.get_pool()
 
@@ -218,10 +343,24 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of compile_rules (...) ---
 
    def add_immediate_rule ( self, rule_str ):
+      """Directly adds a single rule (given in rule file syntax form) to
+      the topmost rule pool.
+
+      arguments:
+      * rule_str -- text line
+
+      Note: this method calls compile_rules(), which creates rule objects
+            for all text lines added so far.
+
+      Returns: True
+      """
       return self.add_rule ( rule_str ) and self.compile_rules()
    # --- end of add_immediate_rule (...) ---
 
    def visualize_pool ( self ):
+      """Visualizes the topmost rule pool. This returns a string that contains
+      all rules of this pool in text form (in rule file syntax).
+      """
       if self._poolstack:
          return '\n'.join (
             '\n'.join ( rule.export_rule() )
@@ -232,6 +371,15 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of visualize_pool (...) ---
 
    def get_channel ( self, channel_name="channel" ):
+      """Creates, registers and returns an EbuildJobChannel suitable for
+      dependency resolution.
+
+      Note: This doesn't need to be called manually in order to resolve
+            dependencies.
+
+      arguments:
+      * channel_name -- name of the channel (defaults to "channel")
+      """
       channel = roverlay.depres.channels.EbuildJobChannel (
          err_queue=self.err_queue, name=channel_name
       )
@@ -240,6 +388,17 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of get_channel (...) ---
 
    def do_resolve ( self, deps, with_deptype=DEFAULT_DEPTYPE ):
+      """Performs dependency resolution for the given dependency list and
+      returns the result, which is None (=not resolved) or a 2-tuple
+      (<resolved deps>, <unresolvable, but optional deps>).
+
+      Note: use resolve() for resolving dependencies unless the 2-tuple
+            result form is desired.
+
+      arguments:
+      * deps         -- dependency string list
+      * with_deptype -- dependency type (optional, defaults to DEFAULT_DEPTYPE)
+      """
       channel = self.get_channel()
       # FIXME/COULDFIX: once again, hardcoded deptype
       try:
@@ -256,15 +415,40 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of do_resolve (...) ---
 
    def resolve ( self, *deps, **kw ):
+      """Like do_resolve(), but accepts the dependency string list in var-args
+      form and returns None (=not resolved) or a list of resolved dependencies.
+
+      arguments:
+      * *deps -- list of dependency strings
+      * **kw  -- passed to do_resolve()
+      """
       result = self.do_resolve ( deps, **kw )
+      # result := ( list<resolved>, list<unresolvable> )
       return None if result is None else result [0]
    # --- end of resolve (...) ---
 
    def can_resolve ( self, *deps, **kw ):
+      """Like resolve(), but simply returns True if all dependencies could
+      be resolved.
+
+      Technically, returns True IFF all mandatory dependencies could be
+      resolved.
+
+      arguments:
+      * *deps --
+      * **kw  --
+      """
       return self.do_resolve ( deps, **kw ) is not None
    # --- end of can_resolve (...) ---
 
    def cannot_resolve ( self, *deps, **kw ):
+      """Like can_resolve(), but returns True if at least one (mandatory)
+      dependency could not be resolved.
+
+      arguments:
+      * *deps --
+      * **kw  --
+      """
       return self.do_resolve ( deps, **kw ) is None
    # --- end of cannot_resolve (...) ---
 

diff --git a/roverlay/interface/generic.py b/roverlay/interface/generic.py
index c6678f3..b86cc31 100644
--- a/roverlay/interface/generic.py
+++ b/roverlay/interface/generic.py
@@ -7,28 +7,53 @@
 #import weakref
 
 class RoverlayInterface ( object ):
+   """Base class for roverlay interfaces.
+   Provides functionality for attaching/detaching subinterfaces.
+   """
 
    def __init__ ( self ):
+      """Initializes this interfaces."""
       super ( RoverlayInterface, self ).__init__()
       self._interfaces = dict()
    # --- end of __init__ (...) ---
 
    def close_interfaces ( self ):
+      """Closes all subinterfaces."""
       if hasattr ( self, '_interfaces' ):
          for iface in self._interfaces.values():
             iface.close()
    # --- end of close_interfaces (...) ---
 
    def close ( self ):
+      """Closes this interfaces and all of its subinterfaces.
+
+      Returns: self
+      """
       self.close_interfaces()
       return self
    # --- end of close (...) ---
 
    def update ( self ):
+      """Updates this interface.
+
+      Does nothing. Derived classes may implement it.
+
+      Returns: self
+      """
       return self
    # --- end of update (...) ---
 
    def attach_interface ( self, name, interface, close_detached=True ):
+      """Adds a subinterface.
+
+      arguments:
+      * name           -- name of the interface
+      * interface      -- interface object to add
+      * close_detached -- if an interface with the same name has been replaced
+                          by the new one: close it if True
+
+      Returns: added interface
+      """
       if name in self._interfaces:
          self.detach ( name, close=close_detached )
 
@@ -37,6 +62,14 @@ class RoverlayInterface ( object ):
    # --- end of attach_interface (...) ---
 
    def detach_interface ( self, name, close=False ):
+      """Detaches an interface.
+
+      arguments:
+      * name  -- name of the interface
+      * close -- close interface after detaching it
+
+      Returns: detached interface if close is False, else True
+      """
       detached = self._interfaces [name]
       del self._interfaces [name]
       if close:
@@ -47,14 +80,40 @@ class RoverlayInterface ( object ):
    # --- end of detach_interface (...) ---
 
    def get_interface ( self, name ):
+      """Provides access to a subinterface by name.
+
+      arguments:
+      * name -- name of the interface
+
+      Returns: interface (object)
+
+      Raises: KeyError if interface does not exist
+      """
       return self._interfaces [name]
    # --- end of get_interface (...) ---
 
    def has_interface ( self, name ):
+      """Returns True if a subinterface with the given name exists, else False.
+
+      arguments:
+      * name -- name of the interface
+      """
       return name and name in self._interfaces
    # --- end of has_interface (...) ---
 
    def __getattr__ ( self, name ):
+      """ Provides alternative access to subinterfaces via
+      <self>.<subinterface name>_interface
+
+      arguments:
+      * name -- attribute name
+
+      Returns: interface if name ends with '_interface'
+
+      Raises: KeyError if name ends with '_interface' and the referenced
+              interface does not exist
+      """
+
       if name [-10:] == '_interface':
          iface_name = name [:-10]
          if iface_name and iface_name in self._interfaces:
@@ -66,8 +125,17 @@ class RoverlayInterface ( object ):
 # --- end of RoverlayInterface ---
 
 class RoverlaySubInterface ( RoverlayInterface ):
+   """Base class derived from RoverlayInterface for interfaces that have
+   a parent interface.
+   """
 
    def __init__ ( self, parent_interface ):
+      """Initializes the subinterface. Creates references to shared objects
+      like logger and config as well as a ref to the parent interface.
+
+      arguments:
+      * parent_interface --
+      """
       super ( RoverlaySubInterface, self ).__init__()
       # weakref? (would require to explicitly keep "parent" instances around)
       self.parent    = parent_interface

diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
index a4d287c..c571eea 100644
--- a/roverlay/interface/root.py
+++ b/roverlay/interface/root.py
@@ -16,11 +16,26 @@ import roverlay.interface.generic
 roverlay.setup_initial_logger()
 
 class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
+   """Root interfaces for accessing roverlay interfaces.
 
+   See MainInterface for a root interface with delayed initialization.
+   """
+
+   # class-wide map ( <interface name> => <interface class> )
+   #  for creating/"spawning" subinterfaces
+   #
    SPAWN_MAP = dict()
 
    @classmethod
    def register_interface ( my_cls, name, cls, force=False ):
+      """Registers a subinterface with the root interface.
+
+      arguments:
+      * name  -- name of the interface, e.g. "depres"
+      * cls   -- interface class
+      * force -- if True: overwrite existing entries for name
+                 Defaults to False.
+      """
       if name and ( force or name not in my_cls.SPAWN_MAP ):
          my_cls.SPAWN_MAP [name] = cls
          return True
@@ -31,6 +46,19 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
    def __init__ ( self,
       config_file=None, config=None, additional_config=None, is_installed=None
    ):
+      """Initializes the root interface:
+      * loads the config
+      * creates shared objects like logger and error queue
+      * calls roverlay.hook.setup()
+
+      arguments:
+      * config_file       -- path to the config file
+      * config            -- config tree or None
+                              takes precedence over config_file
+      * additional_config -- when loading the config file: extra config dict
+      * is_installed      -- whether roverlay has been installed or not
+                              Defaults to None.
+      """
       super ( RootInterface, self ).__init__()
       self.parent    = None
       self.err_queue = roverlay.errorqueue.ErrorQueue()
@@ -66,10 +94,25 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
    # --- end of __init__ (...) ---
 
    def set_installed ( self, status=True ):
+      """Marks roverlay as installed/not installed.
+
+      arguments:
+      * status -- installation status bool (defaults to True)
+
+      Returns: None (implicit)
+      """
       self.config.merge_with ( { 'installed': bool ( status ), } )
    # --- end of set_installed (...) ---
 
    def spawn_interface ( self, name ):
+      """Spawns an registered subinterface.
+      (Creates it if necessary, else uses the existing one.)
+
+      arguments:
+      * name -- name of the interface, e.g. "depres"
+
+      Returns: subinterface
+      """
       if self.has_interface ( name ):
          return self.get_interface ( name )
       else:
@@ -85,5 +128,12 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
    # --- end of spawn_interface (...) ---
 
    def run_hook ( self, phase ):
+      """Triggers a hook event.
+
+      arguments:
+      * phase -- event, e.g. "overlay_success" or "user"
+
+      Returns: success (True/False)
+      """
       return roverlay.hook.run ( phase, catch_failure=False )
    # --- end of run_hook (...) ---


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/
  2013-07-23  7:51 [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/ André Erdmann
@ 2013-07-19 18:00 ` André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-19 18:00 UTC (permalink / raw
  To: gentoo-commits

commit:     8735cde4882262112c7adf46b1e55a390d920e28
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul 19 17:44:54 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul 19 17:44:54 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=8735cde4

depres interface: visualize pools, ignore_missing

---
 roverlay/interface/depres.py | 70 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 10 deletions(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index 6e79bc5..ad292de 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -6,6 +6,8 @@
 
 #import weakref
 
+import errno
+
 import roverlay.interface.generic
 
 
@@ -245,6 +247,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       if ignore_missing:
          rule_files = self.config.get ( "DEPRES.simple_rules.files", None )
          if rule_files:
+            ##return self.load_rule_files ( rule_files, ignore_missing=True )
             return self.load_rule_files ( rule_files )
          else:
             return False
@@ -254,12 +257,26 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
          )
    # --- end of load_rules_from_config (...) ---
 
-   def load_rule_files ( self, files_or_dirs ):
+   def load_rule_files ( self, files_or_dirs, ignore_missing=False ):
       """Loads the given files into a new rule pool (or new pools).
 
+      arguments:
+      * ignore_missing -- suppress exceptions caused by missing files and
+                          return False
+
       Returns: True on success, else False
       """
-      ret = self._resolver.get_reader().read ( files_or_dirs )
+      if ignore_missing:
+         try:
+            ret = self._resolver.get_reader().read ( files_or_dirs )
+         except IOError as ioerr:
+            if ioerr.errno == errno.ENOENT:
+               ret = False
+            else:
+               raise
+      else:
+         ret = self._resolver.get_reader().read ( files_or_dirs )
+
       self.fixup_pool_id()
       return True if ret is None else ret
    # --- end of load_rule_files (...) ---
@@ -311,6 +328,13 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of add_rule_list (...) ---
 
    def try_compile_rules ( self, *args, **kwargs ):
+      """Tells the rule parser to 'compile' rules. Does nothing if the
+      rule parser has any active context (e.g. is inside a multi line rule).
+      See compile_rules() for details.
+
+      Returns: False if rule compiling has been suppressed du to active
+               context, else True (=rules compiled)
+      """
       if self._parser.has_context():
          return False
       else:
@@ -364,18 +388,44 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       return self.add_rule ( rule_str ) and self.compile_rules()
    # --- end of add_immediate_rule (...) ---
 
-   def visualize_pool ( self ):
-      """Visualizes the topmost rule pool. This returns a string that contains
-      all rules of this pool in text form (in rule file syntax).
+   def visualize_pool ( self, pool_id=None ):
+      """Visualizes the topmost rule pool (or the specified one).
+      his returns a string that contains all rules of this pool
+      in text form (in rule file syntax).
+
+      arguments:
+      * pool_id -- index of the pool that should be visualized
+                   Defaults to 0 (-> use topmost pool).
+
+      Returns:
+          visualized pool (str) if requested pool existed, else empty string
       """
-      if self._poolstack:
+      try:
+         pool = self._poolstack [ -1 if pool_id is None else pool_id ]
+      except IndexError:
+         return ""
+      else:
+         return '\n'.join ( pool.export_rules() )
+   # --- end of visualize_pool (...) ---
+
+   def visualize_pools ( self, id_range=None ):
+      """Visualize multiple pools at once.
+
+      arguments:
+      * id_range -- an iterable of indexes or None (-> visualize all)
+                    Defaults to None.
+
+      Returns: visualized pools (str)
+      """
+      if id_range is None:
          return '\n'.join (
-            '\n'.join ( rule.export_rule() )
-               for rule in self._poolstack[-1].rules
+            '\n'.join ( pool.export_rules() ) for pool in self._poolstack
          )
       else:
-         return ""
-   # --- end of visualize_pool (...) ---
+         return '\n'.join (
+            self.visualize_pool ( pool_id ) for pool_id in id_range
+         )
+   # --- end of visualize_pools (...) ---
 
    def get_channel ( self, channel_name="channel" ):
       """Creates, registers and returns an EbuildJobChannel suitable for


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
  2013-07-18 19:25 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-23  7:51 ` André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-23  7:51 UTC (permalink / raw
  To: gentoo-commits

commit:     9929b385114c5bb3b06b446a8b8644dcf4e9695e
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 18 19:21:39 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 18 19:21:39 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9929b385

roverlay/interface/depres: try_compile_rules()

---
 roverlay/interface/depres.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index 181243f..6e79bc5 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -261,7 +261,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       """
       ret = self._resolver.get_reader().read ( files_or_dirs )
       self.fixup_pool_id()
-      return ret
+      return True if ret is None else ret
    # --- end of load_rule_files (...) ---
 
    def add_rule ( self, rule_str ):
@@ -310,6 +310,13 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       return True
    # --- end of add_rule_list (...) ---
 
+   def try_compile_rules ( self, *args, **kwargs ):
+      if self._parser.has_context():
+         return False
+      else:
+         return self.compile_rules()
+   # --- end of try_compile_rules (...) ---
+
    def compile_rules ( self, new_pool=False ):
       """Tells the rule parser to 'compile' rules. This converts the text
       input into dependency rule objects, which are then added to a rule pool.


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-23  7:51 André Erdmann
  2013-07-19 18:00 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
  0 siblings, 1 reply; 12+ messages in thread
From: André Erdmann @ 2013-07-23  7:51 UTC (permalink / raw
  To: gentoo-commits

commit:     8735cde4882262112c7adf46b1e55a390d920e28
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul 19 17:44:54 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul 19 17:44:54 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=8735cde4

depres interface: visualize pools, ignore_missing

---
 roverlay/interface/depres.py | 70 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 10 deletions(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index 6e79bc5..ad292de 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -6,6 +6,8 @@
 
 #import weakref
 
+import errno
+
 import roverlay.interface.generic
 
 
@@ -245,6 +247,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       if ignore_missing:
          rule_files = self.config.get ( "DEPRES.simple_rules.files", None )
          if rule_files:
+            ##return self.load_rule_files ( rule_files, ignore_missing=True )
             return self.load_rule_files ( rule_files )
          else:
             return False
@@ -254,12 +257,26 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
          )
    # --- end of load_rules_from_config (...) ---
 
-   def load_rule_files ( self, files_or_dirs ):
+   def load_rule_files ( self, files_or_dirs, ignore_missing=False ):
       """Loads the given files into a new rule pool (or new pools).
 
+      arguments:
+      * ignore_missing -- suppress exceptions caused by missing files and
+                          return False
+
       Returns: True on success, else False
       """
-      ret = self._resolver.get_reader().read ( files_or_dirs )
+      if ignore_missing:
+         try:
+            ret = self._resolver.get_reader().read ( files_or_dirs )
+         except IOError as ioerr:
+            if ioerr.errno == errno.ENOENT:
+               ret = False
+            else:
+               raise
+      else:
+         ret = self._resolver.get_reader().read ( files_or_dirs )
+
       self.fixup_pool_id()
       return True if ret is None else ret
    # --- end of load_rule_files (...) ---
@@ -311,6 +328,13 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    # --- end of add_rule_list (...) ---
 
    def try_compile_rules ( self, *args, **kwargs ):
+      """Tells the rule parser to 'compile' rules. Does nothing if the
+      rule parser has any active context (e.g. is inside a multi line rule).
+      See compile_rules() for details.
+
+      Returns: False if rule compiling has been suppressed du to active
+               context, else True (=rules compiled)
+      """
       if self._parser.has_context():
          return False
       else:
@@ -364,18 +388,44 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       return self.add_rule ( rule_str ) and self.compile_rules()
    # --- end of add_immediate_rule (...) ---
 
-   def visualize_pool ( self ):
-      """Visualizes the topmost rule pool. This returns a string that contains
-      all rules of this pool in text form (in rule file syntax).
+   def visualize_pool ( self, pool_id=None ):
+      """Visualizes the topmost rule pool (or the specified one).
+      his returns a string that contains all rules of this pool
+      in text form (in rule file syntax).
+
+      arguments:
+      * pool_id -- index of the pool that should be visualized
+                   Defaults to 0 (-> use topmost pool).
+
+      Returns:
+          visualized pool (str) if requested pool existed, else empty string
       """
-      if self._poolstack:
+      try:
+         pool = self._poolstack [ -1 if pool_id is None else pool_id ]
+      except IndexError:
+         return ""
+      else:
+         return '\n'.join ( pool.export_rules() )
+   # --- end of visualize_pool (...) ---
+
+   def visualize_pools ( self, id_range=None ):
+      """Visualize multiple pools at once.
+
+      arguments:
+      * id_range -- an iterable of indexes or None (-> visualize all)
+                    Defaults to None.
+
+      Returns: visualized pools (str)
+      """
+      if id_range is None:
          return '\n'.join (
-            '\n'.join ( rule.export_rule() )
-               for rule in self._poolstack[-1].rules
+            '\n'.join ( pool.export_rules() ) for pool in self._poolstack
          )
       else:
-         return ""
-   # --- end of visualize_pool (...) ---
+         return '\n'.join (
+            self.visualize_pool ( pool_id ) for pool_id in id_range
+         )
+   # --- end of visualize_pools (...) ---
 
    def get_channel ( self, channel_name="channel" ):
       """Creates, registers and returns an EbuildJobChannel suitable for


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-23  7:51 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-23  7:51 UTC (permalink / raw
  To: gentoo-commits

commit:     01a383d00def3f9f5bcaccd21167187cbf61288e
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul 19 17:44:18 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul 19 17:44:18 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=01a383d0

roverlay/interface/main: accept config in setup()

---
 roverlay/interface/main.py | 7 ++-----
 roverlay/interface/root.py | 5 +++--
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/roverlay/interface/main.py b/roverlay/interface/main.py
index dfa89e2..395bd99 100644
--- a/roverlay/interface/main.py
+++ b/roverlay/interface/main.py
@@ -18,11 +18,8 @@ class MainInterface ( roverlay.interface.root.RootInterface ):
          self.setup ( *args, **kwargs )
    # --- end of __init__ (...) ---
 
-   def setup ( self, config_file, *args, **kw ):
-      self.config_file = config_file
-      super ( MainInterface, self ).__init__ (
-         config_file=config_file, *args, **kw
-      )
+   def setup ( self, *args, **kw ):
+      super ( MainInterface, self ).__init__ ( *args, **kw )
       self.__class__.register_interface (
          "depres", roverlay.interface.depres.DepresInterface
       )

diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
index c571eea..a06663b 100644
--- a/roverlay/interface/root.py
+++ b/roverlay/interface/root.py
@@ -60,8 +60,9 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
                               Defaults to None.
       """
       super ( RootInterface, self ).__init__()
-      self.parent    = None
-      self.err_queue = roverlay.errorqueue.ErrorQueue()
+      self.parent      = None
+      self.err_queue   = roverlay.errorqueue.ErrorQueue()
+      self.config_file = config_file
 
       if getattr ( self, 'config', None ):
          pass


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-24  9:54 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-24  9:54 UTC (permalink / raw
  To: gentoo-commits

commit:     99c32fe36386668b42264e6140c44ac58c7a82c4
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 24 09:51:36 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 24 09:51:36 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=99c32fe3

depres interface: CONFIG_KEY_DEPRULES

---
 roverlay/interface/depres.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index ad292de..e6885fc 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -39,6 +39,8 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
    Note that this interface relies on a parent interface (RootInterface).
    """
 
+   CONFIG_KEY_DEPRULES = 'DEPRES.simple_rules.files'
+
    def __init__ ( self, parent_interface ):
       """Initializes the depdency resolution interface.
 
@@ -245,7 +247,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       Returns: True if rule files have been loaded, else False.
       """
       if ignore_missing:
-         rule_files = self.config.get ( "DEPRES.simple_rules.files", None )
+         rule_files = self.config.get ( self.CONFIG_KEY_DEPRULES, None )
          if rule_files:
             ##return self.load_rule_files ( rule_files, ignore_missing=True )
             return self.load_rule_files ( rule_files )
@@ -253,10 +255,12 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
             return False
       else:
          return self.load_rule_files (
-            self.config.get_or_fail ( "DEPRES.simple_rules.files" )
+            self.config.get_or_fail ( self.CONFIG_KEY_DEPRULES )
          )
    # --- end of load_rules_from_config (...) ---
 
+   load_configured = load_rules_from_config
+
    def load_rule_files ( self, files_or_dirs, ignore_missing=False ):
       """Loads the given files into a new rule pool (or new pools).
 


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-24  9:54 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-24  9:54 UTC (permalink / raw
  To: gentoo-commits

commit:     b80e7ea7409d492c298850fbcdcbd126b161c6c2
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 24 09:52:26 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 24 09:52:26 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=b80e7ea7

roverlay/interface/main: register remote interface

---
 roverlay/interface/main.py | 6 +++++-
 roverlay/interface/root.py | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/roverlay/interface/main.py b/roverlay/interface/main.py
index 395bd99..db4ed50 100644
--- a/roverlay/interface/main.py
+++ b/roverlay/interface/main.py
@@ -1,4 +1,4 @@
-# R overlay --
+# R overlay -- main interface
 # -*- coding: utf-8 -*-
 # Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
 # Distributed under the terms of the GNU General Public License;
@@ -8,6 +8,7 @@ import roverlay
 
 import roverlay.interface.root
 import roverlay.interface.depres
+import roverlay.interface.remote
 
 roverlay.setup_initial_logger()
 
@@ -23,5 +24,8 @@ class MainInterface ( roverlay.interface.root.RootInterface ):
       self.__class__.register_interface (
          "depres", roverlay.interface.depres.DepresInterface
       )
+      self.__class__.register_interface (
+         "remote", roverlay.interface.remote.RemoteInterface
+      )
       return True
    # --- end of setup (...) ---

diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
index a06663b..5a4f386 100644
--- a/roverlay/interface/root.py
+++ b/roverlay/interface/root.py
@@ -1,4 +1,4 @@
-# R overlay --
+# R overlay -- root interface
 # -*- coding: utf-8 -*-
 # Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
 # Distributed under the terms of the GNU General Public License;


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-24  9:54 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-07-24  9:54 UTC (permalink / raw
  To: gentoo-commits

commit:     5b8443af2e14467f9137d93a3227ee32f41164d4
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 24 09:51:54 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 24 09:51:54 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=5b8443af

roverlay/interface: remote

Remote interface for syncing.

---
 roverlay/interface/remote.py | 212 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 212 insertions(+)

diff --git a/roverlay/interface/remote.py b/roverlay/interface/remote.py
new file mode 100644
index 0000000..881d013
--- /dev/null
+++ b/roverlay/interface/remote.py
@@ -0,0 +1,212 @@
+# R overlay -- remote interface
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version
+
+import errno
+
+import roverlay.interface.generic
+
+import roverlay.remote.repolist
+import roverlay.remote.status
+
+
+class RemoteInterface ( roverlay.interface.generic.RoverlaySubInterface ):
+   #
+   # Note: this interface is a stub, it supports syncing only!
+   #
+
+   CONFIG_KEY_REPOS = 'REPO.config_files'
+
+   SYNC_SUCCESS = roverlay.remote.status.SYNC_SUCCESS
+   SYNC_FAIL    = roverlay.remote.status.SYNC_FAIL
+   SYNC_DONE    = roverlay.remote.status.SYNC_DONE
+   REPO_READY   = roverlay.remote.status.REPO_READY
+
+   def __init__ ( self, parent_interface ):
+      super ( RemoteInterface, self ).__init__ ( parent_interface )
+      self._repolist = roverlay.remote.repolist.RepoList (
+         sync_enabled=self.config.get_or_fail ( "nosync" )
+      )
+   # --- end of __init__ (...) ---
+
+   @property
+   def repolist ( self ):
+      """direct access to the RepoList"""
+      return self._repolist
+
+   @property
+   def repos ( self ):
+      """direct access to the repos"""
+      return self._repolist.repos
+
+   @property
+   def sync_enabled ( self ):
+      return self._repolist.sync_enabled
+
+   def _set_sync ( self, status ):
+      """Enables/Disables syncing.
+
+      Returns: old sync enable status
+
+      arguments:
+      * status -- new sync enable status
+      """
+      old_sync_enable = self._repolist.sync_enabled
+      self._repolist.sync_enabled = bool ( status )
+      return old_sync_enable
+   # --- end of _set_sync (...) ---
+
+   def enable_sync ( self ):
+      """Enables syncing.
+
+      Returns: old sync enable status
+      """
+      return self._set_sync ( True )
+   # --- end of enable_sync (...) ---
+
+   def disable_sync ( self ):
+      """Disables syncing.
+
+      Returns: old sync enable status
+      """
+      return self._set_sync ( False )
+   # --- end of disable_sync (...) ---
+
+   def load_repo_file ( self, filepath, ignore_missing=False ):
+      """Loads a repo file.
+
+      Returns True on success, else False.
+
+      arguments:
+      * filepath       -- path to the repo config file
+      * ignore_missing -- suppress exceptions caused by missing files
+      """
+      if ignore_missing:
+         try:
+            self._repolist.load_file ( filepath )
+         except OSError as oserr:
+            if oserr.errno == errno.ENOENT:
+               return False
+            else:
+               raise
+         else:
+            return True
+      else:
+         self._repolist.load_file ( filepath )
+         return True
+   # --- end of load_repo_file (...) ---
+
+   def load_repo_files ( self, files, ignore_missing=False ):
+      """Loads zero or more repo files.
+
+      Returns: True if loading of all files succeeded, else False.
+
+      arguments:
+      * files          -- files to load
+      * ignore_missing -- suppress exceptions caused by missing files
+      """
+      ret = True
+      for filepath in files:
+         if not self.load_repo_file ( filepath ):
+            ret = False
+      return ret
+   # --- end of load_repo_files (...) ---
+
+   def load_configured ( self, ignore_missing=False ):
+      """Loads the configured repo files.
+
+      Returns: success (True/False)
+
+      arguments:
+      * ignore_missing -- suppress exceptions caused by missing files
+                          Additionally, do not fail if no repo files
+                          configured.
+      """
+      if ignore_missing:
+         files = self.config.get ( self.CONFIG_KEY_REPOS, None )
+         if files is not None:
+            return self.load_repo_files ( files, ignore_missing=True )
+         else:
+            return True
+      else:
+         return self.load_repo_files (
+            self.config.get_or_fail ( self.CONFIG_KEY_REPOS ),
+            ignore_missing=False
+         )
+   # --- end of load_configured (...) ---
+
+   def sync ( self, enable_sync=None, repo_filter=None ):
+      """Syncs all repos (or a subset of them).
+
+      Returns: success (True/False)
+
+      arguments:
+      * enable_sync -- enable/disable syncing
+                        Defaults to None (-> use RepoList default)
+      * repo_filter -- filter for choosing which repos to sync
+                        Defaults to None (-> do not filter)
+      """
+      sync_enabled = bool (
+         self._repolist.sync_enabled if enable_sync is None else enable_sync
+      )
+
+      success = True
+      for repo in (
+         self._repolist.repos if repo_filter is None
+         else filter ( repo_filter, self._repolist.repos )
+      ):
+         repo.reset()
+         if not repo.sync ( sync_enabled ):
+            success = False
+
+      return success
+   # --- end of sync (...) ---
+
+   def sync_named_repo ( self, repo_name, enable_sync=None ):
+      """Syncs all repos with the given name.
+
+      Returns: success (True/False)
+
+      arguments:
+      * repo_name   -- name of the repo
+      * enable_sync -- enable/disable syncing
+      """
+      return self.sync (
+         enable_sync=enable_sync,
+         repo_filter=lambda r: r.name == repo_name
+      )
+   # --- end of sync_named_repo (...) ---
+
+   def sync_online ( self, repo_filter=None ):
+      """Calls sync with enable_sync=True."""
+      return self.sync ( enable_sync=True, repo_filter=repo_filter )
+   # --- end of sync_online (...) ---
+
+   def sync_offline ( self, repo_filter=None ):
+      """Calls sync with enable_sync=False."""
+      return self.sync ( enable_sync=False, repo_filter=repo_filter )
+   # --- end of sync_offline (...) ---
+
+   def get_repos_by_name ( self, repo_name ):
+      """Returns a list containing all repos with the given name.
+
+      arguments:
+      * repo_name --
+      """
+      return [ r for r in self._repolist.repos if r.name == repo_name ]
+   # --- end of get_repos_by_name (...) ---
+
+   def get_repo_by_name ( self, repo_name ):
+      """Returns the repo with the given name. Returns None if no such repo
+      exists.
+
+      arguments:
+      * repo_name --
+      """
+      rlist = self.get_repos_by_name ( repo_name )
+      return rlist[0] if rlist else None
+   # --- end of get_repo_by_name (...) ---
+
+# --- end of RemoteInterface ---


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-08-20 21:46 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2013-08-20 21:46 UTC (permalink / raw
  To: gentoo-commits

commit:     0cd0e9e1f3aa993f9cc583007cb8d3de46e30d1c
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Aug 20 16:32:29 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Aug 20 16:32:29 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=0cd0e9e1

depres interface: optionally use non-greedy channels

---
 roverlay/interface/depres.py | 75 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 66 insertions(+), 9 deletions(-)

diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index e6885fc..c7ba95c 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -41,12 +41,22 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
 
    CONFIG_KEY_DEPRULES = 'DEPRES.simple_rules.files'
 
-   def __init__ ( self, parent_interface ):
+   GREEDY_DEPRES_CHANNEL    = roverlay.depres.channels.EbuildJobChannel
+   NONGREEDY_DEPRES_CHANNEL = roverlay.depres.channels.NonGreedyDepresChannel
+
+   def __init__ ( self, parent_interface, greedy=None, want_tuple=False ):
       """Initializes the depdency resolution interface.
 
       arguments:
       * parent_interface -- parent interface that provides shared functionality
                             like logging and config
+      * greedy           -- whether to use greedy depres channels by default
+                            or not. See get_channel() for details.
+                            Defaults to None (=greedy if dep resolver uses
+                            threads, else not greedy).
+      * want_tuple       -- when do_resolve() with preserve_order=True:
+                             return resolved deps as tuples not list
+                            Defaults to False.
       """
       super ( DepresInterface, self ).__init__ (
          parent_interface=parent_interface
@@ -56,6 +66,9 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       self._resolver = roverlay.depres.depresolver.DependencyResolver (
          err_queue=self.err_queue
       )
+      self.set_greedy ( greedy )
+      self.want_tuple = bool ( want_tuple )
+
       ## log everything
       self._resolver.set_logmask ( -1 )
       ## disable passing events to listeners
@@ -89,6 +102,18 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       """Index of the topmost rule pool (-1 if no rule pool active)"""
       return self._pool_id
 
+   def set_greedy ( self, greedy ):
+      if greedy is None:
+         self.default_depres_channel = (
+            self.GREEDY_DEPRES_CHANNEL if self._resolver.get_threadcount()
+            else self.NONGREEDY_DEPRES_CHANNEL
+         )
+      elif greedy:
+         self.default_depres_channel = self.GREEDY_DEPRES_CHANNEL
+      else:
+         self.default_depres_channel = self.NONGREEDY_DEPRES_CHANNEL
+   # --- end of set_greedy (...) ---
+
    def _update_resolver ( self ):
       """Updates the resolver.
 
@@ -431,7 +456,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
          )
    # --- end of visualize_pools (...) ---
 
-   def get_channel ( self, channel_name="channel" ):
+   def get_channel ( self, channel_name="channel", greedy=None ):
       """Creates, registers and returns an EbuildJobChannel suitable for
       dependency resolution.
 
@@ -440,15 +465,25 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
 
       arguments:
       * channel_name -- name of the channel (defaults to "channel")
+      * greedy       -- whether to return a greedy or non-greedy depres
+                        channel. The greedy one stops if a mandatory dep
+                        cannot be resolved, whereas the non-greedy one keeps
+                        going until all deps have been processed.
+                        Defaults to None (=use default channel).
       """
-      channel = roverlay.depres.channels.EbuildJobChannel (
-         err_queue=self.err_queue, name=channel_name
-      )
+      if greedy is None:
+         channel_cls = self.default_depres_channel
+      elif greedy:
+         channel_cls = self.GREEDY_DEPRES_CHANNEL
+      else:
+         channel_cls = self.NONGREEDY_DEPRES_CHANNEL
+
+      channel = channel_cls ( err_queue=self.err_queue, name=channel_name )
       self._resolver.register_channel ( channel )
       return channel
    # --- end of get_channel (...) ---
 
-   def do_resolve ( self, deps, with_deptype=DEFAULT_DEPTYPE ):
+   def do_resolve ( self, deps, with_deptype=DEFAULT_DEPTYPE, greedy=None ):
       """Performs dependency resolution for the given dependency list and
       returns the result, which is None (=not resolved) or a 2-tuple
       (<resolved deps>, <unresolvable, but optional deps>).
@@ -459,6 +494,8 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       arguments:
       * deps         -- dependency string list
       * with_deptype -- dependency type (optional, defaults to DEFAULT_DEPTYPE)
+      * greedy       -- whether to use a greedy depres channel or not
+                         Defaults to None.
       """
       channel = self.get_channel()
       # FIXME/COULDFIX: once again, hardcoded deptype
@@ -467,7 +504,8 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
 
          channel_result = channel.satisfy_request (
             close_if_unresolvable=False,
-            preserve_order=True
+            preserve_order=True,
+            want_tuple=self.want_tuple,
          )
       finally:
          channel.close()
@@ -475,6 +513,23 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       return channel_result
    # --- end of do_resolve (...) ---
 
+   def _do_resolve_weak_greedy ( self, deps, kw, greedy=True ):
+      """Calls do_resolve ( deps, **kw ) with the given greedy mode unless
+      greedy is in kw.
+
+      Passes do_resolve()'s return value.
+
+      arguments:
+      * deps   --
+      * kw     --
+      * greedy -- defaults to True
+      """
+      if 'greedy' in kw:
+         return self.do_resolve ( deps, **kw )
+      else:
+         return self.do_resolve ( deps, greedy=greedy, **kw )
+   # --- end of _do_resolve_weak_greedy (...) ---
+
    def resolve ( self, *deps, **kw ):
       """Like do_resolve(), but accepts the dependency string list in var-args
       form and returns None (=not resolved) or a list of resolved dependencies.
@@ -499,7 +554,9 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       * *deps --
       * **kw  --
       """
-      return self.do_resolve ( deps, **kw ) is not None
+      return (
+         self._do_resolve_weak_greedy ( deps, kw, greedy=True ) is not None
+      )
    # --- end of can_resolve (...) ---
 
    def cannot_resolve ( self, *deps, **kw ):
@@ -510,7 +567,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
       * *deps --
       * **kw  --
       """
-      return self.do_resolve ( deps, **kw ) is None
+      return self._do_resolve_weak_greedy ( deps, kw, greedy=True ) is None
    # --- end of cannot_resolve (...) ---
 
 # --- end of DepresInterface ---


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2014-06-05 22:09 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2014-06-05 22:09 UTC (permalink / raw
  To: gentoo-commits

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

roverlay/interface: new_standalone()

Allows to create standalone interfaces, which use a dummy config by default.

---
 roverlay/interface/generic.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 roverlay/interface/root.py    | 21 +++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/roverlay/interface/generic.py b/roverlay/interface/generic.py
index 8fc7239..66b6cb8 100644
--- a/roverlay/interface/generic.py
+++ b/roverlay/interface/generic.py
@@ -134,6 +134,49 @@ class RoverlaySubInterface ( RoverlayInterface ):
    a parent interface.
    """
 
+   # we don't know anything about concrete root interfaces in this module
+   ROOT_INTERFACE_CLS = NotImplemented
+
+   @classmethod
+   def get_standalone_root_interface (
+      cls, is_installed, config, config_file, **kwargs
+   ):
+      assert cls.ROOT_INTERFACE_CLS is not NotImplemented
+
+      if config or config_file:
+         return cls.ROOT_INTERFACE_CLS (
+            config=config, config_file=config_file,
+            is_installed=is_installed,
+            **kwargs
+         )
+      else:
+         return cls.ROOT_INTERFACE_CLS (
+            config=False, is_installed=is_installed, **kwargs
+         )
+   # --- end of get_standalone_root_interface (...) ---
+
+   @classmethod
+   def new_standalone (
+      cls,
+      is_installed=False, config=None, config_file=None,
+      **kwargs
+   ):
+      """Creates a new interface with an anonymous parent interface.
+
+      arguments:
+      * is_installed -- passed to get_standalone_root_interface()
+      * config       -- passed to get_standalone_root_interface()
+      * config_file  -- passed to get_standalone_root_interface()
+      * **kwargs     -- passed to __init__()
+      """
+      return cls (
+         cls.get_standalone_root_interface (
+            is_installed, config, config_file
+         ),
+         **kwargs
+      )
+   # --- end of new_standalone (...) ---
+
    def __init__ ( self, parent_interface ):
       """Initializes the subinterface. Creates references to shared objects
       like logger and config as well as a ref to the parent interface.

diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
index 1ea4ef1..6f6afc9 100644
--- a/roverlay/interface/root.py
+++ b/roverlay/interface/root.py
@@ -9,12 +9,18 @@ import logging
 import roverlay.core
 import roverlay.errorqueue
 import roverlay.hook
+import roverlay.config.tree
 
 import roverlay.interface.generic
 
 # does nothing if already initialized
 roverlay.core.setup_initial_logger()
 
+
+def get_dummy_config():
+   return roverlay.config.tree.ConfigTree()
+# --- end of get_dummy_config (...) ---
+
 class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
    """Root interfaces for accessing roverlay interfaces.
 
@@ -43,6 +49,17 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
          return False
    # --- end of register_interface (...) ---
 
+   @classmethod
+   def new_unconfigured ( cls, **kwargs ):
+      """Creates a new root interface with a dummy config tree.
+
+      arguments:
+      * **kwargs -- passed to __init__()
+      """
+      kwargs ['config'] = False
+      return cls ( **kwargs )
+   # --- end of new_unconfigured (...) ---
+
    def __init__ ( self,
       config_file=None, config=None, additional_config=None, is_installed=None
    ):
@@ -55,6 +72,8 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
       * config_file       -- path to the config file
       * config            -- config tree or None
                               takes precedence over config_file
+                              A dummy config tree will be created if this
+                              arg is False.
       * additional_config -- when loading the config file: extra config dict
       * is_installed      -- whether roverlay has been installed or not
                               Defaults to None.
@@ -66,6 +85,8 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
 
       if getattr ( self, 'config', None ):
          pass
+      elif config is False:
+         self.config = get_dummy_config()
       elif config is not None:
          self.config = config
       elif config_file is not None:


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2014-06-05 22:09 André Erdmann
  0 siblings, 0 replies; 12+ messages in thread
From: André Erdmann @ 2014-06-05 22:09 UTC (permalink / raw
  To: gentoo-commits

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()


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-06-05 22:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-23  7:51 [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/ André Erdmann
2013-07-19 18:00 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
  -- strict thread matches above, loose matches on Subject: below --
2014-06-05 22:09 [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-06-05 22:09 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-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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox