FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
get-fsrc.php
1 #!/usr/bin/php
2 <?php
3 /***********************************************************
4  get-fsrc.php
5  Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  version 2 as published by the Free Software Foundation.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  ***********************************************************/
20 
36 /*
37  * Steps:
38  * 1. establish cvs root in the environment
39  * -> Make sure that set -o noclobber is set in environment.
40  * 2. cd to destination
41  * 3. cvs co
42  * 4. filter for dead packages or packages with no .spec files
43  * - skip processing them, and use a file in the current directory to store them.
44  * 5. make prep for each package.
45  *
46  */
47 
48 // FIXME: $path = '/usr/local/fossology/agents';
49 set_include_path(get_include_path() . PATH_SEPARATOR . $path);
50 
51 require_once("FIXMETOBERELATIVE/pathinclude.php");
52 global $WEBDIR;
53 require_once("$WEBDIR/common/common-cli.php");
54 
55 $usage = "get-fsrc [-h] -s <skip-path> -o <output-path>\n";
56 
57 /*
58  *
59  <<< USAGE
60 
61 Where:
62 -h standard help, usage message.
63 
64 -o output-path path where sources will be checked out, the packages will
65  be checked out into a directory call devel.
66 -s skip-path path were list of dead packages and other skipped packages
67  will be stored.
68  Note is it ALWAYS a good idea to run this script using screen and to
69  capture stdout and stderr into a log file.
70 
71 USAGE;
72 */
73 
74 $options = getopt("ho:s:");
75 //print_r($options);
76 if (empty($options))
77  {
78  echo $usage;
79  exit(1);
80  }
81 if (array_key_exists("h",$options))
82  {
83  echo $usage;
84  exit(0);
85  }
86 if (array_key_exists("o",$options))
87  {
88  $fedora = $options['o'];
89  if (empty($fedora))
90  {
91  echo $usage;
92  exit(1);
93  }
94  }
95  if (array_key_exists("s",$options))
96  {
97  $spath = $options['s'];
98  if (empty($spath))
99  {
100  $spath = '/tmp/skipped.fedora9.pkgs';
101  print "NOTE: setting the path for skipped file to /tmp/skipped.fedora9.pkgs\n";
102  }
103  else
104  {
105  // defect here, should check to see if there is a trailing /....
106  $spath .= '/skipped.fedora9.pkgs';
107  }
108  }
109 
110 
111 chdir($fedora) or die("Can't chdir to $fedora, $php_errormsg\n");
112 
113 $date=`date`;
114 echo "Starting at: $date\n";
115 
116 // checkout and filter
117 $checked_out = cvs_co($fedora);
118 if(!empty($checked_out))
119 {
120  print($checked_out);
121 }
122 // need to check for trailing / and then do the right thing....add
123 // later
124 $devel = "$fedora" . '/devel';
125 chdir($devel) or die("Can't chdir to $fedora, $php_errormsg\n");
126 
127 $list = array();
128 
129 $last = exec('ls', $list, $rtn);
130 if ($rtn != 0)
131 {
132  print "Error, cannot get list of packages with ls\n";
133  exit(1);
134 }
135 
136 // Filter and make
137 foreach($list as $pkg){
138  // wrinkle.... common package does not have a devel, need to special
139  // case it.
140  rtrim($pkg);
141  //cli_PrintDebugMessage("\$pkg is:$pkg");
142  $dir = `pwd`;
143  print "Now at:$dir";
144  if(!(chdir("$pkg"))){
145  echo "ERROR: Can't chdir to $pkg, skipping: $php_errormsg\n";
146  continue;
147  }
148  $plist=`ls`;
149 
150  if (preg_match('/dead.package/', $plist)){
151  echo "$pkg is a dead.package, skipping\n";
152  $saved = save_skipped($spath, "$pkg is a dead package\n");
153  if(!empty($saved))
154  {
155  print "Warning! ";
156  print($saved);
157  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
158  continue;
159  }
160  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
161  }
162  elseif (!(preg_match('/.spec/', $plist)))
163  {
164  echo "$pkg has no spec file, skipping\n";
165  $saved = save_skipped($spath, "$pkg has no spec file\n");
166  if(!empty($saved))
167  {
168  print "Warning! ";
169  print($saved);
170  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
171  continue;
172  }
173  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
174  }
175  else{
176  $dir = `pwd`;
177  $date = `date`;
178  print "Now at:$dir";
179  print "on $date";
180  echo "Making $pkg\n";
181  $mpcmd = "alias rm='rm -f'; make prep > make-prep.out 2>&1";
182  $last = exec("$mpcmd", $mpout, $rtn);
183  if($rtn != 0) {
184  print "ERROR: make prep for $pkg did not exit zero: return was: $rtn\n\n";
185  $saved = save_skipped($spath, "$pkg failed make prep, return code was: $rtn\n");
186  if(!empty($saved))
187  {
188  print "Warning! ";
189  print($saved);
190  }
191  }
192  // put the removeal of the make.out here....as else clause...
193  chdir('..') or die("Can't chdir to .., $php_errormsg\n");
194  }
195  // look for and remove the compressed file... look at older scripts.
196  echo "-----\n\n";
197 }
198 
199 $date=`date`;
200 print "Ending at: $date";
201 
212 function cvs_co($fedora){
213 
214  // make sure cvs root is set
215  $cmd = 'export CVSROOT=:pserver:anonymous@cvs.fedoraproject.org:/cvs/pkgs; '
216  . 'cvs co -r HEAD devel';
217 
218  chdir($fedora) or die("Can't chdir to $fedora, $php_errormsg\n");
219  $last = exec("$cmd", $cvs_co_out, $retval);
220  if ($retval != 0){
221  return("ERROR: cvs co did not return zero status: $retval\n");
222  }
223  return NULL;
224 }
225 
226 function save_skipped ($path, $message)
227 {
228  global $WEBDIR;
229  require_once("$WEBDIR/common/common-cli.php");
230  // save the message containing the package name that failed in a file at $path
231 
232  $logged = cli_logger($path, $message);
233  if(!empty($logged))
234  {
235  return($logged);
236  }
237  return(NULL);
238 }
239 
240 
241 ?>
if(!$Test &&$OptionQ) if($stdin_flag) if($Verbose) else
Definition: cp2foss.php:551
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:44
cli_logger($handle, $message, $mode='a')
Write/append a message to the log handle passed in.
Definition: common-cli.php:74