Commit ca5ae218 authored by Vincent Pelletier's avatar Vincent Pelletier

parallel_parse.sh: Cosmetic changes

Make it a bit more readable.
Use non-abbreviated arguments when available.
Use lower-case for variable names, which is the de-facto for non-exported
variables.
Shift once instead of after each argument.
Make the script exit if it expands an unset variable or any call fails.
parent ffdc722a
#!/bin/bash #!/bin/bash
set -eu
usage() { usage() {
echo "Usage:" echo "Usage:"
echo " find [...] -print0 | $0 \\" echo " find [...] -print0 | $0 \\"
...@@ -22,16 +23,26 @@ if [ "$1" = "-h" -o "$1" = "--help" ]; then ...@@ -22,16 +23,26 @@ if [ "$1" = "-h" -o "$1" = "--help" ]; then
exit 0 exit 0
fi fi
PARALLELISM="$1" parallelism="$1"
shift state_dir="$2"
STATE_DIR="$1" out_file="$3"
mkdir -p "$STATE_DIR" || exit $? shift 3
shift mkdir -p "$state_dir"
OUT_FILE="$1"
shift
# XXX: any simpler way ? # XXX: any simpler way ?
xargs -0 -r -n 1 -P "$PARALLELISM" -I "@FILE@" -- "$SHELL" -c 'INFILE="$1";shift;STATE_DIR="$1";shift;echo -n .;exec "$@" -Q --format json --out "$STATE_DIR/$(sed s:/:@:g <<< "$INFILE").json" "$INFILE"' "$0" "@FILE@" "$STATE_DIR" "$@" xargs \
-0 \
--no-run-if-empty \
--max-args=1 \
--max-procs="$parallelism" \
-I "@FILE@" \
-- \
"$SHELL" \
-c 'infile="$1";stte_dir="$2";shift 2;echo -n .;exec "$@" -Q --format json --out "$state_dir/$(sed s:/:@:g <<< "$infile").json" "$infile"' \
"$0" \
"@FILE@" \
"$state_dir" \
"$@"
echo echo
# XXX: what if there are too many state files for a single execution ? # XXX: what if there are too many state files for a single execution ?
find "$STATE_DIR" -type f -print0 | xargs -0 -r "$@" --out "$OUT_FILE" --state-file find "$state_dir" -type f -print0 | xargs -0 --exit --no-run-if-empty "$@" --out "$out_file" --state-file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment