forked from CovertLab/WholeCell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailSimulationsSummary.pl
executable file
·115 lines (103 loc) · 3.6 KB
/
mailSimulationsSummary.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/perl
#Usage: ./mailSimulationsSummary.pl 259 2011_06_23_01_01_01
#Author: Jonathan Karr, [email protected]
#Affiliation: Covert Lab, Department of Bioengineering, Stanford University
#Last updated: 6/23/2011
use Switch;
use strict;
use Cwd;
use MIME::Lite;
require "/home/projects/WholeCell/simulation/library.pl";
my $simulationIdx = $ARGV[0];
my $simulationDateTime = $ARGV[1];
my %config = getConfiguration();
my $emailAddress = $config{'email'};
my $baseDir = $config{'simulationPath'};
my $outDir = "$baseDir/output/runSimulation";
my $baseURL = 'http://'.$config{'URL'}.'/simulation';
my $webSVNURL = $config{'webSVNURL'};
my @timeStamp = split('_', $simulationDateTime, 6);
chdir($baseDir) or die "$!";
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ("$outDir/$simulationDateTime/conditions.xml");
my $conditions = $doc->getElementsByTagName('conditions', 0)->item(0);
my %metadata = validate_metadata($conditions);
my $firstName = $metadata{'firstName'};
my $lastName = $metadata{'lastName'};
my $email = $metadata{'email'};
my $affiliation = $metadata{'affiliation'};
my $userName = $metadata{'userName'};
my $hostName = $metadata{'hostName'};
my $ipAddress = $metadata{'ipAddress'};
my $revision = $metadata{'revision'};
my $differencesFromRevision = $metadata{'$differencesFromRevision'};
my $conditionsArr = $conditions->getElementsByTagName('condition', 0);
my $conditionsHTML = validate_conditions($conditionsArr);
my $nJobs = count_simulations($conditionsArr);
my $webSVNURLRevision = sprintf($webSVNURL, $revision);
my $errors = '';
unless ((-e "$outDir/$simulationDateTime/summary.html") && (-e "$outDir/$simulationDateTime/population-Growth.pdf")) {
$errors = "Simulation summary not available. See error logs.";
}
my $emailBody = <<HTML;
<html>
<style type="text/css">
body, table {
font-family: Arial;
font-size:10pt;
}
th {
font-weight:bold;
text-align:left;
}
td {
padding-left:10px;
}
</style>
<body>
Simulation set <a href="$baseURL/viewSimulationSet.php?id=$simulationDateTime">#$simulationIdx</a> has finished with $nJobs simulations.<br/>
<br/>
<table cellspacing="0" cellpadding="0">
<tr><th>Researcher</th><td>$firstName $lastName, <a href="mailto:$email">$email</a></td></tr>
<tr><th>Affiliation</th><td>$affiliation</td></tr>
<tr><th>Hostname</th><td>$hostName, $ipAddress</td></tr>
<tr><th>Revision</th><td><a href="$webSVNURLRevision">$revision</a></td></tr>
<tr><th>Differences</th><td style="font-style:italic;">See initial status email</td></tr>
$conditionsHTML
<tr><th>Errors</th><td style="color: red">$errors</td></th>
</table>
</html>
HTML
#mail summary using MIME::LITE
#- http://www.perlfect.com/articles/sendmail.shtml
#- http://www.gettingclever.com/2009/01/sending-mail-with-multiple-attachments.html
my $msg = MIME::Lite->new(
From => 'PBS Daemon <[email protected]>',
To => $emailAddress,
Subject => "Simulation set #$simulationIdx ".
$timeStamp[1].'/'.$timeStamp[2].'/'.$timeStamp[0].' '.
$timeStamp[3].':'.$timeStamp[4].':'.$timeStamp[5].' '.
"finished",
Type => 'multipart/mixed'
);
$msg->attach(
Type => 'text/html',
Data => $emailBody
);
if (-e "$outDir/$simulationDateTime/summary.html") {
$msg->attach(
Type => 'text/html',
Disposition => 'attachment',
Filename => 'summary.html',
Path => "$outDir/$simulationDateTime/summary.html"
);
}
if (-e "$outDir/$simulationDateTime/population-Growth.pdf") {
$msg->attach(
Type => 'application/pdf',
Disposition => 'attachment',
FileName => 'populationSummary.pdf',
Path => "$outDir/$simulationDateTime/population-Growth.pdf"
);
}
$msg->send;