@@ -292,11 +292,11 @@ def __init__(self,
292
292
if not node .status ():
293
293
raise BackupException ('Node must be running' )
294
294
295
- # set default arguments
295
+ # Set default arguments
296
296
username = username or default_username ()
297
297
base_dir = base_dir or tempfile .mkdtemp ()
298
298
299
- # create directory if needed
299
+ # Create directory if needed
300
300
if base_dir and not os .path .exists (base_dir ):
301
301
os .makedirs (base_dir )
302
302
@@ -350,7 +350,7 @@ def _prepare_dir(self, destroy):
350
350
else :
351
351
base_dir = self .base_dir
352
352
353
- # update value
353
+ # Update value
354
354
self .available = available
355
355
356
356
return base_dir
@@ -370,12 +370,15 @@ def spawn_primary(self, name, destroy=True, use_logging=False):
370
370
371
371
base_dir = self ._prepare_dir (destroy )
372
372
373
- # build a new PostgresNode
373
+ # Build a new PostgresNode
374
374
node = PostgresNode (name = name ,
375
375
base_dir = base_dir ,
376
376
master = self .original_node ,
377
377
use_logging = use_logging )
378
378
379
+ # New nodes should always remove dir tree
380
+ node .should_rm_dirs = True
381
+
379
382
node .append_conf ("postgresql.conf" , "\n " )
380
383
node .append_conf ("postgresql.conf" , "port = {}" .format (node .port ))
381
384
@@ -1149,13 +1152,14 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
1149
1152
util: utility to be executed (str).
1150
1153
args: arguments for utility (list).
1151
1154
logfile: stores stdout and stderr (str).
1155
+ write_to_pipe: do we care about stdout?
1152
1156
1153
1157
Returns:
1154
1158
stdout of executed utility.
1155
1159
"""
1156
1160
1157
- with open ( logfile , "a" ) as file_out , \
1158
- open (os .devnull , "w" ) as devnull : # hack for 2.7
1161
+ # we can't use subprocess.DEVNULL on 2.7
1162
+ with open (os .devnull , "w" ) as devnull :
1159
1163
1160
1164
# choose file according to options
1161
1165
stdout_file = subprocess .PIPE if write_to_pipe else devnull
@@ -1169,10 +1173,16 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
1169
1173
out , _ = process .communicate ()
1170
1174
out = '' if not out else out .decode ('utf-8' )
1171
1175
1172
- # write new log entry
1173
- file_out .write ('' .join (map (lambda x : str (x ) + ' ' , [util ] + args )))
1174
- file_out .write ('\n ' )
1175
- file_out .write (out )
1176
+ # write new log entry if possible
1177
+ try :
1178
+ with open (logfile , "a" ) as file_out :
1179
+ # write util name + args
1180
+ file_out .write ('' .join (map (lambda x : str (x ) + ' ' ,
1181
+ [util ] + args )))
1182
+ file_out .write ('\n ' )
1183
+ file_out .write (out )
1184
+ except FileNotFoundError :
1185
+ pass
1176
1186
1177
1187
if process .returncode :
1178
1188
error_text = (
0 commit comments