[Collab-qa-commits] r684 - in wnpp: . popcon
sping-guest at alioth.debian.org
sping-guest at alioth.debian.org
Thu Jan 31 00:10:45 UTC 2008
Author: sping-guest
Date: 2008-01-31 00:10:44 +0000 (Thu, 31 Jan 2008)
New Revision: 684
Modified:
wnpp/cron_sync_popcon.php5
wnpp/popcon/
Log:
Now also using binary-package popcon data
Modified: wnpp/cron_sync_popcon.php5
===================================================================
--- wnpp/cron_sync_popcon.php5 2008-01-30 09:05:33 UTC (rev 683)
+++ wnpp/cron_sync_popcon.php5 2008-01-31 00:10:44 UTC (rev 684)
@@ -27,110 +27,120 @@
$LAST_RUN_FILENAME = "__last_sync_popcon_run";
$MINIMUM_RUN_GAP = 60 * 60 * 12; // 12 hours
-$ENABLE_GAP_CHECK = TRUE;
+$ENABLE_GAP_CHECK = FALSE;
$KEEP_FILES = 4;
-
-
-
-$POPCON_URL = "http://popcon.debian.org/source/by_inst.gz";
$POPCON_DIR = "popcon";
-$POPCON_LOCAL = "${POPCON_DIR}/pkg_by_inst_" . date("Ymd_His"). ".gz";
-open_page();
+function cleanup() {
+ global $link;
-if (!check_run_allowed()) {
- close_page();
- exit(0);
-}
+ // Disconnect
+ echo "LOCAL DISCONNECT\n";
+ mysql_close($link);
-// Download
-echo "REMOTE READ\n";
-$online_file = @file_get_contents($POPCON_URL);
-if (empty($online_file)) {
- echo " ERROR\n";
close_page();
- exit(0);
}
-echo " SUCCESS\n";
-// Ensure directory presence
- at mkdir($POPCON_DIR, 0750);
-// Remove old files
-$old_files = glob("${POPCON_DIR}/pkg_by_inst_????????_??????.gz");
-$count_old_files = count($old_files);
-$rem_files = max(0, $count_old_files - $KEEP_FILES);
-if ($rem_files > 0) {
- echo "LOCAL DELETE\n";
- for ($i = 1; $i <= $rem_files; $i++) {
- $file_to_delete = $old_files[$i];
- echo " [$i/$rem_files] $file_to_delete\n";
- unlink($file_to_delete);
+function process($remote_url, $local_file_prefix) {
+ global $POPCON_DIR;
+ global $POPCON_TABLE;
+ global $KEEP_FILES;
+
+ $local_filename = "${POPCON_DIR}/${local_file_prefix}_" . date("Ymd_His"). ".gz";
+
+
+ // Download
+ echo "REMOTE READ\n";
+ $online_file = @file_get_contents($remote_url);
+ if (empty($online_file)) {
+ echo " ERROR\n";
+ cleanup();
+ exit(0);
}
-}
+ echo " SUCCESS\n";
-// Write to file
-echo "LOCAL WRITE\n";
-$FILE = @fopen($POPCON_LOCAL, "w");
-if ($FILE) {
- $written_bytes = @fwrite($FILE, $online_file);
- @fclose($FILE);
- echo " SUCCESS\n";
-} else {
- echo " ERROR\n";
+ // Remove old files
+ $old_files = glob("${POPCON_DIR}/${local_file_prefix}_????????_??????.gz");
+ $count_old_files = count($old_files);
+ $rem_files = max(0, $count_old_files - $KEEP_FILES);
+ if ($rem_files > 0) {
+ echo "LOCAL DELETE\n";
+ for ($i = 1; $i <= $rem_files; $i++) {
+ $file_to_delete = $old_files[$i];
+ echo " [$i/$rem_files] $file_to_delete\n";
+ unlink($file_to_delete);
+ }
+ }
+
+ // Write to file
+ echo "LOCAL WRITE\n";
+ $FILE = @fopen($local_filename, "w");
+ if ($FILE) {
+ $written_bytes = @fwrite($FILE, $online_file);
+ @fclose($FILE);
+ echo " SUCCESS\n";
+ } else {
+ echo " ERROR\n";
+ }
+
+ // Reading local file
+ echo "LOCAL READ\n";
+ $GZ_FILE = gzopen($local_filename, "rb");
+ $matches = array();
+ if ($GZ_FILE) {
+ for (;;) {
+ $line = gzgets($GZ_FILE);
+ if (!$line) {
+ if (!gzeof($GZ_FILE)) {
+ echo " ERROR\n";
+ }
+ break;
+ }
+
+ if (!preg_match('/^\\d+\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)[^\r\n]*[\r\n]+$/', $line, $matches)) {
+ continue;
+ }
+
+ $package = mysql_real_escape_string($matches[1]);
+ $inst = mysql_real_escape_string($matches[2]);
+ $vote = mysql_real_escape_string($matches[3]);
+ $old = mysql_real_escape_string($matches[4]);
+ $recent = mysql_real_escape_string($matches[5]);
+ $nofiles = mysql_real_escape_string($matches[6]);
+
+// echo " [$package][$inst][$vote][$old][$recent][$nofiles]\n";
+ $query = "INSERT INTO $POPCON_TABLE (package,inst,vote,old,recent,nofiles) VALUES "
+ . "('$package',$inst,$vote,$old,$recent,$nofiles) ON DUPLICATE KEY UPDATE "
+ . "inst=$inst,vote=$vote,old=$old,recent=$recent,nofiles=$nofiles";
+ $result = mysql_query($query);
+ }
+ gzclose($GZ_FILE);
+ }
}
-function cleanup() {
- global $link;
- // Disconnect
- echo "LOCAL DISCONNECT\n";
- mysql_close($link);
+open_page();
+if (!check_run_allowed()) {
close_page();
+ exit(0);
}
+// Ensure directory presence
+ at mkdir($POPCON_DIR, 0750);
+
// Connect to database
echo "LOCAL CONNECT\n";
$link = mysql_connect($SERVER, $USERNAME, $PASSWORD);
mysql_select_db($DATABASE);
-// Reading local file
-echo "LOCAL READ\n";
-$GZ_FILE = gzopen($POPCON_LOCAL, "rb");
-$matches = array();
-if ($GZ_FILE) {
- for (;;) {
- $line = gzgets($GZ_FILE);
- if (!$line) {
- if (!gzeof($GZ_FILE)) {
- echo " ERROR\n";
- }
- break;
- }
+process('http://popcon.debian.org/source/by_inst.gz', 'source_by_inst_');
+process('http://popcon.debian.org/by_inst.gz', 'binary_by_inst_');
- if (!preg_match("/^\\d+\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+[\r\n]+$/", $line, $matches)) {
- continue;
- }
- $package = mysql_real_escape_string($matches[1]);
- $inst = mysql_real_escape_string($matches[2]);
- $vote = mysql_real_escape_string($matches[3]);
- $old = mysql_real_escape_string($matches[4]);
- $recent = mysql_real_escape_string($matches[5]);
- $nofiles = mysql_real_escape_string($matches[6]);
-
- echo " [$package][$inst][$vote][$old][$recent][$nofiles]\n";
- $query = "INSERT INTO $POPCON_TABLE (package,inst,vote,old,recent,nofiles) VALUES "
- . "('$package',$inst,$vote,$old,$recent,$nofiles) ON DUPLICATE KEY UPDATE "
- . "inst=$inst,vote=$vote,old=$old,recent=$recent,nofiles=$nofiles";
- $result = mysql_query($query);
- }
- gzclose($GZ_FILE);
-}
-
cleanup();
?>
Property changes on: wnpp/popcon
___________________________________________________________________
Name: svn:ignore
+ binary_by_inst_*.gz
source_by_inst_*.gz
More information about the Collab-qa-commits
mailing list