[Dehs-devel] r180 - trunk

Raphael Geissert geissert at alioth.debian.org
Mon Feb 1 23:40:31 UTC 2010


Author: geissert
Date: 2010-02-01 23:40:31 +0000 (Mon, 01 Feb 2010)
New Revision: 180

Modified:
   trunk/dehs_pg.php
Log:
Add support for source packages format 3.0, contributed by Didier Raboud


Modified: trunk/dehs_pg.php
===================================================================
--- trunk/dehs_pg.php	2010-01-15 05:49:24 UTC (rev 179)
+++ trunk/dehs_pg.php	2010-02-01 23:40:31 UTC (rev 180)
@@ -29,6 +29,9 @@
 #print_R($_SERVER);
 require "dehs.config.inc";
 require "events.class.php";
+# Use PEAR: Archive_Tar to uncompress 3.0 debian.tar.gz files
+require "PEAR.php"
+require "Archive/Tar.php";
 dir_ctrl($dirs);
 if (!function_exists('file_get_contents')) {
     function file_get_contents($filename) {
@@ -93,19 +96,27 @@
 }
 function ext_watch ($file,$pkg,$version) {
     if (!file_exists($file)) return "";
-    $zp=gzopen($file,"r") or die_status("Fail to open $file");
-    while (!gzeof($zp)) {
-        $line = gzgets ($zp,4096);
-        if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {
+    if (substr($file,-8) == ".diff.gz") {
+        // Format: 1.0
+        $zp=gzopen($file,"r") or die_status("Fail to open $file");
+        while (!gzeof($zp)) {
             $line = gzgets ($zp,4096);
-            preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);
-            for ($i = 1; $i <= $watch_lenght[1]; $i++)      {
-                $line=gzgets ($zp,4096);
-                $watch .=substr($line,1);
+            if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {
+                $line = gzgets ($zp,4096);
+                preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);
+                for ($i = 1; $i <= $watch_lenght[1]; $i++)      {
+                    $line=gzgets ($zp,4096);
+                    $watch .=substr($line,1);
+                }
+                break;
             }
-            break;
         }
     }
+    elseif (substr($file,-14) == ".debian.tar.gz") {
+        // Format 3.0 (*)
+        $AT = new Archive_Tar($file,'gz');
+        $watch = $AT->extractInString('debian/watch');
+    }
     if ($watch!=null) return $watch;
     else return NULL;
 }
@@ -132,7 +143,7 @@
     $rsql=pg_exec($db, "SELECT * FROM pkgs WHERE name like '$initial%' AND (md5_diff!=md5_atsource or md5_diff is null)") OR die_status("Error in diff query\n");
     $total=pg_numrows($rsql);
     $btotal=byte_total($db,$initial);
-    print "Total Diff to downlaod Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";
+    print "Total Diff to download Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";
     while ($res_array=pg_fetch_array($rsql)) {
         #if ($res_array['dist']=='non-US') $conn_id = $conn_non_us;
         #else
@@ -157,17 +168,17 @@
 }
 function download_diff(&$conn_id,$pkg,$version,$directory,$md5_diff,$md5_atsource,$diff_kb,$dist) {
     global $dirs,$mirrors;
-    $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . "$version.diff.gz";
-    #if ($dist=="non-US") $remotefile="/debian-non-US/$directory/$pkg" . "_" . "$version.diff.gz";
-    #else
-    $remotefile="/debian/$directory/$pkg" . "_" . "$version.diff.gz";
-    #print "$localfile - $remotefile\n";
-    if      (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
-        #    print "$pkg Diff.gz => Downloaded\n";
-        if(md5_of_file($localfile)==$md5_atsource) {
-            #print "MD5 => OK\n";
-            #unlink($localfile);
-            return $localfile;
+    $diffTypes = array(".diff.gz",".debian.tar.gz");
+    foreach($diffTypes as $diffType) {
+        $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . $version . $diffType;
+        $remotefile="/debian/$directory/$pkg" . "_" . "$version" . $diffType;
+        if      (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
+            #    print "$pkg Diff.gz => Downloaded\n";
+            if(md5_of_file($localfile)==$md5_atsource) {
+                #print "MD5 => OK\n";
+                #unlink($localfile);
+                return $localfile;
+            }
         }
     }
     print "Download Diff.gz of package $pkg => Fallito\n";
@@ -190,8 +201,48 @@
         foreach ($sections as $section) {
             $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";
             print "\nI'm parsing $dist/$section => Sources.gz\n";
-            # 1 Pacchetto - 2 versione - 3 np - 4 Directory - 5 md5
-            $regexp="/Package:\s($initial.*)[^a]Binary:\s(.+)[^a]Version:\s(\d+:)?(.+)[^a]Priority.+Maintainer:.+<([^>]+)>[^a].+Directory:\s(.+)[^a]Files:.+\s(\S{32})\s(\d+)\s" . '\1\S+' . "\.diff\.gz[^a](Uploaders:\s(.+)[^a])?(Dm-Upload-Allowed:\s(.+)[^a])?(Homepage:\s(.+)[^a])?(Vcs-Browser:\s(.+)[^a])?(Vcs-([A-Z][a-z]+):\s(.+)[^a])?(Checksums-\S+:\s(.+)[^a])?/Ssi";
+
+	    // Big regexp to parse a package entry
+
+            // [1] Source package name
+            $regexp  = "/Package:\s($initial.*)[^a]";
+            // [2]  : Binary package name
+            $regexp .= "Binary:\s(.+)[^a]";
+            // [3]  : Epoch
+            // [4]  : Version
+            $regexp .= "Version:\s(\d+:)?(.+)[^a]";
+            $regexp .= "Priority.+";
+            // [5]  : Maintainer email address
+            $regexp .= "Maintainer:.+<([^>]+)>[^a]";
+            $regexp .= ".+";
+            // [6]  : Source package format
+            $regexp .= "Format:\s(.+)[^a]";
+            // [7]  : Package directory
+            $regexp .= "Directory:\s(.+)[^a]";
+            // [8]  : md5sum of the .diff.gz (or .debian.tar.gz)
+            // [9]  : Size of the file in bytes
+            // [10] : Extension (.diff.gz or .debian.tar.gz)
+            $regexp .= "Files:.+\s(\S{32})\s(\d+)\s" . '\1\S+' . "(\.diff\.gz|\.debian\.tar\.gz)[^a]";
+            // [11] : Uploaders field
+            // [12] : Uploaders value
+            $regexp .= "(Uploaders:\s(.+)[^a])?";
+            // [13] : DM-Upload-Allowed field
+            // [14] : DM-Upload-Allowed value
+            $regexp .= "(Dm-Upload-Allowed:\s(.+)[^a])?";
+            // [15] : Homepage field
+            // [16] : Homepage value
+            $regexp .= "(Homepage:\s(.+)[^a])?";
+            // [17] : Vcs-Browser field
+            // [18] : Vcs-Browser value
+            $regexp .= "(Vcs-Browser:\s(.+)[^a])?";
+            // [19] : Vcs-* field
+            // [20] :     vcs type
+            // [21] : Vcs-* value
+            $regexp .= "(Vcs-([A-Z][a-z]+):\s(.+)[^a])?";
+            // [21] : Checksums-* field
+            // [22] : Checksums-* value
+            $regexp .= "(Checksums-\S+:\s(.+)[^a])?";
+            $regexp .= "/Ssi";
             $zp = gzopen($filename, "r") or die_status("Could not open $filename");
             $extracted=tempnam("/tmp/", "$dist_$section_Sources");
             exec("gzip -c -d $filename > $extracted");
@@ -225,16 +276,18 @@
         }
 	foreach ($pkgs as $package=>$matches) {
 	    $section = $pkgsections[$matches[1]];
+            // Maintainer email address
 	    if ($matches[5]) {
 		$matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]);
 		$matches[5]=pg_escape_string($matches[5]);
 	    }
-	    if ($matches[10]) {
-		$matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]);
-		$matches[10]=pg_escape_string($matches[10]);
+            // Uploaders
+	    if ($matches[12]) {
+		$matches[12]=iconv("ISO-8859-1","UTF-8",$matches[12]);
+		$matches[12]=pg_escape_string($matches[12]);
 	    }
 	    @pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error");
-	    $rst=@pg_exec($db, "INSERT INTO pkgs (name,version,dversionmangled,maint,dir,md5_atsource,bytes,dist,section,uploaders,homepage,vcs_browser,vcs_type,vcs,vcsoversource,lastpkgsourcesupdate) VALUES ('$matches[1]','$matches[4]','$matches[4]','$matches[5]','$matches[6]','$matches[7]','$matches[8]','$dist','$section','$matches[10]','$matches[14]','$matches[16]','$matches[18]','$matches[19]','0',now())");
+	    $rst=@pg_exec($db, "INSERT INTO pkgs (name,version,dversionmangled,maint,dir,md5_atsource,bytes,dist,section,uploaders,homepage,vcs_browser,vcs_type,vcs,vcsoversource,lastpkgsourcesupdate) VALUES ('$matches[1]','$matches[4]','$matches[4]','$matches[5]','$matches[7]','$matches[8]','$matches[9]','$dist','$section','$matches[12]','$matches[16]','$matches[18]','$matches[20]','$matches[21]','0',now())");
 	    if (!$rst) {
 		$rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");
 		$version = $matches[4]; // just for safety
@@ -250,7 +303,7 @@
 		    // and update the lastpkgsourcesupdate field
 		    $extra = ",lastpkgsourcesupdate=now()";
 		}
-		$rst=@pg_exec($db, "UPDATE pkgs SET name='$matches[1]',version='$matches[4]'$extra,maint='$matches[5]',dir='$matches[6]',md5_atsource='$matches[7]',bytes='$matches[8]',dist='$dist',section='$section',uploaders='$matches[10]',homepage='$matches[14]',vcs_browser='$matches[16]',vcs_type='$matches[18]',vcs='$matches[19]' WHERE name='$matches[1]' AND dist='$dist'") OR die_status("\nDb adding error =>" . pg_last_error() . "\n");
+		$rst=@pg_exec($db, "UPDATE pkgs SET name='$matches[1]',version='$matches[4]'$extra,maint='$matches[5]',dir='$matches[7]',md5_atsource='$matches[8]',bytes='$matches[9]',dist='$dist',section='$section',uploaders='$matches[12]',homepage='$matches[16]',vcs_browser='$matches[18]',vcs_type='$matches[20]',vcs='$matches[21]' WHERE name='$matches[1]' AND dist='$dist'") OR die_status("\nDb adding error =>" . pg_last_error() . "\n");
 	    }
 	    $bin_names=split(",", $matches[2]);
 	    foreach ($bin_names as $bin_name) {




More information about the Dehs-devel mailing list