cvs: pearweb /cron make-packages.php
| From: | Thomas V.V.Cox | Date: | Sun, 08 Jul 2001 17:00:35 +0000 |
| Subject: | cvs: pearweb /cron make-packages.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-240@lists.php.net to get a copy of this message | ||
cox Sun Jul 8 13:00:35 2001 EDT
Modified files:
/pearweb/cron make-packages.php
Log:
added error checks, fix some queries and code clean-up
Index: pearweb/cron/make-packages.php diff -u pearweb/cron/make-packages.php:1.2 pearweb/cron/make-packages.php:1.3 --- pearweb/cron/make-packages.php:1.2 Sun Jul 8 06:19:34 2001 +++ pearweb/cron/make-packages.php Sun Jul 8 13:00:32 2001 @@ -1,4 +1,4 @@ -#!/usr/local/bin/php -Cq +#!/usr/bin/php -Cq <?php // -*- C++ -*- /* vim: set expandtab tabstop=4 shiftwidth=4; */ // +---------------------------------------------------------------------+ @@ -47,127 +47,158 @@ */ $PEAR_Dir = "/var/cvs/pear"; -$db = DB::Connect("mysql://pear:pear@localhost/pear"); +/** +* DSN for pear packages database +*/ +$dsn = "pgsql://pear:pear@localhost/pear"; + + +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_error'); + +if (DB::isError($db = DB::connect($dsn))) { + die ("Couldn't open database -> $dsn\n"); +} +if (!is_dir($TgzDir) || !is_writeable($TgzDir)) { + die ("Couldn't use $TgzDir as target packages dir"); +} -$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; +if (!($dir = opendir($PEAR_Dir))) { + die ("Couldn't open Pear Dir: $PEAR_Dir"); +} + +$xml = "< ?xml version=\"1.0\" encoding=\"ISO-8859-1\" ? >\n"; $xml .= "<Packages>\n"; -if ($dir = @opendir($PEAR_Dir)) { - while(($file = readdir($dir)) ) { - if (! strstr($file,".") && ! strstr($file,"CVS") ) - { - echo $file."\n"; - chdir ($PEAR_Dir."/".$file); - if (file_exists("package.xml")) { - - $packager =& new PEAR_Packager(); - - if (PEAR::isError($packager->Package())) { - $packager->log(0,"Reading of package.xml failed!"); - } else { - $packager->log(0,"package.xml read succesfully"); - } - - $xml .= " - <Package> - <Name>".$packager->pkginfo["Package,Name"]."</Name> - <Summary>".$packager->pkginfo["Package,Summary"]."</Summary> - <Release> - <Version>".$packager->pkginfo["Release,Version"]."</Version> - <Date>".$packager->pkginfo["Release,Date"]."</Date> - <Notes>".$packager->pkginfo["Release,Notes"]."</Notes> - </Release> - </Package>\n"; - - /** - * Look if there is already an entry for the author - */ - $sth = $db->query("SELECT handle FROM users WHERE handle = lcase('".$packager->pkginfo['Maintainer,Initials']."')"); - - if ($sth->numRows() == 0) { - - $query = sprintf("INSERT INTO users (handle,name,email,created,createdby) VALUES ('%s','%s','%s','%s','%s')", - strtolower($packager->pkginfo['Maintainer,Initials']), - $packager->pkginfo['Maintainer,Name'], - $packager->pkginfo['Maintainer,EMail'], - date("Y-m-d H:i:s"), - "mj" - ); - - $sth = $db->query($query); - } - - /** - * Store information for new packages - */ - $sth = $db->query("SELECT name FROM packages WHERE name = '".$packager->pkginfo['Package,Name']."'"); - - if ($sth->numRows() == 0) { - - $query = sprintf("INSERT INTO packages (name,summary) VALUES ('%s','%s')", - $packager->pkginfo['Package,Name'], - $packager->pkginfo['Package,Summary'] - ); - - $sth = $db->query($query); - - $query = sprintf("INSERT INTO maintains (handle,package) VALUES ('%s','%s')", - strtolower($packager->pkginfo['Maintainer,Initials']), - $packager->pkginfo['Package,Name'] - ); - - $sth = $db->query($query); - } - - /** - * Store information about the current release - */ - $sth = $db->query("SELECT package FROM releases WHERE package = '".$packager->pkginfo['Package,Name']."' AND - version = '".$packager->pkginfo['Release,Version']."'"); - - if ($sth->numRows() == 0) { - - $query = sprintf("INSERT INTO releases (package,version,releasedate,releasenotes) VALUES ('%s','%s','%s','%s')", - $packager->pkginfo['Package,Name'], - $packager->pkginfo['Release,Version'], - $packager->pkginfo['Release,Date'], - $packager->pkginfo['Release,Notes'] - ); - - $sth = $db->query($query); - } - - - /** - * Copy the tgz file to the new destination - */ - copy($PEAR_Dir."/".$file."/".$packager->pkgver.".tgz",$TgzDir."/".$packager->pkgver.".tgz"); - - /** - * Remove the unused file - */ - unlink($PEAR_Dir."/".$file."/".$packager->pkgver.".tgz"); - } +while ($file = readdir($dir)) { + if (!strstr($file, '.') && !strstr($file, 'CVS') ) + { + chdir ($PEAR_Dir."/".$file); + if (!file_exists("package.xml")) { + continue; + } - chdir (".."); + /** + * Build the package release + */ + $packager =& new PEAR_Packager(); + $packager->debug = 0; + if (PEAR::isError($packager->Package())) { + echo "Reading of {$PEAR_Dir}/package.xml failed!\n"; + chdir ('..'); + continue; + } + $xml .= + "<Package>\n". + " <Name>".$packager->pkginfo['Package,Name']."</Name>\n". + " <Summary>".$packager->pkginfo['Package,Summary']."</Summary>\n". + " <Release>\n". + " <Version>".$packager->pkginfo['Release,Version']."</Version>\n". + " <Date>".$packager->pkginfo['Release,Date']."</Date>\n". + " <Notes>".$packager->pkginfo['Release,Notes']."</Notes>\n". + " </Release>\n". + "</Package>\n"; + + /** + * Look if there is already an entry for the author + */ + $sth = $db->query("SELECT handle + FROM users + WHERE handle = lcase('".$packager->pkginfo['Maintainer,Initials']."')"); + + if (!DB::isError($sth) && ($sth->numRows() == 0)) { + + $query = sprintf("INSERT INTO users + (handle,name,email,created,createdby) + VALUES ('%s','%s','%s','%s','%s')", + strtolower($packager->pkginfo['Maintainer,Initials']), + $packager->pkginfo['Maintainer,Name'], + $packager->pkginfo['Maintainer,EMail'], + date('Y-m-d H:i:s'), + 'mj' //who should be createby? + ); + + $db->query($query); + } + + /** + * Store information for new packages + */ + $sth = $db->query("SELECT name + FROM packages + WHERE name = '".$packager->pkginfo['Package,Name']."'"); + + if (!DB::isError($sth) && ($sth->numRows() == 0)) { + + $query = sprintf("INSERT INTO packages + (name,summary) + VALUES ('%s','%s')", + $packager->pkginfo['Package,Name'], + $packager->pkginfo['Package,Summary'] + ); + + $db->query($query); + + $query = sprintf("INSERT INTO maintains + (handle,package) + VALUES ('%s','%s')", + strtolower($packager->pkginfo['Maintainer,Initials']), + $packager->pkginfo['Package,Name'] + ); + + $db->query($query); } - } - closedir($dir); - $xml .= "</Packages>\n"; - $fxml = fopen($TgzDir."/Packages.xml","w"); - fwrite($fxml,"$xml\n"); - fclose($fxml); + /** + * Store information about the current release + */ + $sth = $db->query("SELECT package + FROM releases + WHERE package = '".$packager->pkginfo['Package,Name']."' + AND version = '".$packager->pkginfo['Release,Version']."'" + ); + + if (!DB::isError($sth) && ($sth->numRows() == 0)) { + + $query = sprintf("INSERT INTO releases + (package,version,releasedate,releasenotes,doneby) + VALUES ('%s','%s','%s','%s','%s')", + $packager->pkginfo['Package,Name'], + $packager->pkginfo['Release,Version'], + $packager->pkginfo['Release,Date'], + $packager->pkginfo['Release,Notes'], + 'mj' //who should be doneby? + ); - if (function_exists("gzopen")) - { - $fxml = gzopen($TgzDir."/Packages.xml.gz","wb"); - gzwrite($fxml,"$xml\n"); - gzclose($fxml); + $db->query($query); + } + + /** + * Move the tgz file to the new destination + */ + rename($PEAR_Dir.'/'.$file.'/'.$packager->pkgver.'.tgz', + $TgzDir.'/'.$packager->pkgver.'.tgz'); + + chdir ('..'); } +} +closedir($dir); + +$xml .= "</Packages>\n"; +$fxml = fopen($TgzDir.'/Packages.xml', 'w'); +fwrite($fxml, $xml); +fclose($fxml); +if (function_exists('gzopen')) { + $fxml = gzopen($TgzDir.'/Packages.xml.gz', 'wb'); + gzwrite($fxml, $xml); + gzclose($fxml); +} + +function &pear_error($obj) { + echo $obj->getMessage() . "\n" . $obj->getDebugInfo(). "\n"; + return null; } ?>
Index: pearweb/cron/make-packages.php diff -u pearweb/cron/make-packages.php:1.2 pearweb/cron/make-packages.php:1.3 --- pearweb/cron/make-packages.php:1.2 Sun Jul 8 06:19:34 2001 +++ pearweb/cron/make-packages.php Sun Jul 8 13:00:32 2001 @@ -1,4 +1,4 @@ -#!/usr/local/bin/php -Cq +#!/usr/bin/php -Cq <?php // -*- C++ -*- /* vim: set expandtab tabstop=4 shiftwidth=4; */ // +---------------------------------------------------------------------+ @@ -47,127 +47,158 @@ */ $PEAR_Dir = "/var/cvs/pear"; -$db = DB::Connect("mysql://pear:pear@localhost/pear"); +/** +* DSN for pear packages database +*/ +$dsn = "pgsql://pear:pear@localhost/pear"; + + +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_error'); + +if (DB::isError($db = DB::connect($dsn))) { + die ("Couldn't open database -> $dsn\n"); +} +if (!is_dir($TgzDir) || !is_writeable($TgzDir)) { + die ("Couldn't use $TgzDir as target packages dir"); +} -$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; +if (!($dir = opendir($PEAR_Dir))) { + die ("Couldn't open Pear Dir: $PEAR_Dir"); +} + +$xml = "< ?xml version=\"1.0\" encoding=\"ISO-8859-1\" ? >\n"; $xml .= "<Packages>\n"; -if ($dir = @opendir($PEAR_Dir)) { - while(($file = readdir($dir)) ) { - if (! strstr($file,".") && ! strstr($file,"CVS") ) - { - echo $file."\n"; - chdir ($PEAR_Dir."/".$file); - if (file_exists("package.xml")) { - - $packager =& new PEAR_Packager(); - - if (PEAR::isError($packager->Package())) { - $packager->log(0,"Reading of package.xml failed!"); - } else { - $packager->log(0,"package.xml read succesfully"); - } - - $xml .= " - <Package> - <Name>".$packager->pkginfo["Package,Name"]."</Name> - <Summary>".$packager->pkginfo["Package,Summary"]."</Summary> - <Release> - <Version>".$packager->pkginfo["Release,Version"]."</Version> - <Date>".$packager->pkginfo["Release,Date"]."</Date> - <Notes>".$packager->pkginfo["Release,Notes"]."</Notes> - </Release> - </Package>\n"; - - /** - * Look if there is already an entry for the author - */ - $sth = $db->query("SELECT handle FROM users WHERE handle = lcase('".$packager->pkginfo['Maintainer,Initials']."')"); - - if ($sth->numRows() == 0) { - - $query = sprintf("INSERT INTO users (handle,name,email,created,createdby) VALUES ('%s','%s','%s','%s','%s')", - strtolower($packager->pkginfo['Maintainer,Initials']), - $packager->pkginfo['Maintainer,Name'], - $packager->pkginfo['Maintainer,EMail'], - date("Y-m-d H:i:s"), - "mj" - ); - - $sth = $db->query($query); - } - - /** - * Store information for new packages - */ - $sth = $db->query("SELECT name FROM packages WHERE name = '".$packager->pkginfo['Package,Name']."'"); - - if ($sth->numRows() == 0) { - - $query = sprintf("INSERT INTO packages (name,summary) VALUES ('%s','%s')", - $packager->pkginfo['Package,Name'], - $packager->pkginfo['Package,Summary'] - ); - - $sth = $db->query($query); - - $query = sprintf("INSERT INTO maintains (handle,package) VALUES ('%s','%s')", - strtolower($packager->pkginfo['Maintainer,Initials']), - $packager->pkginfo['Package,Name'] - ); - - $sth = $db->query($query); - } - - /** - * Store information about the current release - */ - $sth = $db->query("SELECT package FROM releases WHERE package = '".$packager->pkginfo['Package,Name']."' AND - version = '".$packager->pkginfo['Release,Version']."'"); - - if ($sth->numRows() == 0) { - - $query = sprintf("INSERT INTO releases (package,version,releasedate,releasenotes) VALUES ('%s','%s','%s','%s')", - $packager->pkginfo['Package,Name'], - $packager->pkginfo['Release,Version'], - $packager->pkginfo['Release,Date'], - $packager->pkginfo['Release,Notes'] - ); - - $sth = $db->query($query); - } - - - /** - * Copy the tgz file to the new destination - */ - copy($PEAR_Dir."/".$file."/".$packager->pkgver.".tgz",$TgzDir."/".$packager->pkgver.".tgz"); - - /** - * Remove the unused file - */ - unlink($PEAR_Dir."/".$file."/".$packager->pkgver.".tgz"); - } +while ($file = readdir($dir)) { + if (!strstr($file, '.') && !strstr($file, 'CVS') ) + { + chdir ($PEAR_Dir."/".$file); + if (!file_exists("package.xml")) { + continue; + } - chdir (".."); + /** + * Build the package release + */ + $packager =& new PEAR_Packager(); + $packager->debug = 0; + if (PEAR::isError($packager->Package())) { + echo "Reading of {$PEAR_Dir}/package.xml failed!\n"; + chdir ('..'); + continue; + } + $xml .= + "<Package>\n". + " <Name>".$packager->pkginfo['Package,Name']."</Name>\n". + " <Summary>".$packager->pkginfo['Package,Summary']."</Summary>\n". + " <Release>\n". + " <Version>".$packager->pkginfo['Release,Version']."</Version>\n". + " <Date>".$packager->pkginfo['Release,Date']."</Date>\n". + " <Notes>".$packager->pkginfo['Release,Notes']."</Notes>\n". + " </Release>\n". + "</Package>\n"; + + /** + * Look if there is already an entry for the author + */ + $sth = $db->query("SELECT handle + FROM users + WHERE handle = lcase('".$packager->pkginfo['Maintainer,Initials']."')"); + + if (!DB::isError($sth) && ($sth->numRows() == 0)) { + + $query = sprintf("INSERT INTO users + (handle,name,email,created,createdby) + VALUES ('%s','%s','%s','%s','%s')", + strtolower($packager->pkginfo['Maintainer,Initials']), + $packager->pkginfo['Maintainer,Name'], + $packager->pkginfo['Maintainer,EMail'], + date('Y-m-d H:i:s'), + 'mj' //who should be createby? + ); + + $db->query($query); + } + + /** + * Store information for new packages + */ + $sth = $db->query("SELECT name + FROM packages + WHERE name = '".$packager->pkginfo['Package,Name']."'"); + + if (!DB::isError($sth) && ($sth->numRows() == 0)) { + + $query = sprintf("INSERT INTO packages + (name,summary) + VALUES ('%s','%s')", + $packager->pkginfo['Package,Name'], + $packager->pkginfo['Package,Summary'] + ); + + $db->query($query); + + $query = sprintf("INSERT INTO maintains + (handle,package) + VALUES ('%s','%s')", + strtolower($packager->pkginfo['Maintainer,Initials']), + $packager->pkginfo['Package,Name'] + ); + + $db->query($query); } - } - closedir($dir); - $xml .= "</Packages>\n"; - $fxml = fopen($TgzDir."/Packages.xml","w"); - fwrite($fxml,"$xml\n"); - fclose($fxml); + /** + * Store information about the current release + */ + $sth = $db->query("SELECT package + FROM releases + WHERE package = '".$packager->pkginfo['Package,Name']."' + AND version = '".$packager->pkginfo['Release,Version']."'" + ); + + if (!DB::isError($sth) && ($sth->numRows() == 0)) { + + $query = sprintf("INSERT INTO releases + (package,version,releasedate,releasenotes,doneby) + VALUES ('%s','%s','%s','%s','%s')", + $packager->pkginfo['Package,Name'], + $packager->pkginfo['Release,Version'], + $packager->pkginfo['Release,Date'], + $packager->pkginfo['Release,Notes'], + 'mj' //who should be doneby? + ); - if (function_exists("gzopen")) - { - $fxml = gzopen($TgzDir."/Packages.xml.gz","wb"); - gzwrite($fxml,"$xml\n"); - gzclose($fxml); + $db->query($query); + } + + /** + * Move the tgz file to the new destination + */ + rename($PEAR_Dir.'/'.$file.'/'.$packager->pkgver.'.tgz', + $TgzDir.'/'.$packager->pkgver.'.tgz'); + + chdir ('..'); } +} +closedir($dir); + +$xml .= "</Packages>\n"; +$fxml = fopen($TgzDir.'/Packages.xml', 'w'); +fwrite($fxml, $xml); +fclose($fxml); +if (function_exists('gzopen')) { + $fxml = gzopen($TgzDir.'/Packages.xml.gz', 'wb'); + gzwrite($fxml, $xml); + gzclose($fxml); +} + +function &pear_error($obj) { + echo $obj->getMessage() . "\n" . $obj->getDebugInfo(). "\n"; + return null; } ?>