/[dehs]/trunk/dehs_pg.php
ViewVC logotype

Diff of /trunk/dehs_pg.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 178 by geissert, Sat Dec 26 23:37:17 2009 UTC revision 181 by geissert, Tue Feb 2 00:47:30 2010 UTC
# Line 29  ini_set ( "memory_limit", "80M"); Line 29  ini_set ( "memory_limit", "80M");
29  #print_R($_SERVER);  #print_R($_SERVER);
30  require "dehs.config.inc";  require "dehs.config.inc";
31  require "events.class.php";  require "events.class.php";
32    # Use PEAR: Archive_Tar to uncompress 3.0 debian.tar.gz files
33    require "PEAR.php";
34    require "Archive/Tar.php";
35  dir_ctrl($dirs);  dir_ctrl($dirs);
36  if (!function_exists('file_get_contents')) {  if (!function_exists('file_get_contents')) {
37      function file_get_contents($filename) {      function file_get_contents($filename) {
# Line 93  function dir_ctrl($dirs) { Line 96  function dir_ctrl($dirs) {
96  }  }
97  function ext_watch ($file,$pkg,$version) {  function ext_watch ($file,$pkg,$version) {
98      if (!file_exists($file)) return "";      if (!file_exists($file)) return "";
99      $zp=gzopen($file,"r") or die_status("Fail to open $file");      if (substr($file,-8) == ".diff.gz") {
100      while (!gzeof($zp)) {          // Format: 1.0
101          $line = gzgets ($zp,4096);          $zp=gzopen($file,"r") or die_status("Fail to open $file");
102          if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {          while (!gzeof($zp)) {
103              $line = gzgets ($zp,4096);              $line = gzgets ($zp,4096);
104              preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);              if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {
105              for ($i = 1; $i <= $watch_lenght[1]; $i++)      {                  $line = gzgets ($zp,4096);
106                  $line=gzgets ($zp,4096);                  preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);
107                  $watch .=substr($line,1);                  for ($i = 1; $i <= $watch_lenght[1]; $i++)      {
108                        $line=gzgets ($zp,4096);
109                        $watch .=substr($line,1);
110                    }
111                    break;
112              }              }
             break;  
113          }          }
114      }      }
115        elseif (substr($file,-14) == ".debian.tar.gz") {
116            // Format 3.0 (*)
117            $AT = new Archive_Tar($file,'gz');
118            $watch = $AT->extractInString('debian/watch');
119        }
120      if ($watch!=null) return $watch;      if ($watch!=null) return $watch;
121      else return NULL;      else return NULL;
122  }  }
# Line 132  function dl_diffs($initial = '') { Line 143  function dl_diffs($initial = '') {
143      $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");      $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");
144      $total=pg_numrows($rsql);      $total=pg_numrows($rsql);
145      $btotal=byte_total($db,$initial);      $btotal=byte_total($db,$initial);
146      print "Total Diff to downlaod Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";      print "Total Diff to download Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";
147      while ($res_array=pg_fetch_array($rsql)) {      while ($res_array=pg_fetch_array($rsql)) {
148          #if ($res_array['dist']=='non-US') $conn_id = $conn_non_us;          #if ($res_array['dist']=='non-US') $conn_id = $conn_non_us;
149          #else          #else
# Line 157  function dl_diffs($initial = '') { Line 168  function dl_diffs($initial = '') {
168  }  }
169  function download_diff(&$conn_id,$pkg,$version,$directory,$md5_diff,$md5_atsource,$diff_kb,$dist) {  function download_diff(&$conn_id,$pkg,$version,$directory,$md5_diff,$md5_atsource,$diff_kb,$dist) {
170      global $dirs,$mirrors;      global $dirs,$mirrors;
171      $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . "$version.diff.gz";      $diffTypes = array(".diff.gz",".debian.tar.gz");
172      #if ($dist=="non-US") $remotefile="/debian-non-US/$directory/$pkg" . "_" . "$version.diff.gz";      foreach($diffTypes as $diffType) {
173      #else          $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . $version . $diffType;
174      $remotefile="/debian/$directory/$pkg" . "_" . "$version.diff.gz";          $remotefile="/debian/$directory/$pkg" . "_" . "$version" . $diffType;
175      #print "$localfile - $remotefile\n";          if      (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
176      if      (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {              #    print "$pkg Diff.gz => Downloaded\n";
177          #    print "$pkg Diff.gz => Downloaded\n";              if(md5_of_file($localfile)==$md5_atsource) {
178          if(md5_of_file($localfile)==$md5_atsource) {                  #print "MD5 => OK\n";
179              #print "MD5 => OK\n";                  #unlink($localfile);
180              #unlink($localfile);                  return $localfile;
181              return $localfile;              }
182          }          }
183      }      }
184      print "Download Diff.gz of package $pkg => Fallito\n";      print "Download Diff.gz of package $pkg => Fallito\n";
# Line 190  function db_add($initial='') { Line 201  function db_add($initial='') {
201          foreach ($sections as $section) {          foreach ($sections as $section) {
202              $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";              $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";
203              print "\nI'm parsing $dist/$section => Sources.gz\n";              print "\nI'm parsing $dist/$section => Sources.gz\n";
204              # 1 Pacchetto - 2 versione - 3 np - 4 Directory - 5 md5  
205              $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
206    
207                // [1] Source package name
208                $regexp  = "/Package:\s($initial.*)[^a]";
209                // [2]  : Binary package name
210                $regexp .= "Binary:\s(.+)[^a]";
211                // [3]  : Epoch
212                // [4]  : Version
213                $regexp .= "Version:\s(\d+:)?(.+)[^a]";
214                $regexp .= "Priority.+";
215                // [5]  : Maintainer email address
216                $regexp .= "Maintainer:.+<([^>]+)>[^a]";
217                $regexp .= ".+";
218                // [6]  : Source package format
219                $regexp .= "Format:\s(.+)[^a]";
220                // [7]  : Package directory
221                $regexp .= "Directory:\s(.+)[^a]";
222                // [8]  : md5sum of the .diff.gz (or .debian.tar.gz)
223                // [9]  : Size of the file in bytes
224                // [10] : Extension (.diff.gz or .debian.tar.gz)
225                $regexp .= "Files:.+\s(\S{32})\s(\d+)\s" . '\1\S+' . "(\.diff\.gz|\.debian\.tar\.gz)[^a]";
226                // [11] : Uploaders field
227                // [12] : Uploaders value
228                $regexp .= "(Uploaders:\s(.+)[^a])?";
229                // [13] : DM-Upload-Allowed field
230                // [14] : DM-Upload-Allowed value
231                $regexp .= "(Dm-Upload-Allowed:\s(.+)[^a])?";
232                // [15] : Homepage field
233                // [16] : Homepage value
234                $regexp .= "(Homepage:\s(.+)[^a])?";
235                // [17] : Vcs-Browser field
236                // [18] : Vcs-Browser value
237                $regexp .= "(Vcs-Browser:\s(.+)[^a])?";
238                // [19] : Vcs-* field
239                // [20] :     vcs type
240                // [21] : Vcs-* value
241                $regexp .= "(Vcs-([A-Z][a-z]+):\s(.+)[^a])?";
242                // [21] : Checksums-* field
243                // [22] : Checksums-* value
244                $regexp .= "(Checksums-\S+:\s(.+)[^a])?";
245                $regexp .= "/Ssi";
246              $zp = gzopen($filename, "r") or die_status("Could not open $filename");              $zp = gzopen($filename, "r") or die_status("Could not open $filename");
247              $extracted=tempnam("/tmp/", "$dist_$section_Sources");              $extracted=tempnam("/tmp/", "$dist_$section_Sources");
248              exec("gzip -c -d $filename > $extracted");              exec("gzip -c -d $filename > $extracted");
# Line 225  function db_add($initial='') { Line 276  function db_add($initial='') {
276          }          }
277          foreach ($pkgs as $package=>$matches) {          foreach ($pkgs as $package=>$matches) {
278              $section = $pkgsections[$matches[1]];              $section = $pkgsections[$matches[1]];
279                // Maintainer email address
280              if ($matches[5]) {              if ($matches[5]) {
281                  $matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]);                  $matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]);
282                  $matches[5]=pg_escape_string($matches[5]);                  $matches[5]=pg_escape_string($matches[5]);
283              }              }
284              if ($matches[10]) {              // Uploaders
285                  $matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]);              if ($matches[12]) {
286                  $matches[10]=pg_escape_string($matches[10]);                  $matches[12]=iconv("ISO-8859-1","UTF-8",$matches[12]);
287                    $matches[12]=pg_escape_string($matches[12]);
288              }              }
289              @pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error");              @pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error");
290              $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())");
291              if (!$rst) {              if (!$rst) {
292                  $rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");                  $rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");
293                  $version = $matches[4]; // just for safety                  $version = $matches[4]; // just for safety
# Line 250  function db_add($initial='') { Line 303  function db_add($initial='') {
303                      // and update the lastpkgsourcesupdate field                      // and update the lastpkgsourcesupdate field
304                      $extra = ",lastpkgsourcesupdate=now()";                      $extra = ",lastpkgsourcesupdate=now()";
305                  }                  }
306                  $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");
307              }              }
308              $bin_names=split(",", $matches[2]);              $bin_names=split(",", $matches[2]);
309              foreach ($bin_names as $bin_name) {              foreach ($bin_names as $bin_name) {

Legend:
Removed from v.178  
changed lines
  Added in v.181

  ViewVC Help
Powered by ViewVC 1.1.5