Lexical file handles are much simpler to pass around (and generally much cleaner). Also standardize on the 3-parameter open() form.
Signed-off-by: Francois Gouget fgouget@codeweavers.com ---
Some cleanup patches before the big ones.
Having a lexical file handle will come in handy soon. Also, all the other regular file handles will disappear soon so there is no point messing with them.
testbot/bin/WineSendLog.pl | 87 +++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 43 deletions(-)
diff --git a/testbot/bin/WineSendLog.pl b/testbot/bin/WineSendLog.pl index ac14e11dc..9ed83367b 100755 --- a/testbot/bin/WineSendLog.pl +++ b/testbot/bin/WineSendLog.pl @@ -221,29 +221,30 @@ sub SendLog($) #
Debug("-------------------- Developer email --------------------\n"); + my $Sendmail; if ($Debug) { - open(SENDMAIL, ">>&=", 1); + open($Sendmail, ">>&=", 1); } else { - open (SENDMAIL, "|/usr/sbin/sendmail -oi -t -odq"); + open($Sendmail, "|-", "/usr/sbin/sendmail -oi -t -odq"); } - print SENDMAIL "From: $RobotEMail\n"; - print SENDMAIL "To: $To\n"; + print $Sendmail "From: $RobotEMail\n"; + print $Sendmail "To: $To\n"; my $Subject = "TestBot job " . $Job->Id . " results"; my $Description = $Job->GetDescription(); if ($Description) { $Subject .= ": " . $Description; } - print SENDMAIL "Subject: $Subject\n"; + print $Sendmail "Subject: $Subject\n"; if ($Job->Patch and $Job->Patch->MessageId) { - print SENDMAIL "In-Reply-To: ", $Job->Patch->MessageId, "\n"; - print SENDMAIL "References: ", $Job->Patch->MessageId, "\n"; + print $Sendmail "In-Reply-To: ", $Job->Patch->MessageId, "\n"; + print $Sendmail "References: ", $Job->Patch->MessageId, "\n"; } - print SENDMAIL <<"EOF"; + print $Sendmail <<"EOF"; MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="$PART_BOUNDARY"
@@ -263,8 +264,8 @@ EOF { $TestFailures = ""; } - printf SENDMAIL "%-20s %-9s %s\n", $StepTask->VM->Name, $StepTask->Status, - $TestFailures; + printf $Sendmail "%-20s %-9s %s\n", $StepTask->VM->Name, $StepTask->Status, + $TestFailures; }
# Print the job summary @@ -274,7 +275,7 @@ EOF my $StepTask = $StepsTasks->GetItem($Key); my $TaskDir = $StepTask->GetTaskDir();
- print SENDMAIL "\n=== ", $StepTask->GetTitle(), " ===\n"; + print $Sendmail "\n=== ", $StepTask->GetTitle(), " ===\n";
my $LogFiles = GetLogFileNames($TaskDir); my $LogName = $LogFiles->[0] || "log"; @@ -298,16 +299,16 @@ EOF { if ($PrintedDll ne $CurrentDll) { - print SENDMAIL "\n$CurrentDll:\n"; + print $Sendmail "\n$CurrentDll:\n"; $PrintedDll = $CurrentDll; } if ($Line =~ m/^[^:]+:([^ ]+)(?::[0-9a-f]+)? done (258)/) { - print SENDMAIL "$1: The test timed out\n"; + print $Sendmail "$1: The test timed out\n"; } else { - print SENDMAIL "$Line\n"; + print $Sendmail "$Line\n"; } $PrintedSomething = 1; } @@ -321,12 +322,12 @@ EOF { if ($First) { - print SENDMAIL "\n"; + print $Sendmail "\n"; $First = !1; } $HasLogEntries = 1; $Line =~ s/\s*$//; - print SENDMAIL "$Line\n"; + print $Sendmail "$Line\n"; $PrintedSomething = 1; } close ERRFILE; @@ -336,15 +337,15 @@ EOF { if (! $HasLogEntries) { - print SENDMAIL "Empty test log and no error message\n"; + print $Sendmail "Empty test log and no error message\n"; } elsif ($StepTask->Type eq "build") { - print SENDMAIL "No build failures found\n"; + print $Sendmail "No build failures found\n"; } else { - print SENDMAIL "No test failures found\n"; + print $Sendmail "No test failures found\n"; } } else @@ -360,12 +361,12 @@ EOF { $HasErrEntries = 1; $Line =~ s/\s*$//; - print SENDMAIL "$Line\n"; + print $Sendmail "$Line\n"; } close ERRFILE; if (! $HasErrEntries) { - print SENDMAIL "No test log and no error message"; + print $Sendmail "No test log and no error message"; } else { @@ -380,15 +381,15 @@ EOF my $StepTask = $StepsTasks->GetItem($Key); my $TaskDir = $StepTask->GetTaskDir();
- print SENDMAIL <<"EOF"; + print $Sendmail <<"EOF"; --$PART_BOUNDARY Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit EOF - print SENDMAIL "Content-Disposition: attachment; filename=", - $StepTask->VM->Name, ".log\n\n"; - print SENDMAIL "Not dumping logs in debug mode\n" if ($Debug); + print $Sendmail "Content-Disposition: attachment; filename=", + $StepTask->VM->Name, ".log\n\n"; + print $Sendmail "Not dumping logs in debug mode\n" if ($Debug);
my $LogFiles = GetLogFileNames($TaskDir); my $LogName = $LogFiles->[0] || "log"; @@ -399,7 +400,7 @@ EOF while (defined($Line = <LOGFILE>)) { $Line =~ s/\s*$//; - print SENDMAIL "$Line\n" if (!$Debug); + print $Sendmail "$Line\n" if (!$Debug); $PrintSeparator = 1; } close LOGFILE; @@ -412,18 +413,18 @@ EOF { if ($PrintSeparator) { - print SENDMAIL "\n" if (!$Debug); + print $Sendmail "\n" if (!$Debug); $PrintSeparator = !1; } $Line =~ s/\s*$//; - print SENDMAIL "$Line\n" if (!$Debug); + print $Sendmail "$Line\n" if (!$Debug); } close ERRFILE; } }
- print SENDMAIL "--$PART_BOUNDARY--\n"; - close(SENDMAIL); + print $Sendmail "--$PART_BOUNDARY--\n"; + close($Sendmail);
# This is all for jobs submitted from the website if (!defined $Job->Patch) @@ -506,22 +507,22 @@ EOF { if ($Debug) { - open(SENDMAIL, ">>&=", 1); + open($Sendmail, ">>&=", 1); } else { - open (SENDMAIL, "|/usr/sbin/sendmail -oi -t -odq"); + open($Sendmail, "|-", "/usr/sbin/sendmail -oi -t -odq"); } - print SENDMAIL "From: $RobotEMail\n"; - print SENDMAIL "To: $To\n"; - print SENDMAIL "Cc: $WinePatchCc\n"; - print SENDMAIL "Subject: Re: ", $Job->Patch->Subject, "\n"; + print $Sendmail "From: $RobotEMail\n"; + print $Sendmail "To: $To\n"; + print $Sendmail "Cc: $WinePatchCc\n"; + print $Sendmail "Subject: Re: ", $Job->Patch->Subject, "\n"; if ($Job->Patch->MessageId) { - print SENDMAIL "In-Reply-To: ", $Job->Patch->MessageId, "\n"; - print SENDMAIL "References: ", $Job->Patch->MessageId, "\n"; + print $Sendmail "In-Reply-To: ", $Job->Patch->MessageId, "\n"; + print $Sendmail "References: ", $Job->Patch->MessageId, "\n"; } - print SENDMAIL <<"EOF"; + print $Sendmail <<"EOF";
Hi,
@@ -530,12 +531,12 @@ Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at EOF - print SENDMAIL "$WebSite/JobDetails.pl?Key=", + print $Sendmail "$WebSite/JobDetails.pl?Key=", $Job->GetKey(), "\n\n"; - print SENDMAIL "Your paranoid android.\n\n"; + print $Sendmail "Your paranoid android.\n\n";
- print SENDMAIL $Messages; - close SENDMAIL; + print $Sendmail $Messages; + close($Sendmail); } else {
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/WineSendLog.pl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/testbot/bin/WineSendLog.pl b/testbot/bin/WineSendLog.pl index 9ed83367b..bcd62f351 100755 --- a/testbot/bin/WineSendLog.pl +++ b/testbot/bin/WineSendLog.pl @@ -551,21 +551,21 @@ EOF if (defined $Patch->WebPatchId and -d "$DataDir/webpatches") { my $BaseName = "$DataDir/webpatches/" . $Patch->WebPatchId; - if (open (my $result, ">", "$BaseName.testbot")) + if (open(my $Result, ">", "$BaseName.testbot")) { Debug("\n-------------------- WebPatches report --------------------\n"); # Only take into account new errors to decide whether the job was # successful or not. - DebugTee($result, "Status: ". ($Messages ? "Failed" : "OK") ."\n"); - DebugTee($result, "Job-ID: ". $Job->Id ."\n"); - DebugTee($result, "URL: $WebSite/JobDetails.pl?Key=". $Job->GetKey() ."\n"); + DebugTee($Result, "Status: ". ($Messages ? "Failed" : "OK") ."\n"); + DebugTee($Result, "Job-ID: ". $Job->Id ."\n"); + DebugTee($Result, "URL: $WebSite/JobDetails.pl?Key=". $Job->GetKey() ."\n");
foreach my $Key (@SortedKeys) { my $StepTask = $StepsTasks->GetItem($Key); my $TaskDir = $StepTask->GetTaskDir();
- print $result "\n=== ", $StepTask->GetTitle(), " ===\n"; + print $Result "\n=== ", $StepTask->GetTitle(), " ===\n";
my $LogFiles = GetLogFileNames($TaskDir); my $LogName = $LogFiles->[0] || "log"; @@ -576,7 +576,7 @@ EOF while (defined($Line = <$logfile>)) { $Line =~ s/\s*$//; - print $result "$Line\n"; + print $Result "$Line\n"; $PrintSeparator = 1; } close($logfile); @@ -589,17 +589,17 @@ EOF { if ($PrintSeparator) { - print $result "\n"; + print $Result "\n"; $PrintSeparator = !1; } $Line =~ s/\s*$//; - print $result "$Line\n"; + print $Result "$Line\n"; } close($errfile); } } - print $result "--- END FULL_LOGS ---\n"; - close($result); + print $Result "--- END FULL_LOGS ---\n"; + close($Result); } else {
Also compute the job url once instead of duplicating that code.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/WineSendLog.pl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/testbot/bin/WineSendLog.pl b/testbot/bin/WineSendLog.pl index bcd62f351..cda724d57 100755 --- a/testbot/bin/WineSendLog.pl +++ b/testbot/bin/WineSendLog.pl @@ -216,6 +216,10 @@ sub SendLog($) my $StepsTasks = CreateStepsTasks(undef, $Job); my @SortedKeys = sort @{$StepsTasks->GetKeys()};
+ my $JobURL = ($UseSSL ? "https://" : "http://") . + "$WebHostName/JobDetails.pl?Key=". $Job->GetKey(); + + # # Send a job summary and all the logs as attachments to the developer # @@ -268,6 +272,8 @@ EOF $TestFailures; }
+ print $Sendmail "\nYou can also see the results at:\n$JobURL\n\n"; + # Print the job summary my @FailureKeys; foreach my $Key (@SortedKeys) @@ -501,8 +507,6 @@ EOF
Debug("\n-------------------- Mailing list email --------------------\n");
- my $WebSite = ($UseSSL ? "https://" : "http://") . $WebHostName; - if ($Messages) { if ($Debug) @@ -529,11 +533,13 @@ Hi, While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? -Full results can be found at + +Full results can be found at: +$JobURL + +Your paranoid android. + EOF - print $Sendmail "$WebSite/JobDetails.pl?Key=", - $Job->GetKey(), "\n\n"; - print $Sendmail "Your paranoid android.\n\n";
print $Sendmail $Messages; close($Sendmail); @@ -558,7 +564,7 @@ EOF # successful or not. DebugTee($Result, "Status: ". ($Messages ? "Failed" : "OK") ."\n"); DebugTee($Result, "Job-ID: ". $Job->Id ."\n"); - DebugTee($Result, "URL: $WebSite/JobDetails.pl?Key=". $Job->GetKey() ."\n"); + DebugTee($Result, "URL: $JobURL\n");
foreach my $Key (@SortedKeys) {
Also show the WebPatches result filename.
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/WineSendLog.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/testbot/bin/WineSendLog.pl b/testbot/bin/WineSendLog.pl index cda724d57..9d003915a 100755 --- a/testbot/bin/WineSendLog.pl +++ b/testbot/bin/WineSendLog.pl @@ -557,9 +557,10 @@ EOF if (defined $Patch->WebPatchId and -d "$DataDir/webpatches") { my $BaseName = "$DataDir/webpatches/" . $Patch->WebPatchId; + Debug("\n-------------------- WebPatches report --------------------\n"); + Debug("-- $BaseName.testbot --\n"); if (open(my $Result, ">", "$BaseName.testbot")) { - Debug("\n-------------------- WebPatches report --------------------\n"); # Only take into account new errors to decide whether the job was # successful or not. DebugTee($Result, "Status: ". ($Messages ? "Failed" : "OK") ."\n");
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/WineSendLog.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/testbot/bin/WineSendLog.pl b/testbot/bin/WineSendLog.pl index 9d003915a..51830ad17 100755 --- a/testbot/bin/WineSendLog.pl +++ b/testbot/bin/WineSendLog.pl @@ -388,6 +388,7 @@ EOF my $TaskDir = $StepTask->GetTaskDir();
print $Sendmail <<"EOF"; + --$PART_BOUNDARY Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 @@ -429,7 +430,7 @@ EOF } }
- print $Sendmail "--$PART_BOUNDARY--\n"; + print $Sendmail "\n--$PART_BOUNDARY--\n"; close($Sendmail);
# This is all for jobs submitted from the website