Author: coar
Date: Tue Mar  9 03:24:02 2010
New Revision: 920640

URL: http://svn.apache.org/viewvc?rev=920640&view=rev
Log:
Start making more controllable

Modified:
    labs/pulse/web-reports/mlists.php

Modified: labs/pulse/web-reports/mlists.php
URL: 
http://svn.apache.org/viewvc/labs/pulse/web-reports/mlists.php?rev=920640&r1=920639&r2=920640&view=diff
==============================================================================
--- labs/pulse/web-reports/mlists.php (original)
+++ labs/pulse/web-reports/mlists.php Tue Mar  9 03:24:02 2010
@@ -2,8 +2,11 @@
 
 Header('text/html; charset=UTF-8');
 
+Include_Once('Console/Getopt.php')
 Include_Once('liststats-classes.php');
+
 $stderr = fopen('php://stderr', 'a');
+ob_start();
 
 function safelise($list) {
     $list = preg_replace('/@/', ' @ ', $list);
@@ -159,8 +162,100 @@ function chartit($o_db, $list, $width, $
  <body>
   <h1>The Apache Software Foundation Mailing Lists</h1>
 <?php
+/*
+ * Okey, here we go..
+ *
+ * Options:
+ *
+ * -1              Only report on the single date specified.
+ *                 Defaults to most recent; overrides -d; implies -G.
+ * -d days         Only include preceding n days in calculations.
+ *                 Default is all (-1).
+ * -D yy-mm        As-of date.  Default is most recent in database.
+ * -g              do graphs (default).
+ * -G              *don't* do graphs
+ * -n              do-nothing
+ * -o directory    Output directory for files.  Default is '.'.
+ * -O filename     Name of master file for output (default 'index.html').
+ *
+ */
+$tDirectory = '.';
+$tDoc = 'index.html';
+$dryRun = false;
+$graphs = true;
+$nDays = -1;
+$asof = null;
+
+$cg = new Console_Getopt();
+$a_argv = $cg->readPHPArgv();
+$cgstat = $cg->getopt($a_argv, '1D:d:gGO:o:');
+if (PEAR::isError($cgstat)) {
+    die('Error in command line: ' . $cgstat->getMessage() . "\n");
+}
+foreach ($cgstat[0] as $a_opt) {
+    if ($a_opt[0] == '1') {
+        /*
+         * How many days to inclue in the report.
+         */
+        $nDays = 1;
+    }
+    else if (($a_opt[0] == 'd') && ($nDays != 1)) {
+        $nDays = $a_opt[1];
+    }
+    else if ($a_opt[0] == 'D') {
+        $asof = $a_opt[1];
+    }
+    else if ($a_opt[0] == 'g') {
+        /*
+         * Produce and include the graphs.
+         */
+        $graphs = true;
+    }
+    else if ($a_opt[0] == 'G') {
+        /*
+         * Omit the charts.
+         */
+        $graphs = false;
+    }
+    else if ($a_opt[0] == 'n') {
+        /*
+         * Don't actually produce any output.
+         */
+        $dryRun = true;
+    }
+    else if ($a_opt[0] == 'o') {
+        /*
+         * Where to put the files?
+         */
+        $tDirectory = $a_opt[1];
+    }
+    else if ($a_opt[0] == 'O') {
+        /*
+         * Main document for pulling the bits together.
+         */
+        $tDoc = $a_opt[1];
+    }
+    else {
+        /*
+         * Beats me; what option *is* this?
+         */
+        die('Unrecognised option: ' . array_shift($a_opt)
+            . "\n"
+            . print_r($a_opt, true));
+    }
+}
+
+if ($nDays == 1) {
+    $graphs = false;
+}
+
+
 $o_db = new lsDB($_SERVER['PULSE_DB_HOST'], $_SERVER['PULSE_DB_USER'], 
$_SERVER['PULSE_DB_PASSWORD']);
-$asof = $o_db->latest();
+
+if (! isset($asof)) {
+    $asof = $o_db->latest();
+}
+
 $o_sel_current = $o_db->select(array('asof' => $asof,
                                      'status' => 'public'));
 $a_mlists = $o_sel_current->mlists();
@@ -168,49 +263,49 @@ $a_domains = $o_sel_current->domains();
 $total_domains = count($a_domains);
 $total_lists = count($a_mlists);
 print "  <p>\n"
-    . "  This information is collected and analysed on a daily basis.\n"
-    . '  This report was generated at ' . strftime('%c', time()) . " and\n"
-    . "  covers a total of $total_lists mailing list"
-    . ($total_lists == 1 ? ' ' : 's ')
-    . "across $total_domains domain"
-    . ($total_domains == 1 ? '' : 's')
-    . ".\n"
-    . "  </p>\n"
-    . "  <p>\n"
-    . "  The graph alongside each list shows the gross activity over the\n"
-    . "  last 90 days.  The blue line\n"
-    . "  represents the number of subscribers to the list, and the red\n"
-    . "  line charts the number of posts <i>per</i> day.  They are not\n"
-    . "  to the same scale.  <b>This graph is indicative only, showing\n"
-    . "  trends, not exact counts.</b>\n"
-    . "  </p>\n"
-    . "  <menu>\n"
-    . "   <li><a href=\"#statistics\">Statistical summaries</a></li>\n"
-    . "  </menu>\n";
+      . "  This information is collected and analysed on a daily basis.\n"
+      . '  This report was generated at ' . strftime('%c', time()) . " and\n"
+      . "  covers a total of $total_lists mailing list"
+      . ($total_lists == 1 ? ' ' : 's ')
+      . "across $total_domains domain"
+      . ($total_domains == 1 ? '' : 's')
+      . ".\n"
+      . "  </p>\n"
+      . "  <p>\n"
+      . "  The graph alongside each list shows the gross activity over the\n"
+      . "  last 90 days.  The blue line\n"
+      . "  represents the number of subscribers to the list, and the red\n"
+      . "  line charts the number of posts <i>per</i> day.  They are not\n"
+      . "  to the same scale.  <b>This graph is indicative only, showing\n"
+      . "  trends, not exact counts.</b>\n"
+      . "  </p>\n"
+      . "  <menu>\n"
+      . "   <li><a href=\"#statistics\">Statistical summaries</a></li>\n"
+      . "  </menu>\n";
 
 if ($total_domains != 0) {
     $per_cell = ceil($total_domains / 3);
     print "  <p>\n"
-        . "  Jump to the lists for a domain:\n"
-        . "  </p>\n"
-        . "  <table class=\"TOC\">\n"
-        . "   <tr valign=\"top\">\n";
+          . "  Jump to the lists for a domain:\n"
+          . "  </p>\n"
+          . "  <table class=\"TOC\">\n"
+          . "   <tr valign=\"top\">\n";
     for ($i = 1; $i <= $total_domains; $i++) {
         if ((($i - 1) % $per_cell) == 0) {
             if ($i > 1) {
                 print "        </menu>\n"
-                    . "    </td>\n";
+                      . "    </td>\n";
             }
             print "    <td><menu>\n";
         }
         print '         <li><a href="#'
-            . fragmentalise($a_domains[$i - 1])
-            . '">' . $a_domains[$i - 1] . "</a></li>\n";
+              . fragmentalise($a_domains[$i - 1])
+              . '">' . $a_domains[$i - 1] . "</a></li>\n";
     }
     print "        </menu>\n"
-        . "    </td>\n"
-        . "   </tr>\n"
-        . "  </table>\n";
+          . "    </td>\n"
+          . "   </tr>\n"
+          . "  </table>\n";
 }
 
 $domain = null;
@@ -226,18 +321,18 @@ foreach ($a_mlists as $o_mlist) {
         }
         $domain = $cdomain;
         print "  <hr/>\n"
-            . '  <h2 id="' . fragmentalise($domain) . '">Domain '
-            . "<tt>$domain</tt></h2>\n";
+              . '  <h2 id="' . fragmentalise($domain) . '">Domain '
+              . "<tt>$domain</tt></h2>\n";
         $o_sel_indomain = $o_db->select(array('asof' => $asof,
                                               'status' => 'public',
                                               'domain' => $domain));
         $a_scratch = $o_sel_indomain->xids();
         $n = count($a_scratch);
         print "  <p>\n"
-            . "  A total of $n list"
-            . ($n == 1 ? '' : 's')
-            . ".\n"
-            . "  </p>\n";
+              . "  A total of $n list"
+              . ($n == 1 ? '' : 's')
+              . ".\n"
+              . "  </p>\n";
     }
     $mlist = $o_mlist->get('list');
     fputs($stderr, '#');
@@ -273,47 +368,47 @@ foreach ($a_mlists as $o_mlist) {
     }
     $a_posts[$mlist] = $o_mlist->get('posts');
     print "  <hr class=\"list\"/>\n"
-        . '  <h3 id="' . fragmentalise($mlist) . '">Mailing list '
-        . '<tt>' . safelise($mlist) . "</tt></h3>\n";
+          . '  <h3 id="' . fragmentalise($mlist) . '">Mailing list '
+          . '<tt>' . safelise($mlist) . "</tt></h3>\n";
     print "  <img src=\"$fname\"\n"
-        . "   width=\"468\" height=\"200\" style=\"float: right;\"\n"
-        . "   alt=\"[Activity graph]\" />\n"
-        . "  <p>\n"
-        . "  Traffic statistics cover a total of $days.\n"
-        . "  </p>\n"
-        . "  <table>\n"
-        . "   <tr>\n"
-        . "    <td>Current subscribers:</td>\n"
-        . '    <td>' . $o_mlist->subscriber_count() . "</td>\n"
-        . "   </tr>\n"
-        . "   <tr>\n"
-        . "    <td>Current digest subscribers:</td>\n"
-        . '    <td>'
-        . (isset($digesters)
-           ? $o_mlist->digester_count()
-           : '<i>No digest available</i>')
-        . "</td>\n"
-        . "   </tr>\n"
-        . "   <tr>\n"
-        . "    <td>Total posts ($days):</td>\n"
-        . "    <td>$posts</td>\n"
-        . "   </tr>\n"
-        . "   <tr>\n"
-        . "    <td>Mean posts <i>per</i> day:</td>\n"
-        . "    <td>$meanposts</td>\n"
-        . "   </tr>\n"
-        . "  </table>\n";
+          . "   width=\"468\" height=\"200\" style=\"float: right;\"\n"
+          . "   alt=\"[Activity graph]\" />\n"
+          . "  <p>\n"
+          . "  Traffic statistics cover a total of $days.\n"
+          . "  </p>\n"
+          . "  <table>\n"
+          . "   <tr>\n"
+          . "    <td>Current subscribers:</td>\n"
+          . '    <td>' . $o_mlist->subscriber_count() . "</td>\n"
+          . "   </tr>\n"
+          . "   <tr>\n"
+          . "    <td>Current digest subscribers:</td>\n"
+          . '    <td>'
+          . (isset($digesters)
+             ? $o_mlist->digester_count()
+             : '<i>No digest available</i>')
+          . "</td>\n"
+          . "   </tr>\n"
+          . "   <tr>\n"
+          . "    <td>Total posts ($days):</td>\n"
+          . "    <td>$posts</td>\n"
+          . "   </tr>\n"
+          . "   <tr>\n"
+          . "    <td>Mean posts <i>per</i> day:</td>\n"
+          . "    <td>$meanposts</td>\n"
+          . "   </tr>\n"
+          . "  </table>\n";
     if (isset($info)) {
         print "  <dl>\n"
-            . '   <dt><b>Description provided by the list '
-            . "moderators:</b></dt>\n"
-            . "   <dd>\n"
-            . "    <table class=\"description\">\n"
-            . "     <tr>\n"
-            . "      <td><pre>$info</pre></td>\n"
-            . "     </tr>\n"
-            . "    </table></dd>\n"
-            . "  </dl>\n";
+              . '   <dt><b>Description provided by the list '
+              . "moderators:</b></dt>\n"
+              . "   <dd>\n"
+              . "    <table class=\"description\">\n"
+              . "     <tr>\n"
+              . "      <td><pre>$info</pre></td>\n"
+              . "     </tr>\n"
+              . "    </table></dd>\n"
+              . "  </dl>\n";
     }
     print "  <br clear=\"all\"/>\n";
 }
@@ -335,9 +430,9 @@ foreach ($a_posts as $mlist => $posts) {
     $mlist = '<a href="#' . fragmentalise($mlist) . '"><tt>'
         . safelise($mlist) . "</tt></a";
     print "     <tr>\n"
-        . "      <td>$mlist</td>\n"
-        . "      <td>$posts</td>\n"
-        . "     </tr>\n";
+          . "      <td>$mlist</td>\n"
+          . "      <td>$posts</td>\n"
+          . "     </tr>\n";
     if ($n++ > 10) {
         break;
     }
@@ -357,9 +452,9 @@ foreach ($a_meanposts as $mlist => $post
     $mlist = '<a href="#' . fragmentalise($mlist) . '"><tt>'
         . safelise($mlist) . "</tt></a";
     print "     <tr>\n"
-        . "      <td>$mlist</td>\n"
-        . "      <td>$posts</td>\n"
-        . "     </tr>\n";
+          . "      <td>$mlist</td>\n"
+          . "      <td>$posts</td>\n"
+          . "     </tr>\n";
     if ($n++ > 10) {
         break;
     }
@@ -380,9 +475,9 @@ foreach ($a_subs as $mlist => $subs) {
     $mlist = '<a href="#' . fragmentalise($mlist) . '"><tt>'
         . safelise($mlist) . "</tt></a";
     print "     <tr>\n"
-        . "      <td>$mlist</td>\n"
-        . "      <td>$subs</td>\n"
-        . "     </tr>\n";
+          . "      <td>$mlist</td>\n"
+          . "      <td>$subs</td>\n"
+          . "     </tr>\n";
     if ($n++ > 10) {
         break;
     }
@@ -398,6 +493,12 @@ foreach ($a_subs as $mlist => $subs) {
  </body>
 </html>
 <?php
+$oFilename = realpath($tDirectory . DIRECTORY_SEPARATOR . $tDoc);
+$oFile = fopen($oFilename, 'w');
+$output = ob_get_contents();
+fputs($oFile, $output);
+fclose($oFile);
+
 /*
  * Local Variables:
  * mode: C



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to