From: Daniele Varrazzo Date: Fri, 6 Oct 2023 13:02:50 +0000 (+0200) Subject: feat(tools): allow to specify the files to convert async to sync X-Git-Tag: pool-3.2.0~12^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5e32dcd9cf6fe1f9c46170cb0f78ee3733efc27;p=thirdparty%2Fpsycopg.git feat(tools): allow to specify the files to convert async to sync --- diff --git a/tools/convert_async_to_sync.sh b/tools/convert_async_to_sync.sh index 19dfbe111..68732131f 100755 --- a/tools/convert_async_to_sync.sh +++ b/tools/convert_async_to_sync.sh @@ -7,40 +7,62 @@ set -euo pipefail dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${dir}/.." +function log { + echo "$@" >&2 +} +function error { + # Print an error message and exit. + log " +ERROR: $@" + exit 1 +} + check= # If --check is used, give an error if files are changed # (note: it's not a --dry-run) if [[ ${1:-} == '--check' ]]; then check=1 + shift fi +all_inputs=" + psycopg/psycopg/connection_async.py + psycopg/psycopg/cursor_async.py + psycopg_pool/psycopg_pool/null_pool_async.py + psycopg_pool/psycopg_pool/pool_async.py + psycopg_pool/psycopg_pool/sched_async.py + tests/pool/test_pool_async.py + tests/pool/test_pool_common_async.py + tests/pool/test_pool_null_async.py + tests/pool/test_sched_async.py + tests/test_connection_async.py + tests/test_copy_async.py + tests/test_cursor_async.py + tests/test_cursor_client_async.py + tests/test_cursor_common_async.py + tests/test_cursor_raw_async.py + tests/test_cursor_server_async.py + tests/test_pipeline_async.py + tests/test_prepared_async.py + tests/test_tpc_async.py + tests/test_transaction_async.py +" + +# Take other arguments as file names if specified +if [[ ${1:-} ]]; then + inputs="$@" +else + inputs="$all_inputs" +fi + + outputs="" -for async in \ - psycopg/psycopg/connection_async.py \ - psycopg/psycopg/cursor_async.py \ - psycopg_pool/psycopg_pool/null_pool_async.py \ - psycopg_pool/psycopg_pool/pool_async.py \ - psycopg_pool/psycopg_pool/sched_async.py \ - tests/pool/test_pool_async.py \ - tests/pool/test_pool_common_async.py \ - tests/pool/test_pool_null_async.py \ - tests/pool/test_sched_async.py \ - tests/test_connection_async.py \ - tests/test_copy_async.py \ - tests/test_cursor_async.py \ - tests/test_cursor_client_async.py \ - tests/test_cursor_common_async.py \ - tests/test_cursor_raw_async.py \ - tests/test_cursor_server_async.py \ - tests/test_pipeline_async.py \ - tests/test_prepared_async.py \ - tests/test_tpc_async.py \ - tests/test_transaction_async.py -do +for async in $inputs; do + test -f "${async}" || error "file not found: '${async}'" sync=${async/_async/} - echo "converting '${async}' -> '${sync}'" >&2 + log "converting '${async}' -> '${sync}'" python "${dir}/async_to_sync.py" ${async} > ${sync} black -q ${sync} outputs="$outputs ${sync}" @@ -48,8 +70,6 @@ done if [[ $check ]]; then if ! git diff --exit-code $outputs; then - echo " -ERROR: sync and async files out of sync!" >&2 - exit 1 + error "sync and async files... out of sync!" fi fi