[php-apt-parser-maint] r15 - in /branches/des: ChangeLog README examples/ examples/packages.cgi examples/packages.css parse-apt-files.inc

php-apt-parser-maint at lists.alioth.debian.org php-apt-parser-maint at lists.alioth.debian.org
Sun Jun 25 01:09:44 UTC 2006


Author: des-guest
Date: Sun Jun 25 01:09:37 2006
New Revision: 15

URL: http://svn.debian.org/wsvn/php-apt-parser/?sc=1&rev=15
Log:
parse-apt-files.inc: 
 - bring file up to date, 
README:
 - Added info about debarchiver specific usage
ChangeLog: 
 - Make consistent format
Examples:
 - added current .cgi and .css examples

Added:
    branches/des/examples/
    branches/des/examples/packages.cgi   (with props)
    branches/des/examples/packages.css
Modified:
    branches/des/ChangeLog
    branches/des/README
    branches/des/parse-apt-files.inc

Modified: branches/des/ChangeLog
URL: http://svn.debian.org/wsvn/php-apt-parser/branches/des/ChangeLog?rev=15&op=diff
==============================================================================
--- branches/des/ChangeLog (original)
+++ branches/des/ChangeLog Sun Jun 25 01:09:37 2006
@@ -1,17 +1,72 @@
-2006-06-24  Damián Viano  <debian at damianv.com.ar>
-	* README: added info from parse-apt-files.inc
-	* ChangeLog: added entries from parse-apt-files.inc
-	* LICENSE: added MIT license, and Jarno Elonen copyright notice
-	* parse-apt-files.inc: removed all that (now) redundant info
+2006-06-24  Damián Viano  <debian at damianv.com.ar>, 1.3.0:
+	* README: added info from parse-apt-files.inc, and mention to debarchiver
+	  specific usage
+	* ChangeLog: added entries from parse-apt-files.inc, make it consistent
+	* LICENSE: added MIT license, and Jarno Elonen, Daniel Leidert and Damián
+	  Viano copyright notice
+	* parse-apt-files.inc: 
+	  - bring file up to date, 
+		- removed all that (now) redundant info
+	* examples/: 
+	  - added example packages.cgi
+	  - added example packages.css
 
