FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
clean-tars.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 
30 $usage = <<< USAGE
31 clean-tars.php [-h] -i <input-path>
32 
33 Clean cruft out of fedora packages. The following is cleaned:
34 make.out - the make prep output
35 .cvsignore - cvs file
36 compressed archives - all .tgz, .gz, bzip2, bz2, zip files
37 
38 Dead packages and packages with no .spec file are skipped.
39 
40 Where:
41 -h standard help, usage message.
42 -i input-path path where sources/packages will be cleaned
43 
44 USAGE;
45 
46 $options = getopt("hi:");
47 //print_r($options);
48 if (empty($options))
49 {
50  echo $usage;
51  exit(1);
52 }
53 if (array_key_exists("h",$options))
54 {
55  echo $usage;
56  exit(0);
57 }
58 if (array_key_exists("i",$options))
59 {
60  $in_path = $options['i'];
61  if (empty($in_path))
62  {
63  echo $usage;
64  exit(1);
65  }
66 }
67 
68 chdir($in_path) or die("Can't chdir to $in_path: $php_errormsg\n");
69 
70 $toss = exec('ls', $list, $rtn);
71 if($rtn != 0){
72  echo "ERROR, ls of $in_path did not return zero: $rtn\n";
73  exit(1);
74 }
75 
76 $date=`date`;
77 echo "Starting at: $date";
78 $whereami = `pwd`;
79 
80 foreach($list as $pkg)
81 {
82  echo "Package is:$pkg\n";
83  if(!(chdir($pkg))){
84  print "ERROR: Can't chdir to $pkg, skipping: $php_errormsg\n";
85  continue;
86  }
87  $plist = array();
88  $toss = exec('ls -a', $plist, $rtn);
89  if($rtn != 0)
90  {
91  echo "ERROR, ls of $pkg did not return zero: $rtn\n";
92  exit(1);
93  }
94  /*
95  * Dam, folks sure do make this part tricky.... need to have very
96  * robust patterns.
97  *
98  * Remove compressed archives, .cvsignore and make.out
99  * skip dead packages and packages with no .spec.
100  */
101 
102  foreach($plist as $file)
103  {
104  $match = array();
105  if (preg_match('/dead\.package/i', $file))
106  {
107  print "$pkg is a dead.package, skipping\n";
108  continue;
109  }
110  $alist = `ls`;
111  if (!(preg_match('/.*\.spec/i', $alist)))
112  {
113  echo "$pkg has no spec file, skipping\n";
114  continue;
115  }
116 
117  // the pattern for gz files is meant to match tgz and gz
118  if(preg_match('/.*?gz$/i', $file, $match))
119  {
120  echo "Executing set -o noclobber; rm -rf $match[0]\n";
121  $toss = system("set -o noclobber; rm -rf $match[0]", $rtn);
122  if($rtn != 0){
123  echo "ERROR, remove of {$match[0]} did not return zero: $rtn\n";
124  }
125  }
126  if(preg_match('/.*?bz2$/i', $file, $match))
127  {
128  echo "Executing set -o noclobber; rm -rf $match[0]\n";
129  $toss = system("set -o noclobber; rm -rf $match[0]", $rtn);
130  if($rtn != 0)
131  {
132  echo "ERROR, remove of {$match[0]} did not return zero: $rtn\n";
133  }
134  }
135  if(preg_match('/.*?Bzip2$/i', $file, $match))
136  {
137  echo "Executing set -o noclobber; rm -rf $match[0]\n";
138  $toss = system("set -o noclobber; rm -rf $match[0]", $rtn);
139  if($rtn != 0){
140  echo "ERROR, remove of {$match[0]} did not return zero: $rtn\n";
141  }
142  }
143  if(preg_match('/.*?zip$/i', $file, $match))
144  {
145  echo "Executing set -o noclobber; rm -rf $match[0]\n";
146  $toss = system("set -o noclobber; rm -rf $match[0]", $rtn);
147  if($rtn != 0){
148  echo "ERROR, remove of {$match[0]} did not return zero: $rtn\n";
149  }
150  }
151  if(preg_match('/\.cvsignore$/i', $file, $match))
152  {
153  echo "Executing set -o noclobber; rm -rf $match[0]\n";
154  $toss = system("set -o noclobber; rm -rf $match[0]", $rtn);
155  if($rtn != 0){
156  echo "ERROR, remove of {$match[0]} did not return zero: $rtn\n";
157  }
158  }
159  if(preg_match('/make\.out$/i', $file, $match))
160  {
161  echo "Executing set -o noclobber; rm -rf $match[0]\n";
162  $toss = system("set -o noclobber; rm -rf $match[0]", $rtn);
163  if($rtn != 0){
164  echo "ERROR, remove of {$match[0]} did not return zero: $rtn\n";
165  }
166  }
167  } // foreach($plist...
168  chdir('..') or die("Can't chdir to ..: $php_errormsg\n");
169 } // foreach($list as ...
170 
171 $date=`date`;
172 print "Ending at: $date";
173 
174 ?>
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:44
FUNCTION void usage(char *name)
Definition: usage.c:30