[haiku-bugs] Re: [Haiku] #9837: Nightly images webpage buggy

  • From: "kneekoo" <trac@xxxxxxxxxxxx>
  • Date: Sun, 23 Jun 2013 15:54:00 -0000

#9837: Nightly images webpage buggy
---------------------------+-----------------------
   Reporter:  kneekoo      |      Owner:  haiku-web
       Type:  bug          |     Status:  new
   Priority:  normal       |  Milestone:
  Component:  Website/CMS  |    Version:
 Resolution:               |   Keywords:
 Blocked By:               |   Blocking:
Has a Patch:  0            |   Platform:  All
---------------------------+-----------------------

Comment (by kneekoo):

 OK, this code covers even more build cases, easily configurable.
 {{{
 <?php
 function format_bytes($size) {
         $units = array(' B', ' KiB', ' MiB', ' GiB', ' TiB');
         for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
         return round($size, 2).$units[$i];
 }

 function scanDirectory($dirName) {
         $revisions = array();

         // add or remove release types in the $key, $compilers and
 $releases arrays and the HTML will automatically be adjusted to them
         // format: "filestamp1" => "label1", "filestamp2" => "label2"
         $key = array("anyboot" => "Anyboot", "vmware" => "VMDK", "raw" =>
 "Raw", "cd" => "ISO");
         // format: "filestamp1", "filestamp2"
         $compilers = array("x86gcc2hybrid", "x86gcc2", "x86gcc4");
         // format: "filestamp1", "filestamp2"
         $releases = array("r", "hrev", "hrevr1alpha4");

         $types = implode("|", array_keys($key));
         $compiler_list = implode("|", $compilers);
         $release_list = implode("|", $releases);
         if ($listing = scandir($dirName)) {
                 foreach ($listing as $file) {
                         if ($data =
 
preg_match("/-($release_list)([0-9]+)-($compiler_list)-($types)\.(tar\.xz|zip)/",
 $file, $matches)) {
                                 $date = date("Y-m-j",
 filemtime($dirName.'/'.$file));
                                 $extension = $matches[5] == "tar.xz" ?
 "xz" : $matches[5];
                                 $size =
 format_bytes(filesize($dirName.'/'.$file));
                                 if (!array_key_exists($matches[2],
 $revisions)) {
                                         $revisions[$matches[2]] =
 array("link" => "<a href='http://dev.haiku-
 os.org/changeset/".$matches[2]."'>".$matches[1].$matches[2]."</a>");
                                         foreach($key as $type)
 $revisions[$matches[2]][$type] = array();
                                 }
                                 $package = "<a href=\"./$file\"
 title=\"$size $date\">$extension</a>";
 $revisions[$matches[2]][$key[$matches[4]]][] = $package;
                         }
                 }
 ?>
                 <table>
                         <tr>
                                 <th>Revision</th>
 <?php
                                 foreach($key as $name) echo "
 <th>$name</th>\n";
 ?>
                         </tr>
 <?php
                 foreach($revisions as $data) {
 ?>
                         <tr>
                                 <td><?php echo $data['link']; ?></td>
 <?php
                         foreach($key as $name) {
 ?>
                                 <td><?php echo implode(" ", $data[$name]);
 ?></td>
 <?php
                         }
 ?>
                         </tr>
 <?php
                 }
 ?>
                 </table>
 <?php
         }
 }
 ?>
 }}}

--
Ticket URL: <http://dev.haiku-os.org/ticket/9837#comment:3>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: