Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/
Date: Thu, 05 Jun 2014 22:09:27
Message-Id: 1399426441.5111d8d0b0a604a22731cd3c7e5d32e8b93b8acc.dywi@gentoo
1 commit: 5111d8d0b0a604a22731cd3c7e5d32e8b93b8acc
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Wed May 7 01:31:55 2014 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Wed May 7 01:34:01 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=5111d8d0
7
8 roverlay/interface: new_standalone()
9
10 Allows to create standalone interfaces, which use a dummy config by default.
11
12 ---
13 roverlay/interface/generic.py | 43 +++++++++++++++++++++++++++++++++++++++++++
14 roverlay/interface/root.py | 21 +++++++++++++++++++++
15 2 files changed, 64 insertions(+)
16
17 diff --git a/roverlay/interface/generic.py b/roverlay/interface/generic.py
18 index 8fc7239..66b6cb8 100644
19 --- a/roverlay/interface/generic.py
20 +++ b/roverlay/interface/generic.py
21 @@ -134,6 +134,49 @@ class RoverlaySubInterface ( RoverlayInterface ):
22 a parent interface.
23 """
24
25 + # we don't know anything about concrete root interfaces in this module
26 + ROOT_INTERFACE_CLS = NotImplemented
27 +
28 + @classmethod
29 + def get_standalone_root_interface (
30 + cls, is_installed, config, config_file, **kwargs
31 + ):
32 + assert cls.ROOT_INTERFACE_CLS is not NotImplemented
33 +
34 + if config or config_file:
35 + return cls.ROOT_INTERFACE_CLS (
36 + config=config, config_file=config_file,
37 + is_installed=is_installed,
38 + **kwargs
39 + )
40 + else:
41 + return cls.ROOT_INTERFACE_CLS (
42 + config=False, is_installed=is_installed, **kwargs
43 + )
44 + # --- end of get_standalone_root_interface (...) ---
45 +
46 + @classmethod
47 + def new_standalone (
48 + cls,
49 + is_installed=False, config=None, config_file=None,
50 + **kwargs
51 + ):
52 + """Creates a new interface with an anonymous parent interface.
53 +
54 + arguments:
55 + * is_installed -- passed to get_standalone_root_interface()
56 + * config -- passed to get_standalone_root_interface()
57 + * config_file -- passed to get_standalone_root_interface()
58 + * **kwargs -- passed to __init__()
59 + """
60 + return cls (
61 + cls.get_standalone_root_interface (
62 + is_installed, config, config_file
63 + ),
64 + **kwargs
65 + )
66 + # --- end of new_standalone (...) ---
67 +
68 def __init__ ( self, parent_interface ):
69 """Initializes the subinterface. Creates references to shared objects
70 like logger and config as well as a ref to the parent interface.
71
72 diff --git a/roverlay/interface/root.py b/roverlay/interface/root.py
73 index 1ea4ef1..6f6afc9 100644
74 --- a/roverlay/interface/root.py
75 +++ b/roverlay/interface/root.py
76 @@ -9,12 +9,18 @@ import logging
77 import roverlay.core
78 import roverlay.errorqueue
79 import roverlay.hook
80 +import roverlay.config.tree
81
82 import roverlay.interface.generic
83
84 # does nothing if already initialized
85 roverlay.core.setup_initial_logger()
86
87 +
88 +def get_dummy_config():
89 + return roverlay.config.tree.ConfigTree()
90 +# --- end of get_dummy_config (...) ---
91 +
92 class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
93 """Root interfaces for accessing roverlay interfaces.
94
95 @@ -43,6 +49,17 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
96 return False
97 # --- end of register_interface (...) ---
98
99 + @classmethod
100 + def new_unconfigured ( cls, **kwargs ):
101 + """Creates a new root interface with a dummy config tree.
102 +
103 + arguments:
104 + * **kwargs -- passed to __init__()
105 + """
106 + kwargs ['config'] = False
107 + return cls ( **kwargs )
108 + # --- end of new_unconfigured (...) ---
109 +
110 def __init__ ( self,
111 config_file=None, config=None, additional_config=None, is_installed=None
112 ):
113 @@ -55,6 +72,8 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
114 * config_file -- path to the config file
115 * config -- config tree or None
116 takes precedence over config_file
117 + A dummy config tree will be created if this
118 + arg is False.
119 * additional_config -- when loading the config file: extra config dict
120 * is_installed -- whether roverlay has been installed or not
121 Defaults to None.
122 @@ -66,6 +85,8 @@ class RootInterface ( roverlay.interface.generic.RoverlayInterface ):
123
124 if getattr ( self, 'config', None ):
125 pass
126 + elif config is False:
127 + self.config = get_dummy_config()
128 elif config is not None:
129 self.config = config
130 elif config_file is not None: