FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
checkTestData.php
1 #!/usr/bin/php
2 <?php
3 /*
4  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
32 $home = getcwd();
33 echo "DB: at the start.... home is:$home\n";
34 $dirs = explode('/',$home);
35 $size = count($dirs);
36 // are we being run by jenkins? if we are not in fossology/tests, cd there
37 if($dirs[$size-1] == 'workspace' )
38 {
39  if(chdir('fossology/src/testing') === FALSE)
40  {
41  echo "FATAL! Cannot cd to fossology/src/testing from" . getcwd() . "\n";
42  exit(1);
43  }
44  $home = getcwd(); // home should now be ...workspace/fossology/src/testing
45 }
46 echo "DB: home is:$home\n";
47 
48 $redHatPath = 'nomos/testdata';
49 $unpackTestFile = '../../ununpack/agent_tests/test-data/testdata4unpack/argmatch.c.gz';
50 $unpackTests = '../../ununpack/agent_tests';
51 $redHatDataFile = 'RedHat.tar.gz';
52 $unpackDataFile = 'unpack-test-data.tar.bz2';
53 $wgetOptions = ' -a wget.log --tries=3 ';
54 $proxy = 'export http_proxy=lart.usa.hp.com:3128;';
55 $Url = 'http://fossology.org/testing/testFiles/';
56 
57 $errors = 0;
58 // check/install RedHat.tar.gz
59 
60 /*
61 if(!file_exists($redHatPath . "/" . $redHatDataFile))
62 {
63  if(chdir($redHatPath) === FALSE)
64  {
65  echo "ERROR! could not cd to $redHatPath, cannot download $redHatDataFile\n";
66  $errors++;
67  }
68  $cmd = $proxy . "wget" . $wgetOptions . $Url . $redHatDataFile;
69  $last = exec($cmd, $wgetOut, $wgetRtn);
70  if($wgetRtn != 0)
71  {
72  echo "ERROR! Download of $Url$redHatDataFile failed\n";
73  echo "Errors were:\n$last\n";print_r($wgetOut) . "\n";
74  $errors++;
75  }
76 }
77 else
78 
79 if(chdir($home) === FALSE)
80 {
81  echo "FATAL! could not cd to $home\n";
82  exit(1);
83 }
84 */
85 
86 // check/install ununpack data
87 echo "downloading unpack data.....\n";
88 if(!file_exists($unpackTestFile))
89 {
90  echo "$unpackTestFile DOES NOT EXIST!, need to download data files...\n";
91  if(chdir($unpackTests) === FALSE)
92  {
93  echo "FATAL! cannot cd to $unpackTests\n";
94  exit(1);
95  }
96  $cmd = $proxy . "wget" . $wgetOptions . $Url . '/' . $unpackDataFile;
97  $unpkLast = exec($cmd, $unpkOut, $unpkRtn);
98  if($unpkRtn != 0)
99  {
100  echo "ERROR! Download of $Url$unpackDataFile failed:$unpkRtn\n";
101  echo "Errors were:\n";print_r($unpkOut) . "\n";
102  $errors++;
103  }
104  // unpack the tar file.
105  $cmd = "tar -xf $unpackDataFile";
106  $tarLast = exec($cmd, $tarOut, $tarRtn);
107  if($tarRtn != 0)
108  {
109  echo "ERROR! un tar of $unpackDataFile failed\n";
110  echo "Errors were:\n$tarLast\n";print_r($tarOut) . "\n";
111  $errors++;
112  }
113 }
114 
115 if($errors)
116 {
117  exit(1);
118 }
119 exit(0);
120 ?>