diff options
Diffstat (limited to 'class')
-rw-r--r-- | class/Parser.php | 108 |
1 files changed, 106 insertions, 2 deletions
diff --git a/class/Parser.php b/class/Parser.php index 76e289f..ee052e2 100644 --- a/class/Parser.php +++ b/class/Parser.php @@ -102,7 +102,7 @@ class Parser * * @return integer number of parsed line */ - static private function readOneR(TableUpstream $uptable, $repo) + static private function readOneR(TableUpstream $uptable, Array $repo) { $tot = 0; @@ -145,7 +145,7 @@ class Parser } /** - * Parse the content of a R repository + * Parse the content of all R repository * * @param TableUpstream $uptable the table to write to * @param TableRRepo $rrepo the table to read from @@ -162,5 +162,109 @@ class Parser self::log("Write $tot packages in all channels"); return $tot; } + + /** + * Parse the content of all RPM repository + * + * @param TableRpm $rpmtable the table to write to + * @param TableRpmRepo $rpmrepo the table to store timestamp + * @param hastable $row the repo to read from + * + * @return integer number of parsed line + */ + static public function readOneRpm(TableRpm $rpmtable, TableRpmRepo $rpmrepo, Array $row) + { + $tot = 0; + + self::log("REPOSITORY " . $row['main'] . " " . $row['sub']); + $TimRemote = 0; + $repomd = @simplexml_load_file($row['url'] . "repodata/repomd.xml"); + if ($repomd) { + foreach ($repomd->data as $data) { + if ($data->attributes()=="primary") { + $TimRemote = $data->timestamp; + $UrlRemote = $row['url'] . $data->location->attributes(); + } + } + } + if (!$TimRemote) { + self::log("Can't read $UrlRemote"); + + } else if ($TimRemote > $row['stamp']) { + self::log("Loading $UrlRemote"); + + //$fic=gzopen("primary.xml.gz", "r"); + $fic=gzopen($UrlRemote, "r"); + if ($fic) { + $txt=""; + while ($buf=gzread($fic, 8196)) { + $txt .= $buf; + } + self::log("Read " . strlen($txt) . " bytes"); + gzclose($fic); + + $primary = simplexml_load_string($txt); + self::log("Read " . $primary->attributes() . " packages"); + unset($txt); + + $crit = array( + 'repo_main' => $row['main'], + 'repo_sub' => $row['sub'] + ); + $nb = $rpmtable->delete($crit); + self::log("Delete $nb packages"); + + foreach ($primary->package as $package) { + if ($package->attributes()=='rpm') { + $ver = $package->version->attributes(); + + $input = array( + 'repo_main' => $row['main'], + 'repo_sub' => $row['sub'], + 'name' => $package->name, + 'epoch' => $ver['epoch'], + 'ver' => $ver['ver'], + 'rel' => $ver['rel'], + 'summary' => $package->summary, + 'url' => $package->url + ); + if ($rpmtable->add($input)) { + $tot++; + } + } + } + self::log("Write $tot packages"); + + $rpmrepo->update($row['id'], array('stamp' =>$TimRemote)); + + unset($primary); + } else { + self::log("ERROR : can't read $UrlRemote"); + } + } else { + self::log("no update needed : $TimRemote / " . $row['stamp']); + } + + return $tot; + } + + /** + * Parse the content of all RPM repository + * + * @param TableRpm $rpmtable the table to write to + * @param TableRpmRepo $rpmrepo the table to read from + * @param Array $crit array for repo selection + * + * @return integer number of parsed line + */ + static public function readRpm(TableRpm $rpmtable, TableRpmRepo $rpmrepo, Array $crit) + { + $tot = 0; + + foreach ($rpmrepo->request($crit) as $row) { + $tot += self::ReadOneRpm($rpmtable, $rpmrepo, $row); + } + return $tot; + } } ?>
\ No newline at end of file |