|
1 | 1 | # coding: utf-8 |
2 | 2 |
|
| 3 | +import io |
3 | 4 | import os |
4 | 5 | import port_for |
5 | 6 | import six |
|
10 | 11 | from .config import TestgresConfig |
11 | 12 | from .exceptions import ExecUtilException |
12 | 13 |
|
| 14 | + |
13 | 15 | # rows returned by PG_CONFIG |
14 | 16 | _pg_config_data = {} |
15 | 17 |
|
@@ -77,25 +79,26 @@ def execute_utility(util, args, logfile): |
77 | 79 | stdout=subprocess.PIPE, |
78 | 80 | stderr=subprocess.STDOUT) |
79 | 81 |
|
80 | | - # get result |
| 82 | + # get result and decode it |
81 | 83 | out, _ = process.communicate() |
| 84 | + out = '' if not out else out.decode('utf-8') |
82 | 85 |
|
83 | 86 | # write new log entry if possible |
84 | 87 | try: |
85 | | - with open(logfile, "a") as file_out: |
86 | | - # write util name and args |
87 | | - file_out.write(' '.join([util] + args)) |
88 | | - file_out.write('\n') |
89 | | - if out: |
90 | | - with open(logfile, "ab") as file_out: |
91 | | - # write output |
| 88 | + with io.open(logfile, 'a') as file_out: |
| 89 | + # write util's name and args |
| 90 | + file_out.write(u' '.join([util] + args)) |
| 91 | + |
| 92 | + # write output |
| 93 | + if out: |
| 94 | + file_out.write(u'\n') |
92 | 95 | file_out.write(out) |
| 96 | + |
| 97 | + # finally, a separator |
| 98 | + file_out.write(u'\n') |
93 | 99 | except IOError: |
94 | 100 | pass |
95 | 101 |
|
96 | | - # decode output |
97 | | - out = '' if not out else out.decode('utf-8') |
98 | | - |
99 | 102 | # format exception, if needed |
100 | 103 | error_code = process.returncode |
101 | 104 | if error_code: |
@@ -173,6 +176,7 @@ def get_pg_version(): |
173 | 176 | # there might be no pg_config installed, try this first |
174 | 177 | raw_ver = execute_utility('psql', ['--version'], os.devnull) |
175 | 178 | else: |
| 179 | + # ok, we have no other choice |
176 | 180 | raw_ver = get_pg_config()['VERSION'] |
177 | 181 |
|
178 | 182 | # cook version of PostgreSQL |
|
0 commit comments