75
75
DEFAULT_XLOG_METHOD = "fetch"
76
76
77
77
78
+ class TestgresConfig :
79
+ cache_pg_config = True
80
+ cache_initdb = True
81
+
82
+
78
83
class TestgresException (Exception ):
79
84
"""
80
85
Base exception
@@ -1081,7 +1086,7 @@ def call_initdb(_data_dir):
1081
1086
raise InitNodeException (str (e ))
1082
1087
1083
1088
# Call initdb if we have custom params
1084
- if initdb_params :
1089
+ if initdb_params or not TestgresConfig . cache_initdb :
1085
1090
call_initdb (data_dir )
1086
1091
# Else we can use cached dir
1087
1092
else :
@@ -1190,25 +1195,31 @@ def get_pg_config():
1190
1195
1191
1196
global pg_config_data
1192
1197
1193
- if not pg_config_data :
1194
- pg_config_cmd = os .environ .get ("PG_CONFIG" ) or "pg_config"
1198
+ if TestgresConfig .cache_pg_config and pg_config_data :
1199
+ return pg_config_data
1200
+
1201
+ data = {}
1202
+ pg_config_cmd = os .environ .get ("PG_CONFIG" ) or "pg_config"
1203
+ out = six .StringIO (subprocess .check_output ([pg_config_cmd ],
1204
+ universal_newlines = True ))
1205
+ for line in out :
1206
+ if line and "=" in line :
1207
+ key , value = line .split ("=" , 1 )
1208
+ data [key .strip ()] = value .strip ()
1195
1209
1196
- out = six .StringIO (subprocess .check_output ([pg_config_cmd ],
1197
- universal_newlines = True ))
1198
- for line in out :
1199
- if line and "=" in line :
1200
- key , value = line .split ("=" , 1 )
1201
- pg_config_data [key .strip ()] = value .strip ()
1210
+ # Fetch version of PostgreSQL and save it as VERSION_NUM
1211
+ version = data ["VERSION" ]
1212
+ version = version .split (" " )[- 1 ] \
1213
+ .partition ('devel' )[0 ] \
1214
+ .partition ('beta' )[0 ] \
1215
+ .partition ('rc' )[0 ]
1216
+ data ["VERSION_NUM" ] = version
1202
1217
1203
- # Fetch version of PostgreSQL and save it as VERSION_NUM
1204
- version = pg_config_data ["VERSION" ]
1205
- version = version .split (" " )[- 1 ] \
1206
- .partition ('devel' )[0 ] \
1207
- .partition ('beta' )[0 ] \
1208
- .partition ('rc' )[0 ]
1209
- pg_config_data ["VERSION_NUM" ] = version
1218
+ if TestgresConfig .cache_pg_config :
1219
+ pg_config_data .clear ()
1220
+ pg_config_data .update (data )
1210
1221
1211
- return pg_config_data
1222
+ return data
1212
1223
1213
1224
1214
1225
def get_new_node (name , base_dir = None , use_logging = False ):
@@ -1225,3 +1236,11 @@ def get_new_node(name, base_dir=None, use_logging=False):
1225
1236
"""
1226
1237
1227
1238
return PostgresNode (name = name , base_dir = base_dir , use_logging = use_logging )
1239
+
1240
+
1241
+ def configure_testgres (** options ):
1242
+ '''
1243
+ Configure testgres. Look for TestgresConfig to check what can be changed.
1244
+ '''
1245
+ for key , option in options .items ():
1246
+ setattr (TestgresConfig , key , option )
0 commit comments