FOSSology  4.4.0
Open Source License Compliance by Open Source Software
FreshmeatRdfs.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
19 {
20  public $error_code = NULL;
21  public $error_out = array();
22  public $uncompresser = 'bunzip2';
23  public $uncompressed_file = NULL;
24  private $project_info = array ();
25 
26  public function Uncompress($file)
27  {
28  /* should also check for existence? */
29  /* what about a try catch? */
30 
31  if (!(empty ($file)))
32  {
33  $toss = exec("$this->uncompresser $file 2>&1", $output, $rtn);
34  }
35  if ($rtn != 0)
36  {
37  echo "DBG: UNCOMP-> uncompressor returned:$rtn\n";
38  $this->error_code = $rtn;
39  $this->error_out = $output[0];
40  return (FALSE);
41  }
42  /* if there is no .bz2 on the end nothing gets chopped... */
43  $this->uncompressed_file = rtrim($file, '.bz2');
44  return (TRUE);
45  }
46 
68  public function FindInProjInfo($name, $search_space)
69  {
70  $found = NULL;
71  $match = NULL;
72  if (empty ($name))
73  {
74  return (NULL);
75  }
76  if (empty ($search_space))
77  {
78  return (NULL);
79  }
80  $pkey = array_keys($search_space);
81  //print "DB: FMRDFS: pkey is:\n";
82  //var_dump($pkey);
83  //$this->write2file($pkey);
84  if(empty($pkey))
85  {
86  print "DB: FIPI: Pkey is empty!\n";
87  return(NULL);
88  }
89  else
90  {
91  $found = array_search($name, $pkey);
92  if (!is_null($found))
93  {
94  //print "DB FIPI: setting match\n";
95  $match = $search_space[$pkey[$found]];
96  }
97  return ($match);
98  }
99  }
100 
121  public function XtractProjInfo($rdf_file)
122  {
123  /*
124  * be nice to check if it's compressed and if so, uncompress it,
125  * later
126  *
127  * NOTE: this routine will return a VERY large array of data.
128  * See the data structure below for the data collected.
129  */
130 
131  /*
132  * Data Structure:
133  *
134  * Key Value (s)
135  * --- --------
136  * project_name <zero or more urls to archives>,
137  * <short-description>, version
138  *
139  */
140  if (!(file_exists("$rdf_file")))
141  {
142  return;
143  }
144  $meatdoc = simplexml_load_file("$rdf_file");
145  foreach ($meatdoc->project as $project)
146  {
147  $this->project_info["$project->projectname_short"]
148  = array (
149  "$project->url_tgz",
150  "$project->url_bz2",
151  "$project->url_zip",
152  "$project->desc_short"
153  );
154  foreach ($project->latest_release as $verdata)
155  {
156  $this->project_info["$project->projectname_short"][] = $verdata->latest_release_version;
157  }
158  }
159  ksort($this->project_info);
160  return ($this->project_info);
161  }
162 
163  function write2file($array_var)
164  {
165  $name = 'pkeys' . getmypid();
166  $FD = fopen($name, 'w') or die ("can't open $name, $php_errormsg\n");
167  foreach($array_var as $key=>$value)
168  {
169  fwrite($FD, "$value \n");
170  }
171  }
172 }
FindInProjInfo($name, $search_space)
XtractProjInfo($rdf_file)