diff options
author | Remi Collet <fedora@famillecollet.com> | 2010-11-01 10:25:14 +0100 |
---|---|---|
committer | Remi Collet <fedora@famillecollet.com> | 2010-11-01 10:25:14 +0100 |
commit | da00c9df1bf03fe3989c9cc34f0007f285a1ad5e (patch) | |
tree | e850f00ef07ae5fff9f078e3f481d664669192d4 | |
parent | 93c01077b80cc8d6044d1ec82e981c9f2b26f362 (diff) |
use Parser::readRpm()
-rw-r--r-- | class/Parser.php | 108 | ||||
-rw-r--r-- | refresh.php | 77 |
2 files changed, 107 insertions, 78 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 diff --git a/refresh.php b/refresh.php index aa4d486..9603c78 100644 --- a/refresh.php +++ b/refresh.php @@ -70,83 +70,8 @@ try { } else { $crit = array('active' => 1); } - $rpmrepo = new TableRpmRepo($db); - $rpmtable = new TableRpm($db); - - foreach ($rpmrepo->request($crit) as $row) { - echo date("r : ") . "REPOSITORY " . $row['main'] . " " . - $row['sub'] . "\n"; - $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) { - echo date("r : ") . "Can't read $UrlRemote\n"; - - } else if ($TimRemote > $row['stamp']) { - echo date("r : ") . "Loading $UrlRemote\n"; - - //$fic=gzopen("primary.xml.gz", "r"); - $fic=gzopen($UrlRemote, "r"); - if ($fic) { - $txt=""; - while ($buf=gzread($fic, 8196)) { - $txt .= $buf; - } - echo date("r : ") . "Read " . strlen($txt) . " bytes\n"; - gzclose($fic); - - $primary = simplexml_load_string($txt); - echo date("r : ") . "Read " . $primary->attributes() . - " packages\n"; - unset($txt); - - $crit = array( - 'repo_main' => $row['main'], - 'repo_sub' => $row['sub'] - ); - $nb = $rpmtable->delete($crit); - echo date("r : ") . "Delete $nb packages\n"; - - $tot=0; - 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++; - } - } - } - echo date("r : ") . "Write $tot packages\n"; - - $rpmrepo->update($row['id'], array('stamp' =>$TimRemote)); - unset($primary); - } else { - echo date("r : ") . "ERROR : can't read $UrlRemote\n"; - } - } else { - echo date("r : ") . "no update needed : $TimRemote / " . - $row['stamp'] . "\n"; - } - } + Parser::readRpm(new TableRpm($db), new TableRpmRepo($db), $crit); } // If ask // ------------------------------------------------------------------- |