13
13
14
14
class GlobalConfig (object ):
15
15
"""
16
- Global config (override default settings).
17
-
18
- Attributes:
19
- cache_initdb: shall we use cached initdb instance?
20
- cached_initdb_dir: shall we create a temp dir for cached initdb?
21
- cached_initdb_unique: shall we assign new node a unique system id?
22
-
23
- cache_pg_config: shall we cache pg_config results?
24
-
25
- temp_dir: base temp dir for nodes with default 'base_dir'.
26
-
27
- use_python_logging: use python logging configuration for all nodes.
28
- error_log_lines: N of log lines to be shown in exception (0=inf).
29
-
30
- node_cleanup_full: shall we remove EVERYTHING (including logs)?
31
- node_cleanup_on_good_exit: remove base_dir on nominal __exit__().
32
- node_cleanup_on_bad_exit: remove base_dir on __exit__() via exception.
33
-
34
- NOTE: attributes must not be callable or begin with __.
16
+ Global configuration object which allows user to override default settings.
35
17
"""
18
+ # NOTE: attributes must not be callable or begin with __.
36
19
37
20
cache_initdb = True
38
- _cached_initdb_dir = None
21
+ """ shall we use cached initdb instance? """
22
+
39
23
cached_initdb_unique = False
24
+ """ shall we give new node a unique system id? """
40
25
41
26
cache_pg_config = True
27
+ """ shall we cache pg_config results? """
42
28
43
29
use_python_logging = False
30
+ """ enable python logging subsystem (see logger.py). """
31
+
44
32
error_log_lines = 20
33
+ """ N of log lines to be shown in exceptions (0=inf). """
45
34
46
35
node_cleanup_full = True
36
+ """ shall we remove EVERYTHING (including logs)? """
37
+
47
38
node_cleanup_on_good_exit = True
39
+ """ remove base_dir on nominal __exit__(). """
40
+
48
41
node_cleanup_on_bad_exit = False
42
+ """ remove base_dir on __exit__() via exception. """
43
+
44
+ _cached_initdb_dir = None
45
+ """ underlying class attribute for cached_initdb_dir property """
49
46
50
47
@property
51
48
def cached_initdb_dir (self ):
49
+ """ path to a temp directory for cached initdb. """
52
50
return self ._cached_initdb_dir
53
51
54
52
@cached_initdb_dir .setter
@@ -60,6 +58,7 @@ def cached_initdb_dir(self, value):
60
58
61
59
@property
62
60
def temp_dir (self ):
61
+ """ path to temp dir containing nodes with default 'base_dir'. """
63
62
return tempfile .tempdir
64
63
65
64
@temp_dir .setter
@@ -82,6 +81,10 @@ def __setattr__(self, name, value):
82
81
super (GlobalConfig , self ).__setattr__ (name , value )
83
82
84
83
def keys (self ):
84
+ """
85
+ Return a list of all available settings.
86
+ """
87
+
85
88
keys = []
86
89
87
90
for key in dir (GlobalConfig ):
@@ -91,15 +94,29 @@ def keys(self):
91
94
return keys
92
95
93
96
def items (self ):
97
+ """
98
+ Return setting-value pairs.
99
+ """
100
+
94
101
return ((key , self [key ]) for key in self .keys ())
95
102
96
103
def update (self , config ):
104
+ """
105
+ Extract setting-value pairs from 'config' and
106
+ assign those values to corresponding settings
107
+ of this GlobalConfig object.
108
+ """
109
+
97
110
for key , value in config .items ():
98
111
self [key ] = value
99
112
100
113
return self
101
114
102
115
def copy (self ):
116
+ """
117
+ Return a copy of this object.
118
+ """
119
+
103
120
return copy .copy (self )
104
121
105
122
@@ -124,8 +141,8 @@ def _rm_cached_initdb_dirs():
124
141
125
142
def push_config (** options ):
126
143
"""
127
- Permanently set custom GlobalConfig options
128
- and put previous settings on top of stack.
144
+ Permanently set custom GlobalConfig options and
145
+ put previous settings on top of the config stack.
129
146
"""
130
147
131
148
# push current config to stack
@@ -150,10 +167,12 @@ def pop_config():
150
167
def scoped_config (** options ):
151
168
"""
152
169
Temporarily set custom GlobalConfig options for this context.
170
+ Previous options are pushed to the config stack.
153
171
154
172
Example:
155
173
>>> from .api import get_new_node
156
174
>>> with scoped_config(cache_initdb=False):
175
+ ... # create a new node with fresh initdb
157
176
... with get_new_node().init().start() as node:
158
177
... print(node.execute('select 1'))
159
178
[(1,)]
@@ -173,7 +192,7 @@ def scoped_config(**options):
173
192
def configure_testgres (** options ):
174
193
"""
175
194
Adjust current global options.
176
- Look at GlobalConfig to learn what can be set .
195
+ Look at the GlobalConfig to learn about existing settings .
177
196
"""
178
197
179
198
testgres_config .update (options )
0 commit comments