svn: /phpdoc/doc-base/trunk/scripts/ fetch-chms.php

From: Date: Tue, 24 May 2011 09:04:59 +0000
Subject: svn: /phpdoc/doc-base/trunk/scripts/ fetch-chms.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-8172@lists.php.net to get a copy of this message
bjori Tue, 24 May 2011 09:04:59 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=311380 Log: Script to fetch the chm files from oti1 and publish them on rsync Changed paths: A phpdoc/doc-base/trunk/scripts/fetch-chms.php Added: phpdoc/doc-base/trunk/scripts/fetch-chms.php =================================================================== --- phpdoc/doc-base/trunk/scripts/fetch-chms.php (rev 0) +++ phpdoc/doc-base/trunk/scripts/fetch-chms.php 2011-05-24 09:04:59 UTC (rev 311380) @@ -0,0 +1,118 @@ +<?php +define("DEBUG", 0); +$BUILDDIR = "http://oti1.php.net"; +$TMPDIR = sys_get_temp_dir(); +$CHMDIR = "/local/mirrors/phpweb/distributions/manual"; + +$chminfo = "$BUILDDIR/LatestCHMBuilds.txt"; +fetch($chminfo, tempnam(sys_get_temp_dir(), "chm")); + +$chms = file($chminfo, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); +if (!$chms) { + err("No chm info\n"); + return 1; +} + +foreach($chms as $line) { + list($filename, $hash, $date) = explode("\t", $line); + $tmpfilename = "$TMPDIR/$filename.new"; + $realfilename = "$CHMDIR/$filename"; + debug("\n\nWorking on $filename ($tmpfilename => $realfilename)\n"); + + $dlsize = fetch("$BUILDDIR/$filename", $tmpfilename); + if (!$dlsize) { + $err = error_get_last(); + err($err["message"], $filename); + continue; + } + debug("Fetched $dlsize"); + + $realhash = md5_file($tmpfilename); + if ($realhash != $hash) { + err("\nMD5 Failed for $filename ($realhash != $hash)\n"); + continue; + } + debug("\nMD5 OK"); + + debug("Renaming $tmpfilename to $realfilename"); + rename($tmpfilename, $realfilename); + debug("All done with $filename"); +} + +$errors = err(); +if ($errors) { + mail("phpdoc@lists.php.net", "Errors copying CHM files", var_export($errors), "From: phpdoc@lists.php.net\r\n", "-fnoreply@php.net"); + return 2; +} + + +function err($error = null) { + static $errors = array(); + if ($error) { + $errors[] = $error; + } + return $errors; +} +function debug($msg) { + if (DEBUG) { + echo $msg, "\n"; + } +} +function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) { + static $filesize = null; + + switch($notification_code) { + case STREAM_NOTIFY_RESOLVE: + case STREAM_NOTIFY_AUTH_REQUIRED: + case STREAM_NOTIFY_COMPLETED: + case STREAM_NOTIFY_FAILURE: + case STREAM_NOTIFY_AUTH_RESULT: + /* Ignore */ + break; + + case STREAM_NOTIFY_REDIRECTED: + debug("Being redirected to: ". $message); + break; + + case STREAM_NOTIFY_CONNECT: + debug("Connected..."); + break; + + case STREAM_NOTIFY_FILE_SIZE_IS: + $filesize = $bytes_max; + debug("Filesize: ". $filesize); + break; + + case STREAM_NOTIFY_MIME_TYPE_IS: + debug("Mime-type: ". $message); + break; + + case STREAM_NOTIFY_PROGRESS: + if ($bytes_transferred > 0) { + if (DEBUG) { + if (!isset($filesize)) { + printf("\rUnknown filesize.. %2d kb done..", $bytes_transferred/1024); + } else { + $length = (int)(($bytes_transferred/$filesize)*100); + printf("\r[%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024); + } + } + } + break; + } +} + +function fetch($filename, $outputname) { + debug("Fetching $filename"); + $ctx = stream_context_create(null, array("notification" => "stream_notification_callback")); + + $fp = fopen($filename, "r", false, $ctx); + if (!is_resource($fp)) { + err("Fetch failed"); + return 0; + } + return file_put_contents($outputname, $fp); +} + + +

« previous php.doc.cvs (#8172) next »