-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessResults.php
executable file
·156 lines (123 loc) · 4.65 KB
/
ProcessResults.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
include 'TestReportSheet.php';
//$opener=$_REQUEST['handle'];
$length = $_REQUEST['length'];
$path = $_REQUEST['path'];
$mpdURL = $_REQUEST['mpdURL'];
// To get initial list of folders inside temp.
if (is_dir($path)) {
$foldernames = scandir($path, 0);
$i=0;
$folders=array();
foreach ($foldernames as $result) {
if ($result === '.' or $result === '..') continue;
if (is_dir($path . '/' . $result)) {
$folders[$i]=$result;
$i=$i+1;
}
}
} else {
echo "No such directory";
}
// To get the new list of folders which includes newly created results folder.
$j=0;
while($j<=$i)
{
if (is_dir($path))
{
$foldernamesNew = scandir($path, 0);
//$k=0;
$foldersNew=array();
foreach ($foldernamesNew as $result) {
if ($result === '.' or $result === '..') continue;
if (is_dir($path . '/' . $result)) {
$foldersNew[$j]=$result;
//$k=$k+1;
$j=$j+2;//To end the while loop in the next check.+1 not enough.
}
}
}
}
$Newfolder=$foldersNew[0];
$newPath='TestResults';
$FoldName='References';
for($n=1;$n<=$length;$n++)
{
if(!is_dir($newPath.'/'.$FoldName.$n))
{
$FoldName=$FoldName.$n;
break;
}
}
echo $FoldName;
// Check progress.xml to find if Conformance Test is completed, then move the results to TestResults folder.
while(1)
{
if(file_exists($path.'/'.$Newfolder.'/progress.xml')){
//$feed = file_get_contents($path.'/'.$Newfolder.'/progress.xml');
$filesize = filesize($path.'/'.$Newfolder.'/progress.xml');
//if($filesize != 0)
//if(file_exists($path.'/'.$Newfolder.'/progress.xml'))
// {
$xml=simplexml_load_file($path.'/'.$Newfolder.'/progress.xml');
if($xml->completed=="true")
{
//Write all errors to a spreadsheet before moving to new location.
create_initial_spreadsheet();
$error_counter=0;
string_operations($path.'/'.$Newfolder, $mpdURL);
rename($path.'/'.$Newfolder, $newPath.'/'.$FoldName );
chmod($newPath.'/'.$FoldName, 0777);
break;
}
//}
}
sleep(3);
}
// Following is to remove temp/id-random-number folder name in myphp-error.log file
if ( file_exists( $newPath.'/'.$FoldName.'/myphp-error.log' ) )
{
$fileContents=file_get_contents($newPath.'/'.$FoldName.'/myphp-error.log');
$fileContents=str_replace('temp\/'.$Newfolder, "TestResults/".$FoldName, $fileContents);
file_put_contents($newPath.'/'.$FoldName.'/myphp-error.log', $fileContents);
// Remove date-time info
$fileContents1=file_get_contents($newPath.'/'.$FoldName.'/myphp-error.log');
while(strpos($fileContents1, '] ')!== FALSE){
$startPos= strpos($fileContents1, '[');
$endPos= strpos($fileContents1, '] ');
$fileContents1= substr_replace($fileContents1, '', $startPos , $endPos-$startPos+2);
}
file_put_contents($newPath.'/'.$FoldName.'/myphp-error.log', $fileContents1);
}
$contents = file_get_contents($newPath.'/'.$FoldName.'/mpdreport.txt');
$pattern = '/Total time: (\d+) seconds/i';
$replacement = 'Total time: x seconds';
$contents = preg_replace($pattern, $replacement, $contents);
file_put_contents($newPath.'/'.$FoldName.'/mpdreport.txt', $contents);
unlink($newPath.'/'.$FoldName.'/progress.xml');
unlink($newPath.'/'.$FoldName.'/ValidateMP4.exe');
// Following is to remove temp/id-random-number folder name in respective files
replaceFolderName("stdout.txt",$newPath,$FoldName,$Newfolder);
replaceFolderName("config_file.txt",$newPath,$FoldName,$Newfolder);
replaceFolderName("command.txt",$newPath,$FoldName,$Newfolder);
// Compare and get the differences.
if (is_dir($newPath.'/'.'References'.'/'.$FoldName))
{
$oldfile=$newPath.'/'.'References'.'/'.$FoldName;
$newfile=$newPath.'/'.$FoldName;
$command = 'diff'.' '.'-r '.$oldfile.' '.$newfile.' '.'>'.$newPath.'/'.$FoldName.'_diff.txt';
//echo $command;
$output=array();$status=0;
exec($command,$output,$status);
}
function replaceFolderName($fileName,$newPath,$FoldName,$Newfolder)
{
if ( file_exists( $newPath.'/'.$FoldName.'/'.$fileName) )
{
$fileContents=file_get_contents($newPath.'/'.$FoldName.'/'.$fileName);
$fileContents=str_replace('temp/'.$Newfolder, $FoldName, $fileContents);
file_put_contents($newPath.'/'.$FoldName.'/'.$fileName, $fileContents);
}
}
//echo "<p>pasted</p>";
?>