Validates the existence and basic working-ness of other programs Implemented because it is easy to get confusing error output when one does not install a dependency because of the fork-worker model that is both necessary for throughput and makes more obscure the cause of failur
(
to_check=frozenset([PSQL_BIN, LZOP_BIN, PV_BIN]))
| 84 | |
| 85 | |
| 86 | def external_program_check( |
| 87 | to_check=frozenset([PSQL_BIN, LZOP_BIN, PV_BIN])): |
| 88 | """ |
| 89 | Validates the existence and basic working-ness of other programs |
| 90 | |
| 91 | Implemented because it is easy to get confusing error output when |
| 92 | one does not install a dependency because of the fork-worker model |
| 93 | that is both necessary for throughput and makes more obscure the |
| 94 | cause of failures. This is intended to be a time and frustration |
| 95 | saving measure. This problem has confused The Author in practice |
| 96 | when switching rapidly between machines. |
| 97 | |
| 98 | """ |
| 99 | |
| 100 | could_not_run = [] |
| 101 | error_msgs = [] |
| 102 | |
| 103 | def psql_err_handler(popen): |
| 104 | assert popen.returncode != 0 |
| 105 | error_msgs.append(textwrap.fill( |
| 106 | 'Could not get a connection to the database: ' |
| 107 | 'note that superuser access is required')) |
| 108 | |
| 109 | # Bogus error message that is re-caught and re-raised |
| 110 | raise EnvironmentError('INTERNAL: Had problems running psql ' |
| 111 | 'from external_program_check') |
| 112 | |
| 113 | with open(os.devnull, 'wb') as nullf: |
| 114 | for program in to_check: |
| 115 | try: |
| 116 | if program is PSQL_BIN: |
| 117 | psql_csv_run('SELECT 1', error_handler=psql_err_handler) |
| 118 | else: |
| 119 | if program is PV_BIN: |
| 120 | extra_args = ['--quiet'] |
| 121 | else: |
| 122 | extra_args = [] |
| 123 | |
| 124 | proc = popen_sp([program] + extra_args, |
| 125 | stdout=nullf, stderr=nullf, |
| 126 | stdin=subprocess.PIPE) |
| 127 | |
| 128 | # Close stdin for processes that default to |
| 129 | # reading from the pipe; the programs WAL-E uses |
| 130 | # of this kind will terminate in this case. |
| 131 | proc.stdin.close() |
| 132 | proc.wait() |
| 133 | except EnvironmentError: |
| 134 | could_not_run.append(program) |
| 135 | |
| 136 | if could_not_run: |
| 137 | error_msgs.append( |
| 138 | 'Could not run the following programs, are they installed? ' + |
| 139 | ', '.join(could_not_run)) |
| 140 | |
| 141 | if error_msgs: |
| 142 | raise UserException( |
| 143 | 'could not run one or more external programs WAL-E depends upon', |