Skip to content

Commit 63d9daf

Browse files
committed
Python 3 fixes
1 parent 5bb336d commit 63d9daf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

files/backup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ def write_backup_file(backup_path, file_contents, file_name):
181181
file_path = os.path.join(backup_path, state.label, file_name)
182182
cmd = state.rsync_cmd
183183
# use a tempfile with rsync since the path might be remote
184-
with tempfile.NamedTemporaryFile(mode='wb', prefix='postgresql_backup_') as fh:
184+
mode = 'w' if isinstance(file_contents, str) else 'wb'
185+
with tempfile.NamedTemporaryFile(mode=mode, prefix='postgresql_backup_') as fh:
185186
fh.write(file_contents)
186187
fh.flush()
187188
cmd.extend([fh.name, file_path])
@@ -207,6 +208,8 @@ def get_current_labels(backup_path):
207208
cmd = state.rsync_cmd
208209
cmd.extend(['--list-only', backup_path.rstrip('/') + '/'])
209210
out = subprocess.check_output(cmd)
211+
if sys.version_info > (3,):
212+
out = out.decode('utf-8')
210213
labels = []
211214
# there doesn't appear to be a way to format rsync --list-only output
212215
for line in out.splitlines():

0 commit comments

Comments
 (0)