cvs: pear /PEAR_Size package.xml /PEAR_Size/Size Size.php Size_Factory.php Size_Output_csv.php Size_Output_html.php Size_Output_text.php
/PEAR_Size/docs script-usage.txt /PEAR_Size/scripts pearsize.php

From: Date: Sat, 29 Mar 2008 01:03:59 +0000
Subject: cvs: pear /PEAR_Size package.xml /PEAR_Size/Size Size.php Size_Factory.php Size_Output_csv.php Size_Output_html.php Size_Output_text.php
/PEAR_Size/docs script-usage.txt /PEAR_Size/scripts pearsize.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-51731@lists.php.net to get a copy of this message
kguest Sat Mar 29 01:03:59 2008 UTC Added files: /pear/PEAR_Size/Size Size_Output_csv.php Modified files: /pear/PEAR_Size package.xml /pear/PEAR_Size/Size Size.php Size_Factory.php Size_Output_html.php Size_Output_text.php /pear/PEAR_Size/docs script-usage.txt /pear/PEAR_Size/scripts pearsize.php Log: required changes for having a CSV output

http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/package.xml?r1=1.2&r2=1.3&diff_format=u Index: pear/PEAR_Size/package.xml diff -u pear/PEAR_Size/package.xml:1.2 pear/PEAR_Size/package.xml:1.3 --- pear/PEAR_Size/package.xml:1.2 Tue Mar 18 23:50:53 2008 +++ pear/PEAR_Size/package.xml Sat Mar 29 01:03:58 2008 @@ -40,6 +40,7 @@ </dir> <file baseinstalldir="/" name="Size/Size.php" role="php" install-as="PEAR/Size.php"/> <file baseinstalldir="/" name="Size/Size_Factory.php" role="php" install-as="PEAR/Size/Factory.php"/> + <file baseinstalldir="/" name="Size/Size_Output_csv.php" role="php" install-as="PEAR/Size/Output_csv.php"/> <file baseinstalldir="/" name="Size/Size_Output_text.php" role="php" install-as="PEAR/Size/Output_text.php"/> <file baseinstalldir="/" name="Size/Size_Output_html.php" role="php" install-as="PEAR/Size/Output_html.php"/> <file name="TODO" role="doc" /> http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/Size/Size.php?r1=1.8&r2=1.9&diff_format=u Index: pear/PEAR_Size/Size/Size.php diff -u pear/PEAR_Size/Size/Size.php:1.8 pear/PEAR_Size/Size/Size.php:1.9 --- pear/PEAR_Size/Size/Size.php:1.8 Thu Mar 27 22:42:40 2008 +++ pear/PEAR_Size/Size/Size.php Sat Mar 29 01:03:59 2008 @@ -8,7 +8,7 @@ * @package PEAR_Size * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size.php,v 1.8 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size.php,v 1.9 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ @@ -256,23 +256,6 @@ return ($a_total < $b_total ? -1 : 1); } - /** - * Return either given value, or it in readable form depending on criteria. - * - * @param integer $value value - * @param boolean $readable human readable form? - * @param boolean $round round to values of 1000 rather than 1024? - * - * @return string - */ - private function _readableLine($value, $readable, $round) - { - if ($readable) { - return $this->_sizeReadable($value, null, $round); - } else { - return (string) $value; - } - } /** * Analyse packages associated with specified channel @@ -332,46 +315,6 @@ } /** - * Display report of packages in a channel - * - * @param array $stats array of statistics - * @param mixed $details additional details - * - * @return void - */ - private function _channelReport($stats, $details) - { - $table = $this->_driver->table(); - $content_added = false; - foreach ($stats as $statistic) { - $content = array(); - $content[] = $statistic['package']; - $content[] = $this->_readableLine($statistic['total'], - $this->_readable, - $this->_round); - if ($this->_verbose) { - $line = ''; - foreach ($details as $detail) { - $line .= "$detail: "; - $line .= $this->_readableLine($statistic['sizes'][$detail], - $this->_readable, - $this->_round); - $line .= "; "; - } - $line = substr($line, 0, strlen($line) - 2); - $content[] = "($line)"; - } - if ($content !== array() ) { - $table->addRow($content); - $content_added = true; - } - } - if ($content_added) { - echo $table->getTable(); - } - } - - /** * class constructor * * @return void @@ -589,6 +532,10 @@ case 'c': $this->setChannel(trim($param)); break; + case 'C': + case 'csv': + $this->setOutputDriver('csv'); + break; case 'type': case 't': $this->setTypes($param); @@ -678,40 +625,14 @@ */ public function generateReport() { - if ($this->_verbose) { - $this->_driver->cols = 3; - } else { - $this->_driver->cols = 2; - } - $indices = substr($this->search_roles, 1, strlen($this->search_roles) - 2); - $details = explode("|", $indices); - - $msg = "Total: "; - $msg .= $this->_readableLine($this->_grand_total, - $this->_readable, - $this->_round); - $this->_driver->display($msg); - - foreach ($this->_channel_stats as $channel_name=>$ca) { - list($stats, $channel_total) = $ca; - $this->_driver->display(""); - $this->_driver->display("$channel_name:"); - $this->_driver->display(str_pad('', strlen($channel_name) + 1, "=")); - $msg = "Total: "; - if ($this->_readable) { - $msg .= $this->_sizeReadable($channel_total, null, $this->_round); - } else { - $msg .= $channel_total; - } - $this->_driver->display($msg); - - if ($this->_sort_size) { - usort($stats, array("PEAR_Size","_sortBySize")); - } - if (!$this->_summarise) { - $this->_channelReport($stats, $details); - } - } + $display_params = array("verbose" => $this->_verbose, + "readable" => $this->_readable, + "round" => $this->_round); + + $this->_driver->generateReport($this->_channel_stats, + $this->search_roles, + $this->_grand_total, + $display_params); } } ?> http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/Size/Size_Factory.php?r1=1.8&r2=1.9&diff_format=u Index: pear/PEAR_Size/Size/Size_Factory.php diff -u pear/PEAR_Size/Size/Size_Factory.php:1.8 pear/PEAR_Size/Size/Size_Factory.php:1.9 --- pear/PEAR_Size/Size/Size_Factory.php:1.8 Thu Mar 27 22:42:40 2008 +++ pear/PEAR_Size/Size/Size_Factory.php Sat Mar 29 01:03:59 2008 @@ -9,7 +9,7 @@ * @package PEAR_Size * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Factory.php,v 1.8 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Factory.php,v 1.9 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ @@ -21,7 +21,7 @@ * @author Ken Guest <ken@linux.ie> * @copyright 2008 Ken Guest * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Factory.php,v 1.8 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Factory.php,v 1.9 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ interface PEAR_SIZE_Factory @@ -43,19 +43,136 @@ * @author Ken Guest <ken@linux.ie> * @copyright 2008 Ken Guest * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Factory.php,v 1.8 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Factory.php,v 1.9 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ -interface PEAR_Size_Output_Driver +class PEAR_Size_Output_Driver { /** + * Return either given value, or it in readable form depending on criteria. + * + * @param integer $value value + * @param boolean $readable human readable form? + * @param boolean $round round to values of 1000 rather than 1024? + * + * @return string + */ + private function _readableLine($value, $readable, $round) + { + if ($readable) { + return $this->_sizeReadable($value, null, $round); + } else { + return (string) $value; + } + } + + /** * display given text. * * @param string $text text to be displayed * * @return void */ - public function display($text); + public function display($text) + { + echo $text, "\n"; + } + + /** + * generate the report + * + * @param array $channel_stats contains statistics for each channel + * @param array $search_roles roles searched for + * @param array $grand_total entire total of disk space consumed by channel + * @param array $display_params parameters relevant to display of report. + * + * @return void + */ + public function generateReport($channel_stats, + $search_roles, + $grand_total, + $display_params) + { + + $indices = substr($this->search_roles, 1, strlen($this->search_roles) - 2); + $details = explode("|", $indices); + + $this->_verbose = $display_params["verbose"]; + $this->_readable = $display_params["readable"]; + $this->_round = $display_params["round"]; + + //$stats, $details + $indices = substr($search_roles, 1, strlen($search_roles) - 2); + $details = explode("|", $indices); + + $msg = "Total: "; + $msg .= $this->_readableLine($grand_total, + $this->_readable, + $this->_round); + $this->display($msg); + + foreach ($channel_stats as $channel_name=>$ca) { + list($stats, $channel_total) = $ca; + $this->display(""); + $this->display("$channel_name:"); + $this->display(str_pad('', strlen($channel_name) + 1, "=")); + $msg = "Total: "; + if ($this->_readable) { + $msg .= $this->_sizeReadable($channel_total, null, $this->_round); + } else { + $msg .= $channel_total; + } + $this->display($msg); + + if ($this->_sort_size) { + usort($stats, array("PEAR_Size","_sortBySize")); + } + if (!$this->_summarise) { + $this->_channelReport($stats, $details); + } + } + } + + /** + * Display report of packages in a channel + * + * @param array $stats array of statistics + * @param mixed $details additional details + * + * @return void + */ + private function _channelReport($stats, $details) + { + $table = $this->table(); + $content_added = false; + foreach ($stats as $statistic) { + $content = array(); + $content[] = $statistic['package']; + $content[] = $this->_readableLine($statistic['total'], + $this->_readable, + $this->_round); + if ($this->_verbose) { + $line = ''; + foreach ($details as $detail) { + $line .= "$detail: "; + $line .= $this->_readableLine($statistic['sizes'][$detail], + $this->_readable, + $this->_round); + $line .= "; "; + } + $line = substr($line, 0, strlen($line) - 2); + $content[] = "($line)"; + } + if ($content !== array() ) { + $table->addRow($content); + $content_added = true; + } + } + if ($content_added) { + echo $table->getTable(); + } + } + } /** @@ -67,7 +184,7 @@ * @author Ken Guest <ken@linux.ie> * @copyright 2008 Ken Guest * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Factory.php,v 1.8 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Factory.php,v 1.9 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ class PEAR_SIZE_OutputFactory implements PEAR_SIZE_Factory http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/Size/Size_Output_html.php?r1=1.6&r2=1.7&diff_format=u Index: pear/PEAR_Size/Size/Size_Output_html.php diff -u pear/PEAR_Size/Size/Size_Output_html.php:1.6 pear/PEAR_Size/Size/Size_Output_html.php:1.7 --- pear/PEAR_Size/Size/Size_Output_html.php:1.6 Thu Mar 27 22:42:40 2008 +++ pear/PEAR_Size/Size/Size_Output_html.php Sat Mar 29 01:03:59 2008 @@ -9,7 +9,7 @@ * @author Ken Guest <ken@linux.ie> * @copyright 2008 Ken Guest * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Output_html.php,v 1.6 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Output_html.php,v 1.7 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ require_once "HTML/Table.php"; @@ -21,7 +21,7 @@ * @uses HTML_Table * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Output_html.php,v 1.6 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Output_html.php,v 1.7 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ class PEAR_Size_HTML_Table extends HTML_Table @@ -48,10 +48,10 @@ * @uses PEAR_Size_Output_Driver * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Output_html.php,v 1.6 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Output_html.php,v 1.7 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ -class PEAR_Size_Output_Html implements PEAR_Size_Output_Driver +class PEAR_Size_Output_Html extends PEAR_Size_Output_Driver { /** * display given text. http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/Size/Size_Output_text.php?r1=1.5&r2=1.6&diff_format=u Index: pear/PEAR_Size/Size/Size_Output_text.php diff -u pear/PEAR_Size/Size/Size_Output_text.php:1.5 pear/PEAR_Size/Size/Size_Output_text.php:1.6 --- pear/PEAR_Size/Size/Size_Output_text.php:1.5 Thu Mar 27 22:42:40 2008 +++ pear/PEAR_Size/Size/Size_Output_text.php Sat Mar 29 01:03:59 2008 @@ -8,7 +8,7 @@ * @package PEAR_Size * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Output_text.php,v 1.5 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Output_text.php,v 1.6 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ require_once "Console/Table.php"; @@ -17,13 +17,13 @@ * * @category PEAR * @package PEAR_Size - * @uses iPEAR_Size_Output_Driver + * @uses PEAR_Size_Output_Driver * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: Size_Output_text.php,v 1.5 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: Size_Output_text.php,v 1.6 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ -class PEAR_Size_Output_Text implements PEAR_Size_Output_Driver +class PEAR_Size_Output_Text extends PEAR_Size_Output_Driver { /** @@ -103,5 +103,30 @@ } return $tbl; } + /** + * generate the report + * + * @param array $channel_stats contains statistics for each channel + * @param array $search_roles roles searched for + * @param array $grand_total entire total of disk space consumed by channel + * @param array $display_params parameters relevant to display of report. + * + * @return void + */ + public function generateReport($channel_stats, + $search_roles, + $grand_total, + $display_params) + { + if ($display_params["verbose"]) { + $this->cols = 3; + } else { + $this->cols = 2; + } + parent::generateReport($channel_stats, + $search_roles, + $grand_total, + $display_params); + } } ?> http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/docs/script-usage.txt?r1=1.2&r2=1.3&diff_format=u Index: pear/PEAR_Size/docs/script-usage.txt diff -u pear/PEAR_Size/docs/script-usage.txt:1.2 pear/PEAR_Size/docs/script-usage.txt:1.3 --- pear/PEAR_Size/docs/script-usage.txt:1.2 Thu Mar 20 00:26:07 2008 +++ pear/PEAR_Size/docs/script-usage.txt Sat Mar 29 01:03:59 2008 @@ -4,6 +4,7 @@ -a, --all display information for all installed packages -A, --allchannels list packages from all channels, not just the default one -c, --channel specify which channel + -C, --csv output results in CSV format (sizes are measured in bytes). -h, --human-readable print sizes in human readable format (for example: 492 B 1KB 7MB) -H, --si likewise, but use powers of 1000 not 1024 -t, --type specify what type of files are required for the report http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/scripts/pearsize.php?r1=1.6&r2=1.7&diff_format=u Index: pear/PEAR_Size/scripts/pearsize.php diff -u pear/PEAR_Size/scripts/pearsize.php:1.6 pear/PEAR_Size/scripts/pearsize.php:1.7 --- pear/PEAR_Size/scripts/pearsize.php:1.6 Thu Mar 27 22:42:40 2008 +++ pear/PEAR_Size/scripts/pearsize.php Sat Mar 29 01:03:59 2008 @@ -11,12 +11,12 @@ * @package PEAR_Size * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) - * @version CVS: $Id: pearsize.php,v 1.6 2008/03/27 22:42:40 kguest Exp $ + * @version CVS: $Id: pearsize.php,v 1.7 2008/03/29 01:03:59 kguest Exp $ * @link pearsize.php * * $ pearsize --all - * $ pearsize Validate_IE - * $ pearsize Validate_IE --type=test,doc + * $ pearsize Console_Table + * $ pearsize Console_Table --type=test,doc */ /** * Neded to parse options on command line @@ -82,6 +82,8 @@ fputs(STDOUT, " -A, --allchannels "); fputs(STDOUT, "list packages from all channels, not just the default one\n"); fputs(STDOUT, " -c, --channel specify which channel\n"); + fputs(STDOUT, " -C, --csv output results in CSV format "); + fputs(STDOUT, "(sizes are measured in bytes).\n"); fputs(STDOUT, " -h, --human-readable print sizes in human readable "); fputs(STDOUT, "format (for example: 492 B 1KB 7MB)\n"); fputs(STDOUT, " -H, --si "); @@ -104,9 +106,9 @@ fputs(STDOUT, "\nExamples: $ {$app} --all - $ {$app} Validate_IE - $ {$app} -ttest,doc Validate_IE - $ {$app} --type=test,doc,php -h Validate_IE Date_Holidays + $ {$app} Console_Table + $ {$app} -ttest,doc Console_Table + $ {$app} --type=test,doc,php -h Console_Table Date_Holidays \n"); } } @@ -135,6 +137,7 @@ 'all', 'allchannels', 'channel==', + 'csv', 'help', 'human-readable', 'si', @@ -144,7 +147,7 @@ 'version', ); -$options = Console_Getopt::getopt($argv, "aAc:hHt:SsVv", $long_options); +$options = Console_Getopt::getopt($argv, "aAc:ChHt:SsVv", $long_options); if (PEAR::isError($options)) { usage($options); http://cvs.php.net/viewvc.cgi/pear/PEAR_Size/Size/Size_Output_csv.php?view=markup&rev=1.1 Index: pear/PEAR_Size/Size/Size_Output_csv.php +++ pear/PEAR_Size/Size/Size_Output_csv.php <?php /** * CSV renderer for PEAR_Size component. * * PHP Version 5 * * @category PEAR * @package PEAR_Size * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) * @version CVS: $Id: Size_Output_csv.php,v 1.1 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ /** * Output info in Comma Seperated Value style. * * @category PEAR * @package PEAR_Size * @uses PEAR_Size_Output_Driver * @author Ken Guest <ken@linux.ie> * @license LGPL (see http://www.gnu.org/licenses/lgpl.html) * @version CVS: $Id: Size_Output_csv.php,v 1.1 2008/03/29 01:03:59 kguest Exp $ * @link http://pear.php.net/package/PEAR_Size */ class PEAR_Size_Output_CSV extends PEAR_Size_Output_Driver { /** * generate the report * * @param array $channel_stats contains statistics for each channel * @param array $search_roles roles searched for * @param array $grand_total entire total of disk space consumed by channel * @param array $display_params parameters relevant to display of report. * * @return void */ public function generateReport($channel_stats, $search_roles, $grand_total, $display_params) { $indices = substr($search_roles, 1, strlen($search_roles) - 2); $details = explode("|", $indices); echo "channel,package,total,", str_replace("|", ",", $indices), "\n"; foreach ($channel_stats as $channel_name=>$ca) { list($stats, $channel_total) = $ca; foreach ($stats as $statistic) { $content = array(); $content[] = $channel_name; $content[] = $statistic['package']; $content[] = $statistic['total']; foreach ($details as $detail) { $content[] = $statistic['sizes'][$detail]; } echo implode($content, ","), "\n"; } } } } ?>
« previous php.pear.cvs (#51731) next »