FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
FreshmeatRdfs.php
1 <?php
2 
3 
4 /***********************************************************
5  Copyright (C) 2008 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 
32 {
33  public $error_code = NULL;
34  public $error_out = array();
35  public $uncompresser = 'bunzip2';
36  public $uncompressed_file = NULL;
37  private $project_info = array ();
38 
39  public function Uncompress($file)
40  {
41  /* should also check for existence? */
42  /* what about a try catch? */
43 
44  if (!(empty ($file)))
45  {
46  $toss = exec("$this->uncompresser $file 2>&1", $output, $rtn);
47  }
48  if ($rtn != 0)
49  {
50  echo "DBG: UNCOMP-> uncompressor returned:$rtn\n";
51  $this->error_code = $rtn;
52  $this->error_out = $output[0];
53  return (FALSE);
54  }
55  /* if there is no .bz2 on the end nothing gets chopped... */
56  $this->uncompressed_file = rtrim($file, '.bz2');
57  return (TRUE);
58  }
59 
81  public function FindInProjInfo($name, $search_space)
82  {
83  $found = NULL;
84  $match = NULL;
85  if (empty ($name))
86  {
87  return (NULL);
88  }
89  if (empty ($search_space))
90  {
91  return (NULL);
92  }
93  $pkey = array_keys($search_space);
94  //print "DB: FMRDFS: pkey is:\n";
95  //var_dump($pkey);
96  //$this->write2file($pkey);
97  if(empty($pkey))
98  {
99  print "DB: FIPI: Pkey is empty!\n";
100  return(NULL);
101  }
102  else
103  {
104  $found = array_search($name, $pkey);
105  if (!is_null($found))
106  {
107  //print "DB FIPI: setting match\n";
108  $match = $search_space[$pkey[$found]];
109  }
110  return ($match);
111  }
112  }
113 
134  public function XtractProjInfo($rdf_file)
135  {
136  /*
137  * be nice to check if it's compressed and if so, uncompress it,
138  * later
139  *
140  * NOTE: this routine will return a VERY large array of data.
141  * See the data structure below for the data collected.
142  */
143 
144  /*
145  * Data Structure:
146  *
147  * Key Value (s)
148  * --- --------
149  * project_name <zero or more urls to archives>,
150  * <short-description>, version
151  *
152  */
153  if (!(file_exists("$rdf_file")))
154  {
155  return;
156  }
157  $meatdoc = simplexml_load_file("$rdf_file");
158  foreach ($meatdoc->project as $project)
159  {
160  $this->project_info["$project->projectname_short"]
161  = array (
162  "$project->url_tgz",
163  "$project->url_bz2",
164  "$project->url_zip",
165  "$project->desc_short"
166  );
167  foreach ($project->latest_release as $verdata)
168  {
169  array_push(& $this->project_info["$project->projectname_short"],
170  $verdata->latest_release_version
171  );
172  }
173  }
174  ksort($this->project_info);
175  return ($this->project_info);
176  }
177 
178  function write2file($array_var)
179  {
180  $name = 'pkeys' . getmypid();
181  $FD = fopen($name, 'w') or die ("can't open $name, $php_errormsg\n");
182  foreach($array_var as $key=>$value)
183  {
184  fwrite($FD, "$value \n");
185  }
186  }
187 }
188 ?>
XtractProjInfo($rdf_file)
FindInProjInfo($name, $search_space)