* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/
@ 2013-07-04 17:02 André Erdmann
0 siblings, 0 replies; 7+ messages in thread
From: André Erdmann @ 2013-07-04 17:02 UTC (permalink / raw
To: gentoo-commits
commit: f55428dafdbc849c7ed81d0d5dc1ed3a632d514d
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 4 16:51:16 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 4 16:51:16 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=f55428da
roverlay/interface/depres: fix pool counting
load_rule_files() does no longer bypass pool couting (self._pool_id).
---
roverlay/interface/depres.py | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index e9ac5b7..e16363c 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -80,6 +80,10 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
return self
# --- end of update (...) ---
+ def fixup_pool_id ( self ):
+ self._pool_id = len ( self._poolstack ) - 1
+ # --- end of fixup_pool_id (...) ---
+
def has_pool ( self ):
return self._poolstack
# --- end of has_pool (...) ---
@@ -117,7 +121,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
try:
self._poolstack.pop()
self._pool_id -= 1
- assert self._pool_id >= -1
+ assert self._pool_id >= -1, self._pool_id
return True
except AssertionError:
raise
@@ -133,6 +137,13 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
return count
# --- end of discard_pools (...) ---
+ def discard_all_pools ( self ):
+ i = 0
+ while self.discard_pool():
+ i += 1
+ return i
+ # --- end of discard_all_pools (...) ---
+
def discard_empty_pools ( self ):
removed = 0
while self._poolstack and self._poolstack[-1].empty():
@@ -145,14 +156,23 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
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" )
- )
+ def load_rules_from_config ( self, ignore_missing=False ):
+ if ignore_missing:
+ rule_files = self.config.get ( "DEPRES.simple_rules.files", None )
+ if rule_files:
+ return self.load_rule_files ( rule_files )
+ else:
+ return False
+ else:
+ 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 )
+ 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 ):
^ permalink raw reply related [flat|nested] 7+ 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; 7+ 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] 7+ 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 " André Erdmann
@ 2013-07-19 18:00 ` André Erdmann
0 siblings, 0 replies; 7+ messages in thread
From: André Erdmann @ 2013-07-19 18:00 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] 7+ 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; 7+ 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] 7+ 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 " André Erdmann
@ 2013-07-19 18:00 ` André Erdmann
0 siblings, 0 replies; 7+ 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] 7+ messages in thread
* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/
@ 2013-07-18 19:25 André Erdmann
0 siblings, 0 replies; 7+ messages in thread
From: André Erdmann @ 2013-07-18 19:25 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] 7+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-16 16:36 André Erdmann
2013-07-16 16:35 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
0 siblings, 1 reply; 7+ 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] 7+ messages in thread
* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/
2013-07-16 16:36 [gentoo-commits] proj/R_overlay:master " André Erdmann
@ 2013-07-16 16:35 ` André Erdmann
0 siblings, 0 replies; 7+ messages in thread
From: André Erdmann @ 2013-07-16 16:35 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] 7+ messages in thread
* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/
@ 2013-07-03 17:20 André Erdmann
0 siblings, 0 replies; 7+ messages in thread
From: André Erdmann @ 2013-07-03 17:20 UTC (permalink / raw
To: gentoo-commits
commit: 7dee38ce521eec08275ad6d6a259eaa6ed16602a
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 3 16:59:41 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 3 16:59:41 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=7dee38ce
roverlay/interface: fixup
---
roverlay/interface/depres.py | 2 ++
roverlay/interface/generic.py | 4 +++-
roverlay/interface/main.py | 30 ++++++++++++++++++++++++++++++
roverlay/interface/root.py | 37 ++++++++++++++++++++++++++++++++-----
4 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py
index d416312..e9ac5b7 100644
--- a/roverlay/interface/depres.py
+++ b/roverlay/interface/depres.py
@@ -69,6 +69,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
def close ( self ):
super ( DepresInterface, self ).close()
self._resolver.close()
+ return self
# --- end of close (...) ---
def update ( self ):
@@ -76,6 +77,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ):
if self._poolstack:
self._poolstack[-1].sort()
self._update_resolver()
+ return self
# --- end of update (...) ---
def has_pool ( self ):
diff --git a/roverlay/interface/generic.py b/roverlay/interface/generic.py
index 08806ea..c6678f3 100644
--- a/roverlay/interface/generic.py
+++ b/roverlay/interface/generic.py
@@ -21,10 +21,11 @@ class RoverlayInterface ( object ):
def close ( self ):
self.close_interfaces()
+ return self
# --- end of close (...) ---
def update ( self ):
- pass
+ return self
# --- end of update (...) ---
def attach_interface ( self, name, interface, close_detached=True ):
@@ -37,6 +38,7 @@ class RoverlayInterface ( object ):
def detach_interface ( self, name, close=False ):
detached = self._interfaces [name]
+ del self._interfaces [name]
if close:
detached.close()
return True
diff --git a/roverlay/interface/main.py b/roverlay/interface/main.py
new file mode 100644
index 0000000..dfa89e2
--- /dev/null
+++ b/roverlay/interface/main.py
@@ -0,0 +1,30 @@
+# 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 roverlay
+
+import roverlay.interface.root
+import roverlay.interface.depres
+
+roverlay.setup_initial_logger()
+
+class MainInterface ( roverlay.interface.root.RootInterface ):
+
+ def __init__ ( self, *args, **kwargs ):
+ if args or kwargs:
+ 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
+ )
+ self.__class__.register_interface (
+ "depres", roverlay.interface.depres.DepresInterface
+ )
+ return True
+ # --- end of setup (...) ---
diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
index d500582..a4d287c 100644
--- a/roverlay/interface/root.py
+++ b/roverlay/interface/root.py
@@ -8,6 +8,7 @@ import logging
import roverlay
import roverlay.errorqueue
+import roverlay.hook
import roverlay.interface.generic
@@ -28,24 +29,46 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
# --- end of register_interface (...) ---
def __init__ ( self,
- config_file=None, config=None, additional_config=None
+ config_file=None, config=None, additional_config=None, is_installed=None
):
super ( RootInterface, self ).__init__()
self.parent = None
self.err_queue = roverlay.errorqueue.ErrorQueue()
- if config is not None:
+ if getattr ( self, 'config', None ):
+ pass
+ elif config is not None:
self.config = config
elif config_file is not None:
- self.config = roverlay.load_config_file (
- config_file, extraconf=additional_config
- )
+ if additional_config is None:
+ self.config = roverlay.load_config_file (
+ config_file, extraconf={ 'installed': False, }
+ )
+ else:
+ # modifies additional_config
+ additional_config.update ( { 'installed': False, } )
+
+ self.config = roverlay.load_config_file (
+ config_file, extraconf=additional_config
+ )
else:
raise Exception ( "config, config_file?" )
+
+ if is_installed is not None:
+ self.set_installed ( is_installed )
+ elif self.config.get ( "installed", None ) is None:
+ self.set_installed ( False )
+
self.logger = logging.getLogger ( self.__class__.__name__ )
+
+ roverlay.hook.setup()
# --- end of __init__ (...) ---
+ def set_installed ( self, status=True ):
+ self.config.merge_with ( { 'installed': bool ( status ), } )
+ # --- end of set_installed (...) ---
+
def spawn_interface ( self, name ):
if self.has_interface ( name ):
return self.get_interface ( name )
@@ -60,3 +83,7 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
name, iface_cls ( parent_interface=self )
)
# --- end of spawn_interface (...) ---
+
+ def run_hook ( self, phase ):
+ return roverlay.hook.run ( phase, catch_failure=False )
+ # --- end of run_hook (...) ---
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
@ 2013-07-03 10:05 André Erdmann
2013-07-02 21:09 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
0 siblings, 1 reply; 7+ 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] 7+ messages in thread
* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/
2013-07-03 10:05 [gentoo-commits] proj/R_overlay:master " André Erdmann
@ 2013-07-02 21:09 ` André Erdmann
0 siblings, 0 replies; 7+ messages in thread
From: André Erdmann @ 2013-07-02 21:09 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] 7+ messages in thread
end of thread, other threads:[~2013-07-19 18:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-04 17:02 [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/interface/ André Erdmann
-- strict thread matches above, loose matches on Subject: below --
2013-07-23 7:51 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-19 18:00 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 7:51 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-19 18:00 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-18 19:25 André Erdmann
2013-07-16 16:36 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-16 16:35 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-03 17:20 André Erdmann
2013-07-03 10:05 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-02 21:09 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox