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: