From 2e26627e39b15f27be6b6246e9822e7c84879b75 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Wed, 26 Jun 2019 23:11:33 +0200 Subject: [PATCH] parallel: -J ./profile, -J /abs/profile, -J configprofile. parallel: Fixed bug #56558: --rrs with --recend that is not regexp. --- doc/release_new_version | 4 +++ src/parallel | 36 +++++++++++++++---- src/parallel_alternatives.pod | 18 ++++++---- testsuite/tests-to-run/parallel-local-0.3s.sh | 18 ++++++++++ testsuite/wanted-results/parallel-local-0.3s | 8 +++++ 5 files changed, 71 insertions(+), 13 deletions(-) diff --git a/doc/release_new_version b/doc/release_new_version index ce8f5c9b..94b4deb8 100644 --- a/doc/release_new_version +++ b/doc/release_new_version @@ -224,6 +224,10 @@ New in this release: * {= uq; =} causes the replacement string to be unquoted. Example: parallel echo '{=uq;=}.jpg' ::: '*' +* --tagstring {=...=} is now evaluated for each line with --linebuffer. + +* Use -J ./profile to read a profile in current dir. + * Speedup of startup by 40%: Find the parent shell differerently on GNU/Linux, cache information about the CPU and which setpgrp method to use to make GNU Parallel start 40% faster. https://techieroop.com/how-to-run-multiple-bash-scripts-in-parallel/ diff --git a/src/parallel b/src/parallel index 35c554bc..d1ce2a4d 100755 --- a/src/parallel +++ b/src/parallel @@ -2552,13 +2552,20 @@ sub read_options() { # --profile overrides default profiles @profiles = (); for my $profile (@opt::profile) { - # Look for the $profile in . and @Global::config_dirs - push @profiles, grep { -r $_ } - map { "$_/$profile" } ".", @Global::config_dirs; + if($profile =~ m:^\./|^/:) { + # Look for ./profile in . + # Look for /profile in / + push @profiles, grep { -r $_ } $profile; + } else { + # Look for the $profile in @Global::config_dirs + push @profiles, grep { -r $_ } + map { "$_/$profile" } @Global::config_dirs; + } } } for my $profile (@profiles) { if(-r $profile) { + ::debug("init","Read $profile\n"); local $/ = "\n"; open (my $in_fh, "<", $profile) || ::die_bug("read-profile: $profile"); @@ -8161,11 +8168,26 @@ sub block_length($) { } sub remove_rec_sep($) { + # Remove --recstart and --recend from $block + # Input: + # $block_ref = reference to $block to be modified + # $recstart = --recstart + # $recend = --recend + # Uses: + # $opt::regexp = Are --recstart/--recend regexp? + # Returns: + # N/A my ($block_ref,$recstart,$recend) = @_; # Remove record separator - $$block_ref =~ s/$recend$recstart//gos; - $$block_ref =~ s/^$recstart//os; - $$block_ref =~ s/$recend$//os; + if($opt::regexp) { + $$block_ref =~ s/$recend$recstart//gos; + $$block_ref =~ s/^$recstart//os; + $$block_ref =~ s/$recend$//os; + } else { + $$block_ref =~ s/\Q$recend$recstart\E//gos; + $$block_ref =~ s/^\Q$recstart\E//os; + $$block_ref =~ s/\Q$recend\E$//os; + } } sub non_blocking_write($) { @@ -8176,7 +8198,7 @@ sub non_blocking_write($) { my $in = $self->fh(0,"w"); my $rv = syswrite($in, substr($self->{'block'},$self->{'block_pos'})); - if (!defined($rv) && $! == EAGAIN()) { + if (!defined($rv) && $! == ::EAGAIN()) { # would block - but would have written $something_written = 0; # avoid triggering auto expanding block diff --git a/src/parallel_alternatives.pod b/src/parallel_alternatives.pod index 554ecf58..2dd90c6a 100644 --- a/src/parallel_alternatives.pod +++ b/src/parallel_alternatives.pod @@ -1853,30 +1853,36 @@ https://github.com/spion/npm-parallel (Last checked: 2019-01) B runs tasks in parallel. It gives time stamped output. It buffers in RAM. The examples from README.md: + # Put shorthand for timestamp in config for the examples + echo '--rpl '\ + \''{time} $_=::strftime("%Y-%m-%d %H:%M:%S",localtime())'\' \ + > ~/.parallel/machma + echo '--line-buffer --tagstring "{#} {time} {}"' >> ~/.parallel/machma + find . -iname '*.jpg' | machma -- mogrify -resize 1200x1200 -filter Lanczos {} find . -iname '*.jpg' | - parallel mogrify -resize 1200x1200 -filter Lanczos {} + parallel --bar -Jmachma mogrify -resize 1200x1200 -filter Lanczos {} cat /tmp/ips | machma -p 2 -- ping -c 2 -q {} - cat /tmp/ips | parallel -j 2 --tag --line-buffer ping -c 2 -q {} + cat /tmp/ips | parallel -j2 -Jmachma ping -c 2 -q {} cat /tmp/ips | machma -- sh -c 'ping -c 2 -q $0 > /dev/null && echo alive' {} cat /tmp/ips | - parallel --tag 'ping -c 2 -q {} > /dev/null && echo alive' + parallel -Jmachma 'ping -c 2 -q {} > /dev/null && echo alive' find . -iname '*.jpg' | machma --timeout 5s -- mogrify -resize 1200x1200 -filter Lanczos {} find . -iname '*.jpg' | - parallel --timeout 5s mogrify -resize 1200x1200 -filter Lanczos {} + parallel --timeout 5s --bar mogrify -resize 1200x1200 -filter Lanczos {} find . -iname '*.jpg' -print0 | machma --null -- mogrify -resize 1200x1200 -filter Lanczos {} find . -iname '*.jpg' -print0 | - parallel --null mogrify -resize 1200x1200 -filter Lanczos {} + parallel --null --bar mogrify -resize 1200x1200 -filter Lanczos {} -https://github.com/fd0/machma (Last checked: 2019-01) +https://github.com/fd0/machma (Last checked: 2019-06) =head2 DIFFERENCES BETWEEN interlace AND GNU Parallel diff --git a/testsuite/tests-to-run/parallel-local-0.3s.sh b/testsuite/tests-to-run/parallel-local-0.3s.sh index 24779a18..6505e804 100644 --- a/testsuite/tests-to-run/parallel-local-0.3s.sh +++ b/testsuite/tests-to-run/parallel-local-0.3s.sh @@ -747,6 +747,24 @@ par_delimiter_space() { parallel -d " " echo ::: "1 done" } +par_recend_not_regexp() { + echo '### bug #56558: --rrs with --recend that is not regexp' + echo 'a+b' | parallel -k --pipe --rrs --recend '+' -N1 'cat;echo end' +} + +par_profile() { + echo '### Test -J profile, -J /dir/profile, -J ./profile' + echo --tag > testprofile_local + parallel -J ./testprofile_local echo ::: local + rm testprofile_local + echo --tag > testprofile_abs + parallel -J `pwd`/testprofile_abs echo ::: abs + rm testprofile_abs + echo --tag > ~/.parallel/testprofile_config + parallel -J testprofile_config echo ::: config + rm ~/.parallel/testprofile_config +} + export -f $(compgen -A function | grep par_) compgen -A function | grep par_ | LC_ALL=C sort | diff --git a/testsuite/wanted-results/parallel-local-0.3s b/testsuite/wanted-results/parallel-local-0.3s index 873e727a..3b54951e 100644 --- a/testsuite/wanted-results/parallel-local-0.3s +++ b/testsuite/wanted-results/parallel-local-0.3s @@ -616,6 +616,10 @@ par_pipepart_recend_recstart 9 par_pipepart_recend_recstart 10 par_pipepart_roundrobin ### bug #45769: --round-robin --pipepart gives wrong results par_pipepart_roundrobin 2 +par_profile ### Test -J profile, -J /dir/profile, -J ./profile +par_profile local local +par_profile abs abs +par_profile config config par_python_children ### bug #49970: Python child process dies if --env is used par_quote ### Test -q par_quote a b @@ -731,6 +735,10 @@ par_read_from_stdin b 6 par_read_from_stdin b 7 par_read_from_stdin b 8 par_read_from_stdin b 9 +par_recend_not_regexp ### bug #56558: --rrs with --recend that is not regexp +par_recend_not_regexp aend +par_recend_not_regexp b +par_recend_not_regexp end par_replace_replacementstring ### Test replace {} par_replace_replacementstring replace curlies par_replace_replacementstring replace curlies