-2004-10-17  Jarno Elonen  <elonen at debian.org>
-	Version 1.2
+2006-04-27, Damián Viano <debian at damianv.com.ar.>, 1.2.9:
+	* parse-apt-files.inc: 
+		- added span, and class declarations for css, also removed hardcoded
+		  formating
+	  - improved html formating
+
+2006-04-26, Damián Viano <debian at damianv.com.ar.>, 1.2.8:
+	* parse-apt-files.inc: 
+		- added support for a $base_url global to make links absolutes, useful
+		  when runned as cgi
+		- smart striping absolute paths from changes and buildlog files based on
+		  $base_url
+		- fix typo in parsing that messed descriptions with two spaces in the
+		  beggining of a description line
+
+2006-01-04, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.7:
+	* parse-apt-files.inc: 
+		- when searching for .changes and .build files, the search failed, if
+			version number contained x:up_ver-deb_ver (e.g.  3:3.0.5-1). We now
+			remove a leading 'x:' from the version number and finally find our
+			files.
+
+2005-09-21, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.6:
+	* parse-apt-files.inc: 
+	  - removed id from package description fields (reverts 1.2.5 changes)
+
+2005-06-27, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.5:
+	* parse-apt-files.inc: 
+	  - add id to package description fields <b id= "MD5SUM_PACKAGE_VERSION"></b>
+
+2005-06-23, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.4:
+	* parse-apt-files.inc: 
+	  - output section after version if contrib or non-free
+	  - fix XHTML output (validated against http://schneegans.de/sv/)
+
+2005-06-18, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.3:
+	* parse-apt-files.inc: 
+		- links to .build files can be included in overview (found similiar to
+		  .changes files)
+
+2005-06-08, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.2:
+	* parse-apt-files.inc: 
+	  - .changes files of binary-only uploads are now detected
+
+2005-04-20, Daniel Leidert <daniel.leidert at wgdd.de>, 1.2.1:
+	* parse-apt-files.inc: 
+	  - added support for multiple Sources.gz files in parse_and_list()
+	  - added support for shared directory containing.changes files
+	  - quick fix for html link regex
+
+2004-10-17  Jarno Elonen  <elonen at debian.org>, 1.2.0:
 	* parse-apt-files.inc: 
 	  - search for .changes file and print a link if possible
 	  - support for non-compressed Packages and Sources files
 
-2004-08-09  Jarno Elonen  <elonen at debian.org>
-	Version 1.1
+2004-08-09  Jarno Elonen  <elonen at debian.org>, 1.1.0:
 	* parse-apt-files.inc: 
 	  - added support for multiple architectures (thanks to  Djoumé Salvetti)
 	  - added support for multiple versions of the same package

Modified: branches/des/README
URL: http://svn.debian.org/wsvn/php-apt-parser/branches/des/README?rev=15&op=diff
==============================================================================
--- branches/des/README (original)
+++ branches/des/README Sun Jun 25 01:09:37 2006
@@ -9,3 +9,16 @@
 
  include_once("parse-apt-files.inc");
  parse_and_list( Array("i386/Packages.gz", "powerpc/Packages.gz"), "Sources.gz" );
+
+... or especially for debarchiver:
+
+ include_once("parse-apt-files.inc");
+ parse_and_list(
+     Array("dists/sid/main/binary-i386/Packages.gz",
+           "dists/sid/contrib/binary-i386/Packages.gz",
+           "dists/sid/non-free/binary-i386/Packages.gz"),
+     Array("dists/sid/main/source/Sources.gz",
+           "dists/sid/contrib/source/Sources.gz",
+           "dists/sid/non-free/source/Sources.gz"),
+     "dists/sid/installed",
+     "build_logs");

Added: branches/des/examples/packages.cgi
URL: http://svn.debian.org/wsvn/php-apt-parser/branches/des/examples/packages.cgi?rev=15&op=file
==============================================================================
--- branches/des/examples/packages.cgi (added)
+++ branches/des/examples/packages.cgi Sun Jun 25 01:09:37 2006
@@ -1,0 +1,72 @@
+#!/usr/bin/php
+<? echo "Content-Type: text/html; charset=UTF-8\n\n"; ?>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta name="Description" content="Debian packages in my unofficial Debian repository" />
+    <link rel="stylesheet" type="text/css" title="Default" href="/packages.css" />
+    <title>Debian packages in my unofficial Debian repository</title>
+  </head>
+  <body>
+    <h1>Debian packages in my unofficial Debian repository</h1>
+<?
+      include_once("parse-apt-files.inc");
+
+      $debarchiver_destdir= "/home/user/public_html/debian/dists";
+      $base_url= "http://example.com/~user/debian/";
+
+?>
+    <p>
+      This is where I keep my Debian packages, official and unofficial ones.
+    </p>
+    <p>
+      The repository can be accessed by:
+    </p>
+    <pre>
+      deb <?= $base_url ?> unstable main non-free contrib
+      deb-src <?= $base_url ?> unstable main non-free contrib
+    </pre>
+    <p>
+      Of course you may need to s/unstable/testing/ or s/unstable/stable/ accordingly. Distribution names also work (i.e. sarge, etch, sid).
+    </p>
+    <h2>Packages in unstable</h2>
+<?
+      parse_and_list(
+                     Array("$debarchiver_destdir/unstable/main/binary-i386/Packages.gz",
+                           "$debarchiver_destdir/unstable/contrib/binary-i386/Packages.gz",
+                           "$debarchiver_destdir/unstable/non-free/binary-i386/Packages.gz"),
+                     Array("$debarchiver_destdir/unstable/main/source/Sources.gz",
+                           "$debarchiver_destdir/unstable/contrib/source/Sources.gz",
+                           "$debarchiver_destdir/unstable/non-free/source/Sources.gz"),
+                           "$debarchiver_destdir/unstable/installed",
+                           "$debarchiver_destdir/../build_logs");
+?>
+    <h2>Packages in testing</h2>
+<?
+      parse_and_list(
+                     Array("$debarchiver_destdir/testing/main/binary-i386/Packages.gz",
+                           "$debarchiver_destdir/testing/contrib/binary-i386/Packages.gz",
+                           "$debarchiver_destdir/testing/non-free/binary-i386/Packages.gz"),
+                     Array("$debarchiver_destdir/testing/main/source/Sources.gz",
+                           "$debarchiver_destdir/testing/contrib/source/Sources.gz",
+                           "$debarchiver_destdir/testing/non-free/source/Sources.gz"),
+                           "$debarchiver_destdir/testing/installed",
+                           "$debarchiver_destdir/../build_logs");
+?>
+    <h2>Packages in stable</h2>
+<?
+      parse_and_list(
+                     Array("$debarchiver_destdir/stable/main/binary-i386/Packages.gz",
+                           "$debarchiver_destdir/stable/contrib/binary-i386/Packages.gz",
+                           "$debarchiver_destdir/stable/non-free/binary-i386/Packages.gz"),
+                     Array("$debarchiver_destdir/stable/main/source/Sources.gz",
+                           "$debarchiver_destdir/stable/contrib/source/Sources.gz",
+                           "$debarchiver_destdir/stable/non-free/source/Sources.gz"),
+                           "$debarchiver_destdir/stable/installed",
+                           "$debarchiver_destdir/../build_logs");
+?>
+  </body>
+</html>

Propchange: branches/des/examples/packages.cgi
------------------------------------------------------------------------------
    svn:executable = *

Added: branches/des/examples/packages.css
URL: http://svn.debian.org/wsvn/php-apt-parser/branches/des/examples/packages.css?rev=15&op=file
==============================================================================
--- branches/des/examples/packages.css (added)
+++ branches/des/examples/packages.css Sun Jun 25 01:09:37 2006
@@ -1,0 +1,61 @@
+body
+ {
+ background-color: #FFFFFF;
+ color: #000000;
+ font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-size: 10pt;
+
+ margin-top:   0;
+ margin-left:  2pt;
+ margin-right: 2pt;
+ }
+
+H1
+ {
+ background-color: #AAAAEE;
+ color: #303030;
+  
+ font-size:    15pt;
+ font-style:   normal;
+ font-variant: normal;
+ font-weight:  bold;
+ line-height:  normal;
+
+ text-align:     center;
+ vertical-align: middle;
+ 
+  border:  1px solid #333333;
+ }
+ 
+H2
+ {
+ background-color: #DF0451;
+ color: #303030;
+  
+ font-size:    13pt;
+ font-style:   normal;
+ font-variant: normal;
+/* font-weight:  bold; */
+ line-height:  normal;
+
+ text-align:     center;
+ vertical-align: middle;
+ 
+ border:  1px solid #333333;
+ }
+
+div.package
+ {
+ background-color: #DDDDFF;
+
+ margin-left:  3%;
+ margin-right: 3%; 
+ border: solid;
+ border-width: thin;
+ border-color: gray;
+ }
+
+.name { font-weight:  bold; }
+.nonfree { color: #EEAAAA; }
+.contrib { color: #775555; }
+.main { color: #5555FE; }

Modified: branches/des/parse-apt-files.inc
URL: http://svn.debian.org/wsvn/php-apt-parser/branches/des/parse-apt-files.inc?rev=15&op=diff
==============================================================================
--- branches/des/parse-apt-files.inc (original)
+++ branches/des/parse-apt-files.inc Sun Jun 25 01:09:37 2006
@@ -1,11 +1,14 @@
 <?php
     //////////////////////////////////////////////////////////////////
-    // PHP Apt-file parser, Version 1.2
+    // PHP Apt-file parser, Version 1.3
     //
     // The following PHP functions parse Debian APT-repository files
     // (Packages.gz, Sources.gz) and generate an XHTML summary of them.
     //
     // Written by Jarno Elonen in 2003, 2004
+    // Written by Daniel Leidert in 2005, 2006
+    // Written by Damian Viano in 2006
+    //
     //////////////////////////////////////////////////////////////////
 
     // Parse Packages.gz or Sources.gz file and return an array of format
@@ -40,7 +43,7 @@
             {
                 if ( trim($line) !== "." )
                 {
-                    if ( $newtag || substr( 0,2 ) == "  " )
+                    if ( $newtag || substr( $line, 0, 2 ) == "  " )
                         $value .= "\n";
                     else
                         $value .= " ";
@@ -59,7 +62,8 @@
     // Convert given byte-size to more human readable format
     function human_format_size( $bytes )
     {
-        $formats = Array("%d Bytes", "%.1f KB", "%.1f MB", "%.1f GB", "%.1f TB");
+        $formats = Array("%d Bytes", "%.1f KB", "%.1f MB", "%.1f GB", "%.1f
+TB");
         $logsize = min((int)(log($bytes)/log(1024)), count($formats)-1);
         return sprintf( $formats[$logsize], $bytes/pow(1024, $logsize));
     }
@@ -69,27 +73,47 @@
     function link_aware_htmlize( $txt )
     {
         $res = "";
-        $linkpattern = '!([a-z]+://[^ $]+)!is';
+        $linkpattern = '!([a-z]+://[^ \n    \)$]+)!is';
         $frags = preg_split( $linkpattern, $txt, -1, PREG_SPLIT_DELIM_CAPTURE);
         foreach( $frags as $f )
         {
             if ( preg_match( $linkpattern, $f ))
-                $res .= '<a href="' . htmlentities($f) . '">' . htmlentities($f) . '</a>';
+                $res .= '<a href="' . htmlentities($f) . '">' . htmlentities
+($f) . '</a>';
             else
                 $res .= htmlentities( $f );
         }
-        return str_replace( "\n", "<br/>", $res );
+        return str_replace( "\n", "<br/>\n", $res );
     }
 
+        function parse_section( $section )
+        {
+                $res = "<span class=\"section\">";
+                if ( preg_match( "!(contrib/[a-z]+)!is", $section ))
+                    $res .= ', <span class="contrib">contrib</span>';
+                else if ( preg_match( "!(non-free/[a-z]+)!is", $section ))
+                    $res .= ', <span class="nonfree">non-free</span>';
+                else
+                    $res .= ', <span class="main">main</span>';
+                return $res . "</span>";
+        }
+
     // Parse given files and write out a nice summary in HTML
-    function parse_and_list( $packagesgzfiles, $sourcesgzfile )
+    function parse_and_list( $packagesgzfiles, $sourcesgzfile,
+$shared_changesdir = False, $shared_buildlogsdir = False )
     {
-        $sources_temp = parse_packages( $sourcesgzfile );
-
-    // Rebuild sources array
+        global $base_url;
+        if (!is_array($sourcesgzfile))
+            $sourcesgzfile = Array($sourcesgzfile);
+        
+        // Rebuild sources array
         $sources = Array();
-        while( list($i, $p) = each( $sources_temp ))
-            $sources[$p[0]] = $p[1];
+        foreach( $sourcesgzfile as $f )
+        {
+            $sources_temp = parse_packages( $f );
+            while( list($i, $p) = each( $sources_temp ))
+                    $sources[$p[0]] = $p[1];
+        }
 
         if (!is_array($packagesgzfiles))
             $packagesgzfiles = Array($packagesgzfiles);
@@ -109,15 +133,11 @@
         }
 
         // Walk through the packages and print out the info
-        $first = true;
         while( list($name_and_ver, $archs) = each( $packages ))
         {
-            print '<div>';
-
-            if ( !$first )
-                print "<br/>\n";
-            $first = false;
-
+            print "<div class=\"package\">\n";
+
+            // $first = false;
             // use the first arch for description etc.
             ksort( $archs );
             list($pkg, $fields) = reset($archs);
@@ -129,52 +149,163 @@
             else if ( isset( $sources[$pkg] ))
                 $srcfields = $sources[$pkg];
 
-            print '<b>' . htmlentities( $fields["Package"] ) . '</b> '.
-                  '<small>(' . htmlentities( $fields["Version"] ) . ')</small>' . "\n";
+            print '<span class="name">' .
+                  htmlentities( $fields["Package"] ) . '</span> '.
+                  '<span class="version">(' . htmlentities( $fields["Version"] ) .
+                  parse_section( $fields["Section"] ) . ')</span>' . "\n";
 
             if ( strlen(trim($fields["Description"])))
-                print ' - ' . htmlentities( preg_replace( '/[\n].*/', '',
+                print ' - <span class="short_description">' . htmlentities( preg_replace( '/[\n].*/', '',
                     $fields["Description"] ));
-            print "<br/><small>\n";
+            print "</span><br/>\n";
 
             $archlinks = Array();
             while( list($arch_name, list(, $arch_fields)) = each( $archs ))
                 $archlinks[] = '<a href="' .
+                    htmlentities( $base_url ) .
                     htmlentities( $arch_fields["Filename"] ) . '">' .
                     htmlentities( $arch_name ) . ' (' .
-                    human_format_size( $arch_fields["Size"]) . ")</a>\n";
-            print 'Binary for arch ' . join(', ', $archlinks);
-
+                    human_format_size( $arch_fields["Size"]) . ")</a>";
+            print 'Binary for arch <span class="archs">' . join(', ', $archlinks) . "</span>\n";
+
+
+            
+            // Figure out the most likely location for 'changes' file.
+            $changesdir = False;
+            if ( $shared_changesdir !== False )
+                $changesdir = $shared_changesdir;
+            else if (isset($srcfields["Directory"]))
+                $changesdir = $srcfields["Directory"];
+            else
+            {
+                $changesdir = pathinfo($some_bin);
+                $changesdir = $changesdir['dirname'];
+            }
+
+            $buildlogsdir = False;
+            if ( $shared_buildlogsdir !== False )
+                $buildlogsdir = $shared_buildlogsdir;
+            else if (isset($srcfields["Directory"]))
+                $buildlogsdir = $srcfields["Directory"];
+            else
+            {
+                $buildlogsdir = pathinfo($some_bin);
+                $buildlogsdir = $buildlogsdir['dirname'];
+            }
+
+            // If sources are available, print out location.
             if ( isset( $srcfields["Directory"] ))
             {
                 print '| <a href="' .
+                    htmlentities( $base_url ) .
                     htmlentities( $srcfields["Directory"] ) .
                     '">Source dir</a>' . "\n";
 
-                // Try to make a changes file link. This adds quite a bit
-                // of disk access so if your server is very busy, you might
-                // want to comment this out.
-                if ($dhandle = opendir( $srcfields["Directory"] ))
+            }
+  
+            // Try to make a changes file link. This adds quite a bit
+            // of disk access so if your server is very busy, you might
+            // want to comment this out.
+            if ($changesdir !== False && $dhandle = opendir( $changesdir ))
+            {
+                $chfile = False;
+                while (false !== ($file = readdir($dhandle)))
                 {
-                    $chfile = False;
-                    while (false !== ($file = readdir($dhandle)))
-                        if (strpos($file, $srcfields["Package"] . '_' . $srcfields["Version"] . '_') !== False &&
+                    if ( isset($fields["Source"] ))
+                    {
+                        if (strpos($file, $fields["Source"] . '_' .
+preg_replace('/^[0-9]+\:/', '', $fields["Version"])) !== False &&
                             strpos($file, '.changes') !== False )
-                        {
-                          print '| <a href="' . htmlentities( $srcfields["Directory"] . '/' . $file ) .
-                                '">Changes</a>' . "\n";
-                          break;
-                        }
-                    closedir($dhandle);
+                            $chfile = $file;
+                    }
+                    else if ( isset( $srcfields["Directory"] ))
+                    {
+                        if (strpos($file, $srcfields["Source"] . '_' .
+preg_replace('/^[0-9]+\:/', '', $fields["Version"])) !== False &&
+                            strpos($file, '.changes') !== False )
+                            $chfile = $file;
+                    }
+                    else
+                    {
+                        if (strpos($file, $fields["Package"] . '_' .
+preg_replace('/^[0-9]+\:/', '', $fields["Version"])) !== False &&
+                            strpos($file, '.changes') !== False )
+                            $chfile = $file;
+                    }
+                    if ( $chfile !== False )
+                    {
+                        print '| <a href="' .
+                            htmlentities( $base_url ) .
+                            htmlentities( preg_replace ( "!.*" . 
+                                                        preg_replace( 
+                                                           "!.*(/[^/]+/?)$!",
+                                                           '$1', 
+                                                           $base_url) . 
+                                                        "(.*)!", "$1",
+                                                        $changesdir) . 
+                                          '/' . $chfile ) .
+                            '">Changes</a>' . "\n";
+                        break;
+                    }
                 }
-            }
-
-            print "<br/><br/></small></div>\n" .
-                  "<blockquote><div><small>\n" .
-                  link_aware_htmlize(
-                      preg_replace( '/^[^\n]*\n/', '',
-                          $fields["Description"] )) .
-                   "\n</small></div></blockquote>\n\n\n";
+                closedir($dhandle);
+            }
+
+            // Try to make a build-log file link. This adds quite a bit
+            // of disk access so if your server is very busy, you might
+            // want to comment this out.
+            if ($buildlogsdir !== False && $dhandle = opendir( $buildlogsdir ))
+            {
+                $blfile = False;
+                while (false !== ($file = readdir($dhandle)))
+                {
+                    if ( isset($fields["Source"] ))
+                    {
+                        if (strpos($file, $fields["Source"] . '_' .
+preg_replace('/^[0-9]+\:/', '', $fields["Version"])) !== False &&
+                            strpos($file, '.build') !== False )
+                            $blfile = $file;
+                    }
+                    else if ( isset( $srcfields["Directory"] ))
+                    {
+                        if (strpos($file, $srcfields["Source"] . '_' .
+preg_replace('/^[0-9]+\:/', '', $fields["Version"])) !== False &&
+                            strpos($file, '.build') !== False )
+                            $blfile = $file;
+                    }
+                    else
+                    {
+                        if (strpos($file, $fields["Package"] . '_' .
+preg_replace('/^[0-9]+\:/', '', $fields["Version"])) !== False &&
+                            strpos($file, '.build') !== False )
+                            $blfile = $file;
+                    }
+                    if ( $blfile !== False )
+                    {
+                        print '| <a href="' .
+                            htmlentities( $base_url ) .
+                            htmlentities( preg_replace ( "!.*" . 
+                                                        preg_replace( 
+                                                           "!.*(/[^/]+/?)$!",
+                                                           '$1', 
+                                                           $base_url) . 
+                                                        "(.*)!", "$1",
+                                                        $buildlogsdir) . 
+                                          '/' . $blfile ) .
+                            '">Build-Log</a>' . "\n";
+                        break;
+                    }
+                }
+                closedir($dhandle);
+            }
+            
+            print "<br/><br/>\n" .
+                "<blockquote><p class=\"description\">\n" .
+                link_aware_htmlize(
+                    preg_replace( '/^[^\n]*\n/', '',
+                    $fields["Description"] )) .
+                "\n</p>\n" .
+                "</blockquote>\n</div>\n";
         }
     }
 ?>




More information about the php-apt-parser-maint mailing list