From 8b50ace3024268b3067c0bf43bbd68f824b90d81 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 1 Nov 2010 11:02:02 +0100 Subject: use Parser::readPear() - end of work for refresh --- class/Parser.php | 203 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) (limited to 'class/Parser.php') diff --git a/class/Parser.php b/class/Parser.php index 3113718..ef4a751 100644 --- a/class/Parser.php +++ b/class/Parser.php @@ -363,5 +363,208 @@ class Parser } return $nb; } + + /** + * Parse the content of all PEAR repository + * + * @param TableUpstream $uptable the table to write to + * @param string $channelname the channel name + * @param string $channelurl the channel URL + * + * @return integer number of parsed line + */ + static public function readOnePear(TableUpstream $uptable, $channelname, $channelurl) + { + $channel = @simplexml_load_file("http://$channelurl/channel.xml"); + if (!$channel) { + self::log("can't read PEAR site (channel of $channelname)"); + return 0; + } + + $rest = $channel->servers->primary->rest->baseurl[0]; + self::log("PEAR reading channel=$channelname, baseurl = $rest"); + + $categories = @simplexml_load_file($rest."c/categories.xml"); + if (!$categories) { + self::log("can't read PEAR site (categories)"); + return 0; + } + + $crit = array('type'=>'pear', 'channel'=>$channelname); + $nb = $uptable->delete($crit); + self::log("Delete $nb packages"); + + $nb=0; + if (!isset($categories->c[0])) { + self::log("Reading ALL"); // ezc only + $pitxt = @file_get_contents($rest."p/packages.xml"); + if (!$pitxt) { + self::log("can't read PEAR site (".$rest."p/packagesinfo.xml)"); + return 0; + } + $allpi = @simplexml_load_string($pitxt); + foreach ($allpi->p as $name) { + $pitxt = @file_get_contents( + $rest."r/".strtolower($name)."/allreleases.xml" + ); + if (!$pitxt) { + self::log( + "can't read PEAR site (".$rest."r/". + strtolower($name)."/allreleases.xml" + ); + continue; + } + $pi = @simplexml_load_string($pitxt); + + $rpmname1="php-".$channelname."-". + str_replace("_", "-", $name); + $rpmname2="php-".$channelname."-".$name; + + $uptable->record( + "pear", + $channelname, + $rpmname1, + (string)$pi->r[0]->v, + false, + (string)$pi->r[0]->s + ); + $uptable->record( + "pear", + $channelname, + $rpmname2, + (string)$pi->r[0]->v, + false, + (string)$pi->r[0]->s + ); + foreach ($pi->r as $rev) { + if ($rev->s=='stable') { + $uptable->record( + "pear", + $channelname, + $rpmname1, + (string)$rev->v, + true + ); + $uptable->record( + "pear", + $channelname, + $rpmname2, + (string)$rev->v, + true + ); + break; + } + } + $nb++; + } + + } else { + foreach ($categories->c as $cat) { + self::log("Reading $cat"); + + $pitxt = @file_get_contents( + $rest."c/".urlencode($cat)."/packagesinfo.xml" + ); + if (!$pitxt) { + self::log( + "can't read PEAR site (".$rest."c/". + urlencode($cat)."/packagesinfo.xml)" + ); + continue; + } + $pitxt = "/U", + "", + str_replace("\r\n", "\n", substr($pitxt, 2)) + ); + + $pi = @simplexml_load_string($pitxt); + if (!$pi) { + self::log("can't read response ($cat)"); + continue; + } + foreach ($pi->pi as $ps) { + if (isset($ps->p->n) && isset($ps->a->r)) { + $name=(string)$ps->p->n; + + if ($channelname=='phing' && $name=='phing') { + $rpmname1="php-pear-phing"; + } else if ($channelname=='phpunit' + && $name=='PHPUnit' + ) { + $rpmname1="php-pear-PHPUnit"; + } else { + $rpmname1="php-".$channelname."-". + str_replace("_", "-", $name); + } + $rpmname2="php-".$channelname."-".$name; + + $uptable->record( + "pear", + $channelname, + $rpmname1, + (string)$ps->a->r[0]->v, + false, + (string)$ps->a->r[0]->s + ); + $uptable->record( + "pear", + $channelname, + $rpmname2, + (string)$ps->a->r[0]->v, + false, + (string)$ps->a->r[0]->s + ); + foreach ($ps->a->r as $rev) { + if ($rev->s=='stable') { + $uptable->record( + "pear", + $channelname, + $rpmname1, + (string)$rev->v, + true + ); + $uptable->record( + "pear", + $channelname, + $rpmname2, + (string)$rev->v, + true + ); + break; + } + } + $nb++; + } + } + } + } + self::log("read $nb packages in $channelname"); + return $nb; + + } + /** + * Parse the content of all PEAR repository + * + * @param TableUpstream $uptable the table to write to + * @param TablePearRepo $pear the table to read from + * + * @return integer number of parsed line + */ + static public function readPear(TableUpstream $uptable, TablePearRepo $pear) + { + $tot = 0; + + self::log("PEAR reading channels"); + + $channels = $pear->getAllRepo(true); + foreach ($channels as $channelname => $channelurl) { + $tot += self::readOnePear($uptable, $channelname, $channelurl); + } + + self::log("Write $tot packages in all channels"); + return $tot; + } + } ?> \ No newline at end of file -- cgit