[Dehs-devel] r176 - trunk

Raphael Geissert geissert at alioth.debian.org
Sat Dec 26 23:03:23 UTC 2009


Author: geissert
Date: 2009-12-26 23:03:23 +0000 (Sat, 26 Dec 2009)
New Revision: 176

Modified:
   trunk/dehs_pg.php
Log:
Fix parsing of Sources with multiple package versions


Modified: trunk/dehs_pg.php
===================================================================
--- trunk/dehs_pg.php	2009-11-25 17:55:19 UTC (rev 175)
+++ trunk/dehs_pg.php	2009-12-26 23:03:23 UTC (rev 176)
@@ -186,6 +186,7 @@
 
     foreach ($dists as $dist=>$sections) {
         $pkgs = array();
+	$pkgsections = array();
         foreach ($sections as $section) {
             $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";
             print "\nI'm parsing $dist/$section => Sources.gz\n";
@@ -204,42 +205,10 @@
                         $buff1 .= $line;
                     }
                     if (preg_match($regexp,$buff1,$matches))  {
-                        if (isset($pkgs[$matches[1]]))
-                            continue;
-                        else
-                            $pkgs[$matches[1]] = 1;
-                        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]);
-                        }
-                        @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())");
-                        if (!$rst) {
-                            $rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");
-                            $version = $matches[4]; // just for safety
-                            while ($res_array=pg_fetch_array($rsql)) {
-                                $version = $res_array['version'];
-                            }
-                            $extra = '';
-                            if ($version != $matches[4]) {
-                                // only update the dversionmangled field if the versions differ
-                                $extra = ",dversionmangled='$matches[4]'";
-                                // also reset wwiz_type
-                                $extra = ",wwiz_type=NULL";
-                                // 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");
-                        }
-                        $bin_names=split(",", $matches[2]);
-                        foreach ($bin_names as $bin_name) {
-                            pg_exec($db,"INSERT INTO bin_atsrc (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") OR die_status("Temp table pkgs_atsrc query error");
-                            $rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ;
-                        }
+                        if (!isset($pkgs[$matches[1]]) || is_updated($pkgs[$matches[1]][4],$matches[4],true)) {
+                            $pkgs[$matches[1]] = $matches;
+			    $pkgsections[$matches[1]] = $section;
+			}
                     }
                     else {
                         preg_match("/Package:\s(.+)[^a]Binary/im",$buff1,$matches);
@@ -253,6 +222,41 @@
             }
             gzclose($zp) ;
         }
+	foreach ($packages as $package=>$matches) {
+	    $section = $pkgsections[$matches[1]];
+	    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]);
+	    }
+	    @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())");
+	    if (!$rst) {
+		$rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");
+		$version = $matches[4]; // just for safety
+		while ($res_array=pg_fetch_array($rsql)) {
+		    $version = $res_array['version'];
+		}
+		$extra = '';
+		if ($version != $matches[4]) {
+		    // only update the dversionmangled field if the versions differ
+		    $extra = ",dversionmangled='$matches[4]'";
+		    // also reset wwiz_type
+		    $extra = ",wwiz_type=NULL";
+		    // 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");
+	    }
+	    $bin_names=split(",", $matches[2]);
+	    foreach ($bin_names as $bin_name) {
+		pg_exec($db,"INSERT INTO bin_atsrc (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") OR die_status("Temp table pkgs_atsrc query error");
+		$rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ;
+	    }
+	}
     }
     clear_db($db);
     pg_close($db);




More information about the Dehs-devel mailing list