parallel: --env implemented. Test fails, man page missing.

This commit is contained in:
Ole Tange 2012-09-23 23:21:13 +02:00
parent cdb8944aad
commit 1f5be2bb43
4 changed files with 54 additions and 8 deletions

View file

@ -181,6 +181,11 @@ New in this release:
* GNU Parallel is accepted for Ubuntu Quantal. * GNU Parallel is accepted for Ubuntu Quantal.
http://packages.ubuntu.com/quantal/parallel http://packages.ubuntu.com/quantal/parallel
* Blog post in Japanese by Siguniang.
https://siguniang.wordpress.com/2012/09/09/notes-on-gnu-parallel-the-command-line-power-tool/
(Siguniang mentions the logo is called 'The Cafe Wall Illusion')
http://www.michaelbach.de/ot/ang_cafewall/index.html
* GNU Parallel, where have you been all my life? * GNU Parallel, where have you been all my life?
http://ssdigit.nothingisreal.com/2012/09/gnu-parallel-where-have-you-been-all-my.html http://ssdigit.nothingisreal.com/2012/09/gnu-parallel-where-have-you-been-all-my.html

View file

@ -520,6 +520,7 @@ sub options_hash {
"arg-sep|argsep=s" => \$::opt_arg_sep, "arg-sep|argsep=s" => \$::opt_arg_sep,
"arg-file-sep|argfilesep=s" => \$::opt_arg_file_sep, "arg-file-sep|argfilesep=s" => \$::opt_arg_file_sep,
"trim=s" => \$::opt_trim, "trim=s" => \$::opt_trim,
"env=s" => \@::opt_env,
"plain" => \$::opt_plain, "plain" => \$::opt_plain,
"profile|J=s" => \@::opt_profile, "profile|J=s" => \@::opt_profile,
"pipe|spreadstdin" => \$::opt_pipe, "pipe|spreadstdin" => \$::opt_pipe,
@ -595,7 +596,7 @@ sub get_options_from_array {
sub parse_options { sub parse_options {
# Returns: N/A # Returns: N/A
# Defaults: # Defaults:
$Global::version = 20120822; $Global::version = 20120903;
$Global::progname = 'parallel'; $Global::progname = 'parallel';
$Global::infinity = 2**31; $Global::infinity = 2**31;
$Global::debug = 0; $Global::debug = 0;
@ -812,6 +813,7 @@ sub parse_options {
} }
parse_sshlogin(); parse_sshlogin();
parse_env_var();
if(remote_hosts() and ($::opt_X or $::opt_m or $::opt_xargs)) { if(remote_hosts() and ($::opt_X or $::opt_m or $::opt_xargs)) {
# As we do not know the max line length on the remote machine # As we do not know the max line length on the remote machine
@ -826,6 +828,27 @@ sub parse_options {
open_joblog(); open_joblog();
} }
sub parse_env_var {
# Parse --env and set $Global::envvar
# Returns: N/A
$Global::envvar = "";
my @vars = ();
for my $varstring (@::opt_env) {
# Split up --env VAR1,VAR2
push @vars, split /,/, $varstring;
}
$Global::envvar =
(q{eval `echo $SHELL | grep -E "/(t)?csh" > /dev/null}
. q{ && echo }
. join("", map { "setenv $_ "
. ::shell_quote_scalar(::shell_quote_scalar($ENV{$_})).'\;' } @vars)
. q{ || echo }
. join("", map { "export $_="
. ::shell_quote_scalar(::shell_quote_scalar($ENV{$_})).'\;' } @vars)
.q{`;});
$Global::envvarlen = length $Global::envvar;
}
sub open_joblog { sub open_joblog {
my $append = 0; my $append = 0;
if($::opt_resume and not $::opt_joblog) { if($::opt_resume and not $::opt_joblog) {
@ -3423,7 +3446,7 @@ sub sshlogin_wrap {
my $sshlogin = $self->sshlogin(); my $sshlogin = $self->sshlogin();
my $sshcmd = $sshlogin->sshcommand(); my $sshcmd = $sshlogin->sshcommand();
my $serverlogin = $sshlogin->serverlogin(); my $serverlogin = $sshlogin->serverlogin();
my $next_command_line = $self->replaced(); my $next_command_line = $Global::envvar.$self->replaced();
my ($pre,$post,$cleanup)=("","",""); my ($pre,$post,$cleanup)=("","","");
if($serverlogin eq ":") { if($serverlogin eq ":") {
$self->{'sshlogin_wrap'} = $next_command_line; $self->{'sshlogin_wrap'} = $next_command_line;
@ -3440,12 +3463,14 @@ sub sshlogin_wrap {
} }
# If the remote login shell is (t)csh then use 'setenv' # If the remote login shell is (t)csh then use 'setenv'
# otherwise use 'export' # otherwise use 'export'
# We cannot use parse_env_var(), as PARALLEL_SEQ changes
# for each command
my $parallel_env = my $parallel_env =
q{'eval `echo $SHELL | grep -E "/(t)?csh" > /dev/null} (q{ 'eval `echo $SHELL | grep -E "/(t)?csh" > /dev/null }
. q{ && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;} . q{ && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; }
. q{ setenv PARALLEL_PID '$PARALLEL_PID'} . q{ setenv PARALLEL_PID '$PARALLEL_PID' }
. q{ || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;} . q{ || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; }
. q{PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'}; . q{ PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' });
if($::opt_workdir) { if($::opt_workdir) {
$self->{'sshlogin_wrap'} = $self->{'sshlogin_wrap'} =
($pre . "$sshcmd $serverlogin $parallel_env " ($pre . "$sshcmd $serverlogin $parallel_env "
@ -4202,6 +4227,8 @@ sub len {
# Worse than worst case: every char needs to be quoted with \ twice # Worse than worst case: every char needs to be quoted with \ twice
$len *= 4; $len *= 4;
} }
# If we are using --env, add the prefix for that, too.
$len += $Global::envvarlen;
return $len; return $len;
} }

View file

@ -354,7 +354,8 @@ k, m, g, t, or p which would multiply the size with 1024, 1048576,
1000000000, 1000000000000, or 1000000000000000 respectively. 1000000000, 1000000000000, or 1000000000000000 respectively.
GNU B<parallel> tries to meet the block size but can be off by the GNU B<parallel> tries to meet the block size but can be off by the
length of one record. length of one record. For performance reasons I<size> should be bigger
than a single record.
I<size> defaults to 1M. I<size> defaults to 1M.

View file

@ -3,6 +3,19 @@
echo '### Test slow arguments generation - https://savannah.gnu.org/bugs/?32834' echo '### Test slow arguments generation - https://savannah.gnu.org/bugs/?32834'
seq 1 3 | parallel -j1 "sleep 2; echo {}" | parallel -kj2 echo seq 1 3 | parallel -j1 "sleep 2; echo {}" | parallel -kj2 echo
echo '### Test --env - https://savannah.gnu.org/bugs/?37351'
export TWOSPACES=' 2 spaces '
export THREESPACES=" > My brother's 12\" records < "
parallel --env TWOSPACES echo 'a"$TWOSPACES"b' ::: 1
parallel --env TWOSPACES --env THREESPACES echo 'a"$TWOSPACES"b' 'a"$THREESPACES"b' ::: 2
parallel --env TWOSPACES,THREESPACES echo 'a"$TWOSPACES"b' 'a"$THREESPACES"b' ::: 2a
parallel -S localhost --env TWOSPACES echo 'a"$TWOSPACES"b' ::: 1
parallel -S localhost --env TWOSPACES --env THREESPACES echo 'a"$TWOSPACES"b' 'a"$THREESPACES"b' ::: 2
parallel -S localhost --env TWOSPACES,THREESPACES echo 'a"$TWOSPACES"b' 'a"$THREESPACES"b' ::: 2a
parallel -S csh@localhost --env TWOSPACES echo 'a"$TWOSPACES"b' ::: 1
parallel -S csh@localhost --env TWOSPACES --env THREESPACES echo 'a"$TWOSPACES"b' 'a"$THREESPACES"b' ::: 2
parallel -S csh@localhost --env TWOSPACES,THREESPACES echo 'a"$TWOSPACES"b' 'a"$THREESPACES"b' ::: 2a
echo '### Test too slow spawning' echo '### Test too slow spawning'
killall -9 burnP6 2>/dev/null killall -9 burnP6 2>/dev/null
seq 1 2 | parallel -j2 -N0 timeout -k 25 26 burnP6 & seq 1 2 | parallel -j2 -N0 timeout -k 25 26 burnP6 &