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

Contents of /trunk/dehs_pg.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 188 - (hide annotations) (download)
Fri Jan 21 02:48:01 2011 UTC (2 years, 4 months ago) by geissert
File size: 53761 byte(s)
Fix incorrect handling of epochs (Closes: #598710)
1 atomo64-guest 168 #!/usr/bin/php -q
2 atomo64-guest 54 <?php
3 evaso-guest 5 /*
4 atomo64-guest 54
5     Originally written by Stefano Fabri <bluefuture@nospam@email.it>
6     Copyright 2004, Stefano Fabri
7 atomo64-guest 105 Copyright 2007, 2008 by Raphael Geissert <atomo64@gmail.com>
8 atomo64-guest 54
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13    
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     GNU General Public License for more details.
18    
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 evaso-guest 5 */
23 atomo64-guest 54
24 evaso-guest 5 // stabilire una connessione
25     #ini_set ( "error_reporting", "E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR");
26     ini_set ("html_errors", "off");
27     set_time_limit(0);
28 geissert 177 ini_set ( "memory_limit", "80M");
29 evaso-guest 13 #print_R($_SERVER);
30     require "dehs.config.inc";
31 atomo64-guest 122 require "events.class.php";
32 geissert 180 # Use PEAR: Archive_Tar to uncompress 3.0 debian.tar.gz files
33 geissert 181 require "PEAR.php";
34 geissert 180 require "Archive/Tar.php";
35 evaso-guest 5 dir_ctrl($dirs);
36 evaso-guest 13 if (!function_exists('file_get_contents')) {
37 atomo64-guest 54 function file_get_contents($filename) {
38     if (!($file = fopen($filename,"rb"))) return false;
39     else {
40     $contents = "";
41     do {
42     $data = fread($file, 4096);
43     if (strlen($data) == 0) {
44     break;
45     }
46     $contents .= $data;
47     } while (true);
48     fclose($file);
49     return $contents;
50     }
51     }
52     }
53    
54     if (!function_exists('file_put_contents')) {
55     function file_put_contents($filename, $content, $flags = 0) {
56     if (!($file = fopen($filename,$flags))) return false;
57     else {
58     $n = fwrite($file, $content);
59     fclose($file);
60     return true;
61     }
62     }
63     }
64    
65 atomo64-guest 76 if (in_array("-db_add",$argv)) db_add((!empty($argv[2])?$argv[2]:''), false);
66     elseif (in_array("-db_query",$argv)) db_query($argv[2],(!empty($argv[3])?$argv[3]:'%') );
67 atomo64-guest 59 elseif (in_array("-dl_diffs",$argv) || in_array("-keep_diff",$argv)) dl_diffs($argv[2]);
68 atomo64-guest 64 elseif (in_array("-keep_sources",$argv) || in_array("-download_sources",$argv)) download_sources();
69 atomo64-guest 135 elseif (in_array("-db_popcon",$argv)) db_popcon();
70 atomo64-guest 122 elseif (in_array("-dl_popcon",$argv) || in_array("-keep_popcon",$argv)) dl_popcon();
71 atomo64-guest 85 elseif (in_array("-db_upstream",$argv)) db_upstream((!empty($argv[2])?$argv[2]:'%'));
72 atomo64-guest 149 elseif (in_array("-dl_from_vcs",$argv)) dl_from_vcs((!empty($argv[2])?$argv[2]:'%'),(!empty($argv[3])?$argv[3]:'%'));
73 atomo64-guest 54 elseif (in_array("-update_all",$argv)) update_all();
74 atomo64-guest 64 elseif (in_array("-update_new",$argv)) update_new();
75 atomo64-guest 65 elseif (in_array("-update_bogus",$argv)) update_bogus();
76 atomo64-guest 54 elseif (in_array("-check_db",$argv)) check_db();
77     elseif (in_array("-dehsqa_db",$argv)) dehsqa_db();
78     elseif (in_array("-clear_db",$argv)) clear_db();
79     elseif (in_array("-db_up_error",$argv)) db_up_error();
80 atomo64-guest 85 elseif (in_array("-up_changes",$argv)) up_changes((!empty($argv[2])?$argv[2]:'%'), true);
81     elseif (in_array("-watchf",$argv) || in_array("-wwiz",$argv)) watch_wizard((!empty($argv[2])?$argv[2]:'%'));
82 atomo64-guest 54 elseif (in_array("-kb_total",$argv)) print "Diff
83 evaso-guest 5 #stat_up_error();
84     #stat_up_error();to download Kb => " . kb_total($argv[2]) . "\n" ;
85 atomo64-guest 54 elseif (in_array("-watch_stat",$argv)) watch_stat();
86     else print "Command $argv[1] not found\n";
87 evaso-guest 5 #stat_up_error();
88     function dir_ctrl($dirs) {
89 atomo64-guest 132 if (!is_array($dirs)) {
90     $dirs = array($dirs);
91     }
92 atomo64-guest 54 foreach ($dirs as $dir) {
93     if (!is_dir($dir)) exec("mkdir -m 0740 -p " . escapeshellarg($dir), $output, $res);
94     if ($res != 0) die_status("Error creating basic dir: $dir\n");
95     }
96 evaso-guest 5 }
97 atomo64-guest 54 function ext_watch ($file,$pkg,$version) {
98     if (!file_exists($file)) return "";
99 geissert 180 if (substr($file,-8) == ".diff.gz") {
100     // Format: 1.0
101     $zp=gzopen($file,"r") or die_status("Fail to open $file");
102     while (!gzeof($zp)) {
103 atomo64-guest 54 $line = gzgets ($zp,4096);
104 geissert 180 if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {
105     $line = gzgets ($zp,4096);
106     preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);
107     for ($i = 1; $i <= $watch_lenght[1]; $i++) {
108     $line=gzgets ($zp,4096);
109     $watch .=substr($line,1);
110     }
111     break;
112 evaso-guest 5 }
113     }
114 atomo64-guest 54 }
115 geissert 182 elseif (preg_match('/\.debian\.tar\.(gz|bz2)$/', $file, $matches)) {
116 geissert 180 // Format 3.0 (*)
117 geissert 182 $AT = new Archive_Tar($file,$matches[1]);
118 geissert 180 $watch = $AT->extractInString('debian/watch');
119     }
120 atomo64-guest 54 if ($watch!=null) return $watch;
121     else return NULL;
122 evaso-guest 5 }
123     function ftp_cn($login,$password,$ftp_server) {
124 atomo64-guest 54 $conn_id = @ftp_connect($ftp_server) or die_status("Error: Cannot contact ftp server $ftp_server\n");
125     // login con user name e password
126     ftp_pasv($conn_id,1);
127     $login_result = ftp_login($conn_id, "anonymous","bo@bo.org");
128     // controllo della connessione
129     if ((!$conn_id) || (!$login_result)) {
130 evaso-guest 5 echo "Ftp connection failed!\n";
131     echo "Failed connection to $ftp_server\n";
132 atomo64-guest 49 die_status();
133 evaso-guest 5 } else {
134     return $conn_id;
135     }
136     }
137 atomo64-guest 59 function dl_diffs($initial = '') {
138 atomo64-guest 54 global $dirs,$dbconn,$mirrors;
139     check_db();
140     $conn_normal=ftp_cn("anonymous","bo@bo.org",$mirrors['unstable']);
141     #$conn_non_us=ftp_cn("anonymous","bo@bo.org",$mirrors["non-US"]);
142     $db = pg_pconnect($dbconn) ;
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");
144     $total=pg_numrows($rsql);
145     $btotal=byte_total($db,$initial);
146 geissert 180 print "Total Diff to download Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";
147 atomo64-guest 54 while ($res_array=pg_fetch_array($rsql)) {
148     #if ($res_array['dist']=='non-US') $conn_id = $conn_non_us;
149     #else
150     $conn_id = $conn_normal;
151 atomo64-guest 95 if ($localfile=download_diff($conn_id,$res_array[name],$res_array[version],$res_array['dir'],$res_array[md5_diff],$res_array[md5_atsource],$res_array[bytes],$res_array[dist])) {
152 atomo64-guest 54 $watch=ext_watch($localfile,$res_array[name],$res_array[version]);
153     unlink($localfile);
154     if ($watch!=NULL) {
155     $watch=iconv("ISO-8859-1","UTF-8",$watch);
156 atomo64-guest 66 $watch= pg_escape_string($watch);
157 atomo64-guest 54 pg_exec($db, "UPDATE pkgs SET watch='" . $watch . "', md5_diff='" . $res_array[md5_atsource] . "' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'") or die_status("Query error");
158     }
159     else pg_exec($db, "UPDATE pkgs SET watch=NULL, md5_diff='" . $res_array[md5_atsource] . "' where name='" . $res_array[name] . "' AND dist='" . $res_array[dist] ."'") or die_status("Errore nella query");
160     }
161     $btotal=$btotal-$res_array['bytes'];
162     number_format ($btotal/1024, 2, ",",".");
163     print "\rDiffs left => " . $total-- . " Bytes left => " . number_format ($btotal/1024, 2, ",",".") . " - " . $res_array[name];
164     }
165     ftp_quit($conn_normal);
166     pg_close($db);
167     return "Fatto\n";
168     }
169 atomo64-guest 95 function download_diff(&$conn_id,$pkg,$version,$directory,$md5_diff,$md5_atsource,$diff_kb,$dist) {
170 atomo64-guest 54 global $dirs,$mirrors;
171 geissert 182 $diffTypes = array(".diff.gz",".debian.tar.gz",".debian.tar.bz2");
172 geissert 188
173     if (strpos($version, ':') !== false)
174     $version = substr($version, strpos($version, ':')+1);
175    
176 geissert 180 foreach($diffTypes as $diffType) {
177     $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . $version . $diffType;
178     $remotefile="/debian/$directory/$pkg" . "_" . "$version" . $diffType;
179     if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
180     # print "$pkg Diff.gz => Downloaded\n";
181     if(md5_of_file($localfile)==$md5_atsource) {
182     #print "MD5 => OK\n";
183     #unlink($localfile);
184     return $localfile;
185     }
186 atomo64-guest 54 }
187     }
188     print "Download Diff.gz of package $pkg => Fallito\n";
189     return false;
190 evaso-guest 5 }
191 atomo64-guest 102 function db_add($initial='') {
192 atomo64-guest 54 global $dirs,$dists,$dbconn;
193     check_db();
194 atomo64-guest 64 download_sources();
195 atomo64-guest 54
196 atomo64-guest 65 $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
197 atomo64-guest 54 pg_exec($db, "CREATE TEMP TABLE pkgs_atsrc (name text,dist text)") or die_status('Error creating temp table pkgs_atsrc');
198     pg_exec($db, "CREATE UNIQUE INDEX idxdis on pkgs_atsrc (name,dist)") or die_status('Error creating index on temp table');
199     pg_exec($db, "CREATE TEMP TABLE bin_atsrc (name text,bin_name text, dist text)") or die_status('Error creating temp table pkgs_atsrc');
200     pg_exec($db, "CREATE UNIQUE INDEX idxbis on bin_atsrc (name,bin_name,dist)") or die_status('Error creating index on temp table bin_atsrc');
201    
202     foreach ($dists as $dist=>$sections) {
203 geissert 175 $pkgs = array();
204 geissert 176 $pkgsections = array();
205 evaso-guest 5 foreach ($sections as $section) {
206 atomo64-guest 54 $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";
207     print "\nI'm parsing $dist/$section => Sources.gz\n";
208 geissert 180
209     // Big regexp to parse a package entry
210    
211     // [1] Source package name
212     $regexp = "/Package:\s($initial.*)[^a]";
213     // [2] : Binary package name
214     $regexp .= "Binary:\s(.+)[^a]";
215     // [3] : Epoch
216     // [4] : Version
217     $regexp .= "Version:\s(\d+:)?(.+)[^a]";
218     $regexp .= "Priority.+";
219     // [5] : Maintainer email address
220     $regexp .= "Maintainer:.+<([^>]+)>[^a]";
221     $regexp .= ".+";
222     // [6] : Source package format
223     $regexp .= "Format:\s(.+)[^a]";
224     // [7] : Package directory
225     $regexp .= "Directory:\s(.+)[^a]";
226 geissert 182 // [8] : md5sum of the .diff.gz (or .debian.tar.(gz|bz2))
227 geissert 180 // [9] : Size of the file in bytes
228     // [10] : Extension (.diff.gz or .debian.tar.gz)
229 geissert 182 $regexp .= "Files:.+\s(\S{32})\s(\d+)\s" . '\1\S+' . "(\.diff\.gz|\.debian\.tar\.(?:gz|bz2))[^a]";
230 geissert 180 // [11] : Uploaders field
231     // [12] : Uploaders value
232     $regexp .= "(Uploaders:\s(.+)[^a])?";
233     // [13] : DM-Upload-Allowed field
234     // [14] : DM-Upload-Allowed value
235     $regexp .= "(Dm-Upload-Allowed:\s(.+)[^a])?";
236     // [15] : Homepage field
237     // [16] : Homepage value
238     $regexp .= "(Homepage:\s(.+)[^a])?";
239     // [17] : Vcs-Browser field
240     // [18] : Vcs-Browser value
241     $regexp .= "(Vcs-Browser:\s(.+)[^a])?";
242     // [19] : Vcs-* field
243     // [20] : vcs type
244     // [21] : Vcs-* value
245     $regexp .= "(Vcs-([A-Z][a-z]+):\s(.+)[^a])?";
246     // [21] : Checksums-* field
247     // [22] : Checksums-* value
248     $regexp .= "(Checksums-\S+:\s(.+)[^a])?";
249     $regexp .= "/Ssi";
250 atomo64-guest 54 $zp = gzopen($filename, "r") or die_status("Could not open $filename");
251     $extracted=tempnam("/tmp/", "$dist_$section_Sources");
252     exec("gzip -c -d $filename > $extracted");
253     $sourcesize=filesize($extracted);
254     unlink($extracted);
255     if(filesize($filename)>20) {
256     while (!gzeof($zp)) {
257     $line='';
258     while ($line!="\n") {
259     $line = gzgets ($zp,4096) ;
260     $buff1 .= $line;
261     }
262     if (preg_match($regexp,$buff1,$matches)) {
263 geissert 184 $matches[4] = ((isset($matches[3]) && strlen($matches[3]))? $matches[3] : ''). $matches[4];
264 geissert 176 if (!isset($pkgs[$matches[1]]) || is_updated($pkgs[$matches[1]][4],$matches[4],true)) {
265 geissert 177 unset($matches[0]);
266 geissert 176 $pkgs[$matches[1]] = $matches;
267     $pkgsections[$matches[1]] = $section;
268     }
269 atomo64-guest 54 }
270     else {
271     preg_match("/Package:\s(.+)[^a]Binary/im",$buff1,$matches);
272     if(strncmp($initial,$matches[1],strlen($initial))<0) break;
273     }
274     $left=$sourcesize-gztell($zp);
275     print "\rSource file Left => $left";
276     $buff1="";
277     unset($matches);
278     }
279 evaso-guest 5 }
280     gzclose($zp) ;
281     }
282 geissert 178 foreach ($pkgs as $package=>$matches) {
283 geissert 176 $section = $pkgsections[$matches[1]];
284 geissert 180 // Maintainer email address
285 geissert 176 if ($matches[5]) {
286     $matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]);
287     $matches[5]=pg_escape_string($matches[5]);
288     }
289 geissert 180 // Uploaders
290     if ($matches[12]) {
291     $matches[12]=iconv("ISO-8859-1","UTF-8",$matches[12]);
292     $matches[12]=pg_escape_string($matches[12]);
293 geissert 176 }
294     @pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error");
295 geissert 180 $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())");
296 geissert 176 if (!$rst) {
297     $rsql=pg_exec($db, "SELECT pkgs.version FROM pkgs WHERE name='$matches[1]' AND dist='$dist';");
298     $version = $matches[4]; // just for safety
299     while ($res_array=pg_fetch_array($rsql)) {
300     $version = $res_array['version'];
301     }
302     $extra = '';
303     if ($version != $matches[4]) {
304     // only update the dversionmangled field if the versions differ
305     $extra = ",dversionmangled='$matches[4]'";
306     // also reset wwiz_type
307     $extra = ",wwiz_type=NULL";
308     // and update the lastpkgsourcesupdate field
309     $extra = ",lastpkgsourcesupdate=now()";
310     }
311 geissert 180 $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");
312 geissert 176 }
313     $bin_names=split(",", $matches[2]);
314     foreach ($bin_names as $bin_name) {
315     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");
316     $rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ;
317     }
318     }
319 atomo64-guest 54 }
320 atomo64-guest 102 clear_db($db);
321 atomo64-guest 54 pg_close($db);
322 evaso-guest 5 }
323 atomo64-guest 72 function db_query($pkg,$dist='%') {
324 atomo64-guest 54 global $dirs,$dbconn;
325 atomo64-guest 65 $db = pg_pconnect($dbconn ) or die_status(pg_last_error($db));
326 atomo64-guest 122 $rsql=pg_exec($db, "SELECT * FROM pkgs
327     WHERE name='$pkg' AND dist LIKE '$dist';");
328 atomo64-guest 72 while ($res_array=pg_fetch_array($rsql)) {
329 atomo64-guest 54 print "Package=> " . $res_array['name'] . "\n";
330     print "Version => " . $res_array['version'] . "\n";
331 atomo64-guest 73 print "Mangled version => " . $res_array['dversionmangled'] . "\n";
332 atomo64-guest 54 print "Diff MD5 Downloaded => " . $res_array['md5_diff'] . "\n";
333     print "Diff MD5 at Sources => " . $res_array['md5_atsource'] . "\n";
334     print "Distribution => " . $res_array['dist'] . "\n";
335     print "Section => " . $res_array['section'] . "\n";
336     print "KBytes => " . number_format ( $res_array['bytes']/1024, 2, ",",".") . "\n";
337 atomo64-guest 122 print "Pop Inst=>" . $res_array['pop_inst'] . "\n";
338 evaso-guest 5 if ($res_array['watch']) {
339 atomo64-guest 54 $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$res_array['watch']);
340 atomo64-guest 121 print "Version Upstream => " . $uscan_res['uversion'] . "\n";
341 atomo64-guest 72 print "Watch => " . trim($res_array['watch'])."\n";
342 atomo64-guest 121 print "Watch Warnings => " . $uscan_res['warnings'];
343 evaso-guest 5 }
344     else print "Watch => Not present" . "\n";
345 atomo64-guest 58 if ($res_array['wwiz_type']) {
346     $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$res_array['wwiz']);
347 atomo64-guest 121 print "WWiz Upstream => " . $uscan_res['uversion'] . "\n";
348 atomo64-guest 72 print "WWiz => " . $res_array['wwiz']."\n";
349 atomo64-guest 121 print "WWiz Warings => " . $uscan_res['warnings'];
350 atomo64-guest 58 }
351     print "\n";
352 atomo64-guest 54 }
353 atomo64-guest 72 if (pg_numrows($rsql)==0) echo "Package=> " . $pkg . "\nNot found\n!!";
354 atomo64-guest 54 pg_close($db);
355 evaso-guest 5 }
356 atomo64-guest 54 function byte_total(&$db,$initial) {
357     global $dirs;
358     $rsql=pg_exec ($db,"Select sum(bytes) as totbytes FROM pkgs WHERE name like '$initial%' AND (md5_diff!=md5_atsource or md5_diff is null)");
359     $res_array=pg_fetch_array($rsql);
360     return $res_array[totbytes] ;
361 evaso-guest 5 }
362 atomo64-guest 64 function download_sources () {
363 atomo64-guest 54 global $dirs,$dists,$mirrors;
364     foreach ($dists as $dist=>$sections) {
365     $server=$mirrors[$dist];
366     $conn_id = ftp_cn("anonymous","bo@bo.org",$server);
367     foreach ($sections as $section) {
368     $localfile=$dirs[sources_dir] . "/$dist/$section/Sources.gz";
369     $remotefile=remote_dist_dir($dist) . "/$dist/$section/source/Sources.gz";
370     $sources_info=md5_source($section,$dist);
371     if (!file_exists ($dirs[sources_dir] . "/$dist/")) mkdir ( $dirs[sources_dir] . "/$dist",0740);
372     if (!file_exists ($dirs[sources_dir] . "/$dist/$section")) mkdir ($dirs[sources_dir] . "/$dist/$section",0740);
373     if (!file_exists($localfile) OR md5_of_file($localfile)!=$sources_info[md5]) {
374     print "Downloading $remotefile Bytes $sources_info[bytes]=> ";
375     if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
376     print "Done\n";
377     if(md5_of_file($localfile)==$sources_info[md5]) print "MD5 => OK\n";
378 atomo64-guest 59 else print "MD5 => no match\n";
379 atomo64-guest 54 }
380     else {
381 atomo64-guest 59 unlink($localfile);
382 atomo64-guest 54 print "Fail\n";
383     die_status ("Error in source file");
384     }
385     }
386 evaso-guest 5 }
387 atomo64-guest 54 ftp_quit($conn_id);
388     }
389 evaso-guest 5 }
390     function md5_source($section,$dist) {
391 atomo64-guest 54 global $mirrors;
392 atomo64-guest 144 $release=file_get_contents ("ftp://$mirrors[$dist]" . remote_dist_dir($dist) . "/$dist/Release") or die_status("Failed to check MD5 of sources");
393     preg_match ("/\s([^\s]+)\s+(\d+)\s$section\/source\/Sources\.gz/i", $release,$matches);
394 atomo64-guest 54 return array("md5"=>$matches[1],"bytes"=>$matches[2]);
395     # 183dea9ca3c2e35ffd6cf5eee9501c21 2941637 main/binary-i386/Packages.gz
396 evaso-guest 5 }
397 atomo64-guest 54
398 atomo64-guest 118 function vers_conv($debvers, $extendedConv = true) {
399 atomo64-guest 54 // Strip off the epoch
400     $pos = strpos($debvers, ':');
401     if ( $pos !== FALSE) {
402     $debvers = substr($debvers, $pos+1);
403     }
404 evaso-guest 45
405 atomo64-guest 54 // strip off the Debian revision (look from the back of the string)
406     $pos = strrpos($debvers, '-');
407     if ( $pos !== FALSE) {
408     $debvers = substr($debvers, 0, $pos);
409     }
410 evaso-guest 45
411 atomo64-guest 116 if ($extendedConv) {
412     // strip off repacking indicators
413     $debvers = preg_replace("/[-.+~]?(ds|dfsg|debian)(.*)/i", "", $debvers);
414     }
415    
416 atomo64-guest 54 return $debvers;
417 evaso-guest 5 }
418     function check_db() {
419 atomo64-guest 54 global $dirs,$dbconn;
420 atomo64-guest 64 $db = pg_pconnect($dbconn) or die_status(1/*pg_last_notice($db)*/);
421 atomo64-guest 95 if (!pg_table_exists($db, "pkgs")) {
422 atomo64-guest 149 pg_exec($db, "CREATE TABLE pkgs (id serial PRIMARY KEY,name text,version text, dversionmangled text,maint text, uploaders text, dir text,watch text,md5_diff text,md5_atsource text,bytes numeric,dist text,section text,up_version text,up_changes text, up_url text,watch_warn text,updated bool, keep_changes bool, wwiz text,wwiz_version text, wwiz_type text, lastcheck timestamp, homepage text, vcs text, vcs_type text, vcs_browser text,vcs_watch text, vcsoversource bool,vcs_up_version text,vcs_dversionmangled text,vcs_up_url text, vcs_watch_warn text, vcs_updated bool, lastvcsfetch timestamp, lastupvsdebsync timestamp, lastpkgsourcesupdate timestamp, failures_count numeric, pop_inst numeric,pop_vote numeric)") or die_status('Error creating table pkgs\n');
423 atomo64-guest 54 pg_exec($db, "CREATE UNIQUE INDEX idxname on pkgs (name,dist)") or die_status('Errore creating index - ' . pg_last_error($db));
424 atomo64-guest 95 pg_exec($db, "CREATE INDEX checkx on pkgs (lastcheck)") or die_status('Errore creating index - ' . pg_last_error($db));
425 atomo64-guest 133 pg_exec($db, "CREATE INDEX updatex on pkgs (lastcheck,lastpkgsourcesupdate);") or die_status('Errore creating index - ' . pg_last_error($db));
426 atomo64-guest 122 pg_exec($db, "CREATE INDEX maintx on pkgs (maint)") or die_status('Errore creating index - ' . pg_last_error($db));
427 atomo64-guest 54 $sw=true;
428     }
429 atomo64-guest 95 if (!pg_table_exists($db, "binpkgs")) {
430 atomo64-guest 54 pg_exec($db, "CREATE TABLE binpkgs (id serial PRIMARY KEY, name text,bin_name text,dist text, pop_inst numeric,pop_vote numeric, up_error numeric,avg_error_date numeric)") or die_status('Error creating table binpkgs\n');
431     pg_exec($db, "CREATE UNIQUE INDEX idxbin on binpkgs (name,bin_name,dist)") or die_status('Errore creating index - ' . pg_last_error($db));
432     $sw=true;
433     }
434 atomo64-guest 95 if (!pg_table_exists($db, "events")) {
435 atomo64-guest 122 pg_exec($db, "CREATE TABLE events (id serial PRIMARY KEY, name text,type text, dist text, stamp timestamp, content text)") or die_status('Error creating table events\n');
436     pg_exec($db, "CREATE UNIQUE INDEX idxevents on events (name,dist,content)") or die_status('Error creating index - ' . pg_last_error($db));
437     pg_exec($db, "CREATE INDEX pkgxeventtype on events (name,type,dist)") or die_status('Error creating index - ' . pg_last_error($db));
438 atomo64-guest 78 $sw=true;
439 atomo64-guest 95 }
440 atomo64-guest 122 if (!pg_table_exists($db, "stamps")) {
441     pg_exec($db, "CREATE TABLE stamps (type text PRIMARY KEY, stamp timestamp, pid text)") or die_status('Error creating table stamps\n');
442     $sw=true;
443     }
444 atomo64-guest 54 #if (!pg_table_exists($db,"upstream")){
445     # pg_exec($db, "CREATE TABLE upstream (name text,dist text,up_version text,watch_warn text,updated bool)") or die_status('Errore nel creare la tabella');
446     # pg_exec($db, "CREATE UNIQUE INDEX idxupstrm on upstream (name,dist)") or die_status('Errore nel creare gli indici ' . pg_last_error($db));
447     # $sw=true;
448     #}
449     pg_close($db);
450     if($sw) return $sw;
451     else return false;
452 evaso-guest 5 }
453     function pg_table_exists (&$dblink, $table) {
454 atomo64-guest 54 $sql = "SELECT relname as tbl FROM pg_class WHERE relname = '$table'";
455     if ($res = pg_exec ($dblink, $sql)) {
456     return pg_numrows($res) > 0;
457     } else {
458     return false; // or throw exception
459     }
460     }
461 evaso-guest 5
462    
463     function watch_stat() {
464 atomo64-guest 54 global $dirs,$dbconn;
465 atomo64-guest 65 $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
466 atomo64-guest 54 $rsql=pg_exec ($db,"Select count(name) as totwatch FROM pkgs WHERE watch!=''");
467     $tot_watch=pg_fetch_array($rsql);
468     print "Total packages with Watch =>$tot_watch[0]\n";
469     $rsql=pg_exec ($db,"Select count(name) as totwatch FROM pkgs WHERE watch IS NULL");
470     $tot_nowatch=pg_fetch_array($rsql);
471     pg_close($db);
472     print "Totale packages without Watch => $tot_nowatch[0]\n";
473     print "Watch presence rate => " . number_format ($tot_watch[0]/($tot_nowatch[0]+$tot_watch[0])*100, 2, ",",".") . "%\n";
474 evaso-guest 5 }
475     function remote_dist_dir($dist) {
476 atomo64-guest 54 #if ($dist=="non-US") return "/debian-non-US/dists/unstable";
477     #else
478     return "/debian/dists";
479 evaso-guest 5 }
480 atomo64-guest 102 function clear_db(&$db) {
481 atomo64-guest 54 #global $dbconn;
482     #if (check_db()) die_status("Il Database era vuoto\n");
483 atomo64-guest 64 #download_sources();
484 atomo64-guest 54 #$db = pg_pconnect($dbconn) or die_status(pg_result_error($db));
485     $sql1= "Delete from binpkgs where id NOT IN
486 evaso-guest 5 (select id FROM binpkgs INNER JOIN bin_atsrc USING (name,bin_name,dist))" ;
487 atomo64-guest 54 $sql2= "Delete from pkgs where id NOT IN (select id FROM pkgs INNER JOIN pkgs_atsrc USING (name,dist))" ;
488 atomo64-guest 102 $sql3= "UPDATE pkgs SET wwiz=NULL, wwiz_type=NULL, wwiz_version=NULL WHERE watch IS NOT NULL and watch!=''" ;
489     $sql4= "UPDATE pkgs SET up_changes=NULL WHERE updated='1'";
490     if(pg_exec($db,$sql1) && pg_exec($db,$sql2) && pg_exec($db,$sql3) && pg_exec($db,$sql4)) {
491 atomo64-guest 85 print "Db clear complete\n";
492     }
493 evaso-guest 5 }
494 atomo64-guest 135 function db_popcon() {
495 atomo64-guest 54 global $dirs,$dbconn;
496 atomo64-guest 65 $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
497 atomo64-guest 135 $filename=$dirs['popcon_dir'] . "/popcon.db";
498     $popcon_db = dba_open($filename, 'r-', 'db4');
499 atomo64-guest 122
500 atomo64-guest 124 $rsql = pg_exec($db, "SELECT name FROM pkgs");
501 atomo64-guest 122
502     while ($res_array=pg_fetch_array($rsql)) {
503     $package = $res_array['name'];
504    
505 atomo64-guest 126 if (!dba_exists('si:' . $package, $popcon_db)) {
506 atomo64-guest 122 continue;
507 atomo64-guest 54 }
508 atomo64-guest 122
509 atomo64-guest 126 $inst = dba_fetch("si:$package", $popcon_db);
510     $vote = dba_fetch("sv:$package", $popcon_db);
511 atomo64-guest 122
512 atomo64-guest 135 // when one of the values is 'missing' set to -1 so the other value
513     // _is_ UPDATEd, but use -1 to catch those bugs
514 atomo64-guest 136 $inst = (is_numeric($inst))? $inst : -1;
515     $vote = (is_numeric($vote))? $vote : -1;
516 atomo64-guest 135
517 atomo64-guest 122 @pg_exec($db, "UPDATE pkgs SET pop_inst='$inst',pop_vote='$vote' WHERE name='$package'");
518 atomo64-guest 54 }
519 atomo64-guest 122
520     dba_close($popcon_db);
521 atomo64-guest 54 @pg_close($db);
522 evaso-guest 5 }
523 atomo64-guest 59 function dl_popcon() {
524 atomo64-guest 54 global $dirs,$dbconn;
525 atomo64-guest 122
526 atomo64-guest 135 $localtempdir=$dirs['popcon_dir'] . "/new";
527 atomo64-guest 131 dir_ctrl($localtempdir);
528    
529 atomo64-guest 135 $localfile=$dirs['popcon_dir'] . "/popcon.db";
530 atomo64-guest 122 $remotefile='http://qa.debian.org/data/popcon/popcon.db';
531    
532     $return = 0;
533 atomo64-guest 123 $output = null;
534 atomo64-guest 131 exec('cd ' . escapeshellarg($localtempdir) . ' && ' .
535 atomo64-guest 135 '/usr/bin/wget -qN ' . escapeshellarg($remotefile), $output, $return);
536 atomo64-guest 122
537     if ($return != 0) {
538     echo __FUNCTION__ . "wget exited with status $return!\n";
539     return false;
540     }
541    
542 atomo64-guest 131 return copy($localtempdir . '/popcon.db', $localfile);
543 evaso-guest 5 }
544 atomo64-guest 102 function is_updated ($up_vers,$debian_vers, $dversionAsIs = false) {
545 atomo64-guest 97 if ($up_vers=='') return 1;
546 atomo64-guest 102
547 atomo64-guest 116 $extendedConv = true;
548    
549 atomo64-guest 102 if ($up_vers === $debian_vers) $dversionAsIs = true;
550    
551 atomo64-guest 116 if (strpos(strtolower($up_vers), 'dfsg') !== false && strpos(strtolower($debian_vers), 'dfsg') !== false) {
552     $extendedConv = false;
553     }
554 atomo64-guest 102
555 geissert 185 passthru("dpkg --compare-versions -- ".escapeshellarg($up_vers)." le " . escapeshellarg($dversionAsIs?$debian_vers:vers_conv($debian_vers, $extendedConv)),$great);
556 atomo64-guest 116
557 atomo64-guest 97 return (int)!($great);
558 evaso-guest 17 }
559 atomo64-guest 99 function db_upstream($initial='%', $checkStamps = false, $limit = null) {
560     global $dirs, $dbconn, $minimumAge;
561    
562 atomo64-guest 54 check_db();
563 atomo64-guest 64 $db = pg_pconnect($dbconn) ;
564 atomo64-guest 95 events::DB($db);
565 atomo64-guest 99
566     $postWHERE = '';
567     if ($checkStamps) {
568 atomo64-guest 167 $postWHERE = "AND (lastcheck<='".sqldate(time() - ($minimumAge*24*3600))."' OR lastcheck IS NULL OR (lastpkgsourcesupdate>lastcheck))";
569 atomo64-guest 99 }
570    
571     $postORDER = '';
572     if ($limit !== null && is_int($limit)) {
573     $postORDER = 'LIMIT ' . $limit;
574     }
575    
576 atomo64-guest 149 $rsql=pg_exec($db, "SELECT id, name,dist,up_version,version,watch,lastupvsdebsync,failures_count FROM pkgs WHERE watch is not null AND name LIKE '$initial' $postWHERE ORDER BY lastcheck DESC $postORDER");
577 atomo64-guest 54 $tot=pg_numrows($rsql);
578 atomo64-guest 99
579 atomo64-guest 54 while ($res_array=pg_fetch_array($rsql)) {
580 atomo64-guest 95
581 atomo64-guest 54 $uscan_res=uscan_foo($res_array['name'],$res_array['version'],$res_array['watch']);
582 atomo64-guest 95
583 atomo64-guest 121 #print $uscan_res['uversion'] . "\n Name => $res_array[name]\n";
584 atomo64-guest 95 $version = $res_array['version'];
585     $dversionmangled = $res_array['version'];
586     $lastupvsdebsync = $res_array['lastupvsdebsync'];
587 atomo64-guest 110 $mangle = true;
588 atomo64-guest 95
589 atomo64-guest 149 /* Do not increase the number of failures if uscan didn't throw any warning
590     because it might be that the watch file is "empty"
591     */
592     if (!$uscan_res['uversion'] && $uscan_res['warnings']) {
593     $res_array['failures_count']++;
594     } else {
595     $res_array['failures_count'] = 0;
596     }
597    
598 atomo64-guest 121 print "\rVersion=>" . $uscan_res['dversion'];
599     if ($uscan_res['dversion']!=null) $version=$uscan_res['dversion'];
600     if ($uscan_res['dversionmangled']!=null && $uscan_res['dversionmangled'] != vers_conv($res_array['version'])) {
601     $dversionmangled=$uscan_res['dversionmangled'];
602 atomo64-guest 110 $mangle = false;
603     }
604 atomo64-guest 95
605 atomo64-guest 121 $up_url=iconv("ISO-8859-1","UTF-8",$uscan_res['uurl']);
606     $up_version=iconv("ISO-8859-1","UTF-8",$uscan_res['uversion']);
607 atomo64-guest 116
608 atomo64-guest 121 $updated = $uscan_res['updated'];
609 atomo64-guest 95
610     /*if (!$updated)*/ {
611 atomo64-guest 121 $updated=is_updated($uscan_res['uversion'], $dversionmangled, !$mangle);
612 atomo64-guest 76 }
613    
614 atomo64-guest 70 if (!$updated) {
615 atomo64-guest 149 events::newVersion($res_array['name'], $res_array['version'], $up_version, $res_array['dist'], $up_url);
616 atomo64-guest 95 } else {
617     $lastupvsdebsync = sqldate();
618 atomo64-guest 70 }
619    
620 atomo64-guest 107 if ($lastupvsdebsync === null) {
621     $lastupvsdebsync = sqldate(0);
622     }
623    
624 atomo64-guest 149 $keep_changes = (int) ($up_version != $res_array['up_version']);
625 atomo64-guest 95
626 atomo64-guest 66 $watch_warn='';
627 atomo64-guest 121 if($uscan_res['warnings'] != null) {
628     $watch_warn=pg_escape_string(iconv("ISO-8859-1","UTF-8", $uscan_res['warnings']));
629 atomo64-guest 66 }
630 atomo64-guest 95
631 atomo64-guest 149 pg_exec($db, "UPDATE pkgs SET
632     up_version='" . pg_escape_string($up_version) . "',
633     dversionmangled='".pg_escape_string($dversionmangled)."',
634     up_url='" . pg_escape_string($up_url) . "',
635     watch_warn='" . $watch_warn . "',
636     keep_changes='$keep_changes',
637     wwiz_version=NULL,
638     wwiz_type=NULL,
639     wwiz=NULL,
640     failures_count=$res_array[failures_count],
641     updated='$updated',
642     lastcheck=now(),
643     lastupvsdebsync='$lastupvsdebsync'
644     WHERE id=$res_array[id]") or die_status("Error in update pkgs upstream");
645    
646 atomo64-guest 121 #print "\rUpdated " . $res_array['name'] . " => $updated Up Version => ". $uscan_res['uversion'];
647 atomo64-guest 78 print "\t Upstream left => " . $tot --;
648 atomo64-guest 54 # }
649     # else print "Added ". $res_array['name'] ."\n";
650     # if ($great==0) {
651    
652     # print "Package=> " . $res_array['name'] . "\n";
653     # print "Version => " . $res_array['version'] . "\n";
654 atomo64-guest 121 # print "Upstream Ver=> " . $uscan_res['uversion'] . "\n";
655     #print "Watch warings=> " . $uscan_res['warnings'] . "\n";
656 atomo64-guest 54 # }
657     }
658     print "\n";
659     pg_close($db);
660 evaso-guest 5 }
661 evaso-guest 20 function check_url ($url) {
662 atomo64-guest 54 $url_p = parse_url ($url);
663     if (isset ($url_p["host"])) $host = $url_p["host"];
664     else return false;
665     preg_match("/(http|ftp)/",$host,$matches);
666     if ($matches[1]=='http') $fp = fsockopen ($host, 80, $errno, $errstr, 5);
667     elseif ($matches[1]=='ftp') $fp2 = fsockopen ($host, 21, $errno, $errstr, 5);
668     if (!$fp AND !$fp2) return false;
669     else return true;
670 evaso-guest 20 }
671 evaso-guest 17 function keep_remote ($localfile,$remotefile) {
672 atomo64-guest 54 if (!check_url($remotefile)) return false;
673     # $rfp = @fopen ($remotefile, "r");
674     # if (!$rfp) {
675     # return false;
676     # }
677     # fclose($rfp);
678     # $lfp = fopen ($localfile, "w");
679     # stream_set_blocking($rfp,0);
680     # ini_set ( "memory_limit", "100M");
681     # while (!feof($rfp)) {
682     # $data = fread($rfp, 8192);
683     # $bytes+=8192;
684     # print "Downlaoding $remotefile: $bytes\r";
685     # fwrite($lfp, $data);
686     # } while (true);
687     # ini_set ( "memory_limit", "15M");
688    
689     if (!copy($remotefile, $localfile)) {
690     echo "Copia di $file non riuscita ...\n";
691     return false;
692     }
693     # fclose($lfp);
694     # fclose($rfp);
695    
696     return true;
697 evaso-guest 44 }
698 atomo64-guest 59 function up_changes($src_name='%', $force = false) {
699     global $dbconn, $fetchUpstreamChanges;
700    
701     if (!$fetchUpstreamChanges && !$force) {
702 atomo64-guest 95 //print "\nSkipping download of upstream sources to grab changelogs\n";
703 atomo64-guest 59 return;
704     }
705    
706 atomo64-guest 54 $changes_files=array("CHANGES","NEWS","Changelog","ChangeLog","changelog");
707 evaso-guest 44 $db = pg_pconnect($dbconn) ;
708 atomo64-guest 85 $rsql=pg_exec($db, "SELECT id,up_url FROM pkgs WHERE up_url!='' AND keep_changes='t' AND name LIKE '$src_name'");
709 atomo64-guest 54 $tot=pg_numrows($rsql);
710     while ($res_array=pg_fetch_array($rsql)) {
711     $localfile=tempnam("/tmp/", "dehs-" . $res_array[id] . ".tar.gz");
712     print "I'm downloading $res_array[up_url]\r";
713     $res=keep_remote($localfile,$res_array['up_url']);
714     print "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]";
715     if (!$res) {
716     pg_exec($db, "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]");
717     $notdown++;
718     $tot--;
719     print "Packages Left: " . $tot-- . " Found: $found Not found: $notfound Not Down: $notdown\r";
720     #print "\n Not Downlaoded: $res_array[up_url]\n";
721     unlink($localfile);
722     continue;
723     }
724     foreach($changes_files as $filename) {
725 atomo64-guest 59 $command="tar --wildcards -zxOf " . $localfile . " *$filename 2>/dev/null";
726 atomo64-guest 54 exec($command,$up_changes,$cmdres);
727     $up_changes=rtrim(implode("\n",$up_changes));
728     if ($cmdres==0 AND strlen($up_changes)>20) {
729     $sw=true;
730     $conv_res=iconv("ISO-8859-1","UTF-8",$up_changes);
731     if ($conv_res) $up_changes=$conv_res;
732 atomo64-guest 66 $up_changes=pg_escape_string($up_changes);
733 atomo64-guest 54 $up_changes_sql="UPDATE pkgs SET up_changes='$up_changes', keep_changes='f' WHERE id=$res_array[id]";
734     pg_exec($db,$up_changes_sql);
735     #print "\nFound $filename on $res_array[up_url]\n";
736     $found++;
737     break;
738     }
739     }
740     if (!$sw) {
741     pg_exec($db, "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]");
742     #print "\n Not Found any on $res_array[up_url]\n";
743     $notfound++;
744     }
745     unlink($localfile);
746     print "Packages Left: " . $tot-- . " Found: $found Not found: $notfound Not Down: $notdown\r";
747     }
748     pg_close($db);
749 evaso-guest 17 }
750 evaso-guest 5 function uscan_foo($name,$version,$watch){
751 atomo64-guest 46 global $base, $uscan;
752 atomo64-guest 54
753 evaso-guest 43 $tmpnam=tempnam('/tmp/', $name.'_watch');
754 evaso-guest 42 $fw=fopen($tmpnam,"w");
755 atomo64-guest 54 fwrite($fw,$watch);
756     fclose($fw);
757    
758     $uscan_res=shell_exec("$uscan --dehs --package $name --upstream-version " . escapeshellarg(vers_conv($version)) . " --watchfile $tmpnam 2>/dev/null 2>&1");
759    
760 evaso-guest 43 unlink($tmpnam);
761 atomo64-guest 54
762     $p = xml_parser_create();
763     xml_parse_into_struct($p, $uscan_res, $vals, $index);
764     xml_parser_free($p);
765    
766 geissert 187 list($upstream)=explode("\n", $vals[$index['UPSTREAM-VERSION'][0]][value]);
767     list($up_url)=explode("\n", $vals[$index['UPSTREAM-URL'][0]][value]);
768 atomo64-guest 54 $deb_vers=$vals[$index['DEBIAN-UVERSION'][0]][value];
769 atomo64-guest 73 $deb_mangled_vers=$vals[$index['DEBIAN-MANGLED-UVERSION'][0]][value];
770 atomo64-guest 54 $warnings=$vals[$index['WARNINGS'][0]][value];
771     $updated=$vals[$index['STATUS'][0]][value];
772    
773 atomo64-guest 95 if ($updated=="up to date") $updated=1;
774     else $updated=0;
775 atomo64-guest 54
776     if ($upstream=='') $upstream=null;
777     if ($up_url=='') $up_url=null;
778     if ($deb_vers=='') $deb_vers=null;
779     if ($warnings=='') $warnings=null;
780 atomo64-guest 73 if ($deb_mangled_vers=='') $deb_mangled_vers=null;
781 atomo64-guest 54
782 atomo64-guest 121 $ret = array();
783     $ret['uversion'] = $upstream;
784     $ret['warnings'] = $warnings;
785     $ret['uurl'] = $up_url;
786     $ret['dversion'] = $deb_vers;
787     $ret['dversionmangled'] = $deb_mangled_vers;
788     $ret['updated'] = $updated;
789    
790     return $ret;
791 atomo64-guest 54 }
792 evaso-guest 5 function db_up_error() {
793     global $dbconn;
794 atomo64-guest 54 check_db();
795 atomo64-guest 64 $db = pg_pconnect($dbconn) ;
796 atomo64-guest 54 $bugurl="http://bugs.debian.org/cgi-bin/pkgreport.cgi?which=tag&data=upstream&archive=no&show_list_header=no&pend-exc=done";
797 atomo64-guest 59 print "\nDownloading bugs list =>";
798 atomo64-guest 133 if (!($ferrors=file_get_contents($bugurl))) {
799     /*die_status ("I can't keep error page from bugs.debian.org");*/
800     fwrite(STDERR, "I can't keep error page from bugs.debian.org, but not aborting");
801     return false;
802     }
803 atomo64-guest 54 print "Done\n";
804     $ferrors=explode("<li>",$ferrors);
805     $totline=count($ferrors);
806     #$errors[]=array();
807     #array_pop($errors);
808 atomo64-guest 59 print "Total lines => $totline\n";
809 atomo64-guest 54 foreach ($ferrors as $line) {
810     # print $line . "\n";
811 atomo64-guest 150 if (preg_match("/Package:.+?>([^<]+)<\/a>.+?<strong>((\d+)\syears?\sand\s|)(\d+)\sdays?/sS",$line,$matches)) {
812 atomo64-guest 54 $errors[$matches[1]][err_tot]++;
813     $errors[$matches[1]][days]+=$matches[3]*365+$matches[4];
814     #if ($matches[3]) print "Anni $matches[3]";
815     #print "Giorni $matches[4]\n";
816     }
817 atomo64-guest 59 print "\rLines left => " . $totline--;
818 atomo64-guest 54 }
819     #arsort($errors);
820     $total=count($errors);
821 atomo64-guest 59 foreach ($errors as $pkg_name=>$value) {
822     pg_exec($db, "UPDATE binpkgs SET up_error=" . $value[err_tot] . ",avg_error_date=" . $value[days]/$value[err_tot] . " WHERE bin_name='$pkg_name'") or die_status("Error in upstream bug query");
823 atomo64-guest 54 #print "Pkg: $error Errori: $value[err_tot] Average Days: " . $value[days]/$value[err_tot] . "\n";
824 atomo64-guest 59 print "\rBugs left => " . $total--;
825 atomo64-guest 54 }
826     pg_close($db);
827 evaso-guest 5 }
828 atomo64-guest 99 function watch_wizard($src_name='%', $checkStamps = false, $limit = null){
829     global $dirs,$dbconn,$sfIgnore,$watchFileExts,$watchFileDversionMangle,$watchFormat,$minimumAge;
830 atomo64-guest 54 $db = pg_pconnect($dbconn) or die_status ("Db error");
831     $checked=$errors=$notfound=$verok=$notmatch=0;
832    
833 atomo64-guest 62 // prepare some stuff that needs to be done once per run
834 atomo64-guest 73 $opts = array();
835     $exts = '';
836     $dvmanglers = '';
837 atomo64-guest 62
838     foreach ($watchFileExts as $ext) {
839     $exts .= $ext . '|';
840     }
841     unset($ext);
842    
843 atomo64-guest 73 if ($exts != '') {
844     $opts[] = 'uversionmangle=s/\.(' . substr($exts, 0, -1) . ')$//i';
845 atomo64-guest 84 $exts = '(' . $exts . ')';
846 atomo64-guest 62 }
847    
848 atomo64-guest 73 foreach ($watchFileDversionMangle as $dvmangler) {
849     $dvmanglers .= $dvmangler . '|';
850     }
851     unset($dvmangler);
852    
853     if ($dvmanglers != '') {
854     $opts[] = 'dversionmangle=s/[-.+~]?(' . substr($dvmanglers, 0, -1) . ')(.*)$//i';
855     }
856    
857 atomo64-guest 84 $opts[] = 'pasv';
858    
859 atomo64-guest 73 if (is_array($opts)) {
860     $_opts = '';
861     foreach ($opts as $opt) {
862     $_opts .= $opt . ',';
863     }
864     $opts = '';
865     if ($_opts != ',') {
866     $opts = 'opts=' . substr($_opts, 0, -1) . ' \\';
867     }
868     }
869    
870 atomo64-guest 99 $postWHERE = '';
871     if ($checkStamps) {
872 atomo64-guest 121 $postWHERE = "AND (lastcheck<='".sqldate(time() - ($minimumAge*24*3600))."' OR lastcheck IS NULL)"
873 atomo64-guest 122 . " AND wwiz_type!='no_cright' AND wwiz_type!='notmatch'";
874 atomo64-guest 99 }
875    
876     $postORDER = '';
877     if ($limit !== null && is_int($limit)) {
878     $postORDER = 'LIMIT ' . $limit;
879     }
880    
881 atomo64-guest 122 $sqlstring="SELECT name,version,dversionmangled,section,dist, wwiz_version FROM pkgs
882 atomo64-guest 99 WHERE (watch IS NULL OR watch='') AND name LIKE '$src_name' $postWHERE ORDER BY lastcheck DESC $postORDER";
883 atomo64-guest 71 $rsql=pg_exec($db, $sqlstring);
884    
885 atomo64-guest 54 while ($res_array=pg_fetch_array($rsql)) {
886    
887     if (substr($res_array["name"],0,3)=='lib')
888     $initial=substr($res_array["name"],0,4);
889     else
890     $initial=substr($res_array["name"],0,1);
891    
892     $url="http://packages.debian.org/changelogs/pool/" .
893     $res_array["section"] . "/" .
894     $initial . "/" .
895     $res_array["name"] ."/" .
896     $res_array["name"] . "_" .
897     $res_array["version"] . "/copyright";
898     $contents=@file_get_contents($url) or '';
899     $generatedWatches = array();
900    
901     if (!$contents) {
902     $url="http://packages.debian.org/changelogs/pool/" .
903     $res_array["section"] . "/" .
904     $initial . "/" .
905     $res_array["name"] ."/" .
906     $res_array["name"] . "_" .
907     $res_array["version"] . "/" . $res_array["name"] . ".copyright";
908     $contents=@file_get_contents($url) or '';
909     }
910    
911 atomo64-guest 73 if (!$contents) {
912     $url="http://packages.debian.org/changelogs/pool/" .
913     $res_array["section"] . "/" .
914     $initial . "/" .
915     $res_array["name"] ."/" .
916     "current/copyright";
917     $contents=@file_get_contents($url) or '';
918     }
919    
920 atomo64-guest 54 if ($contents) {
921    
922     if (preg_match ('/(sf\.net|sourceforge\.net)/i', $contents, $matches) ||
923     (preg_match ('/([\w\-]+)\.(sf\.net|sourceforge\.net)/i', $contents, $matches)
924     && !in_array($matches[1], $sfIgnore))) {
925     preg_match("/([^\d]+)/",$res_array['name'],$dmatches);
926     $depured_debian_name=$dmatches[1];
927     /*$matches[1]="ftp://download.sf.net/pub/sourceforge/" . substr($depured_debian_name,0,1) . "/" . substr($depured_debian_name,0,2) . "/" . $depured_debian_name . "/";*/
928 atomo64-guest 62 $generatedWatches[]=array('url'=>"http://sf.net/" . $depured_debian_name . "/");
929 atomo64-guest 54 $generatedWatches[]=array('url'=>"http://sf.net/" . $depured_debian_name . "/",'name'=>$depured_debian_name);
930    
931     }
932    
933 atomo64-guest 67 if (preg_match ('#((ftp://|http://|https://)\S+(html|htm|/(?(?=.+(tar|tgz|zip|gz|bz2))|[^>\s\)\a]+)))#i',$contents,$matches)) {
934 atomo64-guest 54 $final=substr($matches[1],-1);
935     if ($final=='.') {
936     $matches[1]=substr($matches[1],0,-1);
937     $final=substr($matches[1],-1);
938     }
939 atomo64-guest 58 if ($matches[2]=="http://" || $matches[2]=="https://") {
940 atomo64-guest 54 $space=' ' . "(?:.*/)?";
941     } elseif ($final!='/') {
942     $matches[1].='/';
943     }
944 atomo64-guest 59 $generatedWatches[]=array('url' => preg_replace("#((http|https|ftp)://.+):(.*)#i",'$1' . '$3', $matches[1],1), 'space' => $space);
945 atomo64-guest 54 }
946    
947 atomo64-guest 67 if (preg_match ('#((ftp|http)\.\S+(html|htm|/(?(?=.+(tar|tgz|zip|gz|bz2))|[^>\s\)\a]+)))#i',$contents,$matches)) {
948 atomo64-guest 54 $final=substr($matches[1],-1);
949     if ($final=='.') {
950     $matches[1]=substr($matches[1],0,-1);
951     $final=substr($matches[1],-1);
952     }
953     $space = '';
954     if ($matches[2]=="http") {
955     $space=' ' . "(?:.*/)?";
956     } elseif ($final!='/') {
957     $matches[1].='/';
958     }
959 atomo64-guest 59 $generatedWatches[]=array('url'=>preg_replace('#(http|ftp)\.(.+)#i','$1://$0', $matches[1],1), 'space'=>$space);
960 atomo64-guest 54 }
961    
962     if (empty($generatedWatches)) {
963     $notmatch++;
964     $contents=iconv("ISO-8859-1","UTF-8",$contents);
965 atomo64-guest 121 pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz='" . pg_escape_string($contents) . "', wwiz_type='notmatch', up_url='', up_changes='', lastcheck=now(), keep_changes='f' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
966 atomo64-guest 54
967     } else {
968    
969 atomo64-guest 56 $defs = array('name' => $res_array['name'], 'url' => '', 'space' => '');
970 atomo64-guest 54
971     foreach ($generatedWatches as $tWatch) {
972    
973 atomo64-guest 59 if (!is_array($tWatch)) {
974     $tWatch = array($tWatch);
975     }
976    
977 atomo64-guest 54 $tWatch = array_merge($defs, $tWatch);
978    
979 atomo64-guest 62 $watch = sprintf($watchFormat, $tWatch['url'], $tWatch['space'], $tWatch['name'], $exts, $opts);
980 atomo64-guest 54
981 atomo64-guest 62 $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$watch);
982 atomo64-guest 54
983 atomo64-guest 121 if ($uscan_res['uversion'] && levenshtein($uscan_res['uversion'], $res_array['version']) < strlen($res_array['version'])) {
984 atomo64-guest 71 break;
985 atomo64-guest 54 }
986     }
987    
988 atomo64-guest 121 if ($uscan_res['warnings'] && !$uscan_res['uversion']) {
989     pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz='" . pg_escape_string($uscan_res['warnings']) . "', wwiz_type='error', up_url='', up_changes='', lastcheck=now(), keep_changes='f' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
990 atomo64-guest 54 $errors++;
991     } else {
992     $verok++;
993 atomo64-guest 121 if ($uscan_res['uversion'] != $res_array['wwiz_version']) {
994 atomo64-guest 54 $keep_changes = 1;
995     } else {
996     $keep_changes = 0;
997     }
998 atomo64-guest 76
999     $dversionmangled = $res_array[version];
1000 atomo64-guest 121 if ($uscan_res['dversionmangled']!=null && $uscan_res['dversionmangled'] != vers_conv($res_array['version'])) $dversionmangled=$uscan_res['dversionmangled'];
1001 atomo64-guest 76
1002 atomo64-guest 121 $updated = $uscan_res['updated'];
1003 atomo64-guest 95 /*if ($updated)*/ {
1004 atomo64-guest 121 $updated = is_updated($uscan_res['uversion'], $dversionmangled, $dversionmangled != $uscan_res['dversionmangled']);
1005 atomo64-guest 76 }
1006 atomo64-guest 70
1007 atomo64-guest 78 /*if (!$updated) {
1008 atomo64-guest 121 events::newVersion($res_array['name'], $res_array['version'], $uscan_res['uversion'], $res_array['dist']);
1009 atomo64-guest 78 }*/
1010 atomo64-guest 70
1011 atomo64-guest 121 pg_exec($db, "UPDATE pkgs SET wwiz='" . pg_escape_string($watch) ."', wwiz_type='watch', wwiz_version='" . pg_escape_string($uscan_res['uversion']) . "',dversionmangled='".pg_escape_string($dversionmangled)."', up_url='" . pg_escape_string($uscan_res['uurl']) . "', keep_changes='$keep_changes', updated='$updated', lastcheck=now() where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
1012 atomo64-guest 54 }
1013     }
1014     } else {
1015     $notfound++;
1016     pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz_type='no_cright' where name='" . pg_escape_string($res_array['name']) . "' AND dist='" . $res_array['dist'] ."'");
1017     }
1018     print "Package checked: " . $checked++ .
1019     " OK: $verok Error: $errors Not Matched: $notmatch\r";
1020     }
1021     print "\nCopyright files not found: $notfound\n";
1022 atomo64-guest 59 print "Automatic generated watch file failures: $errors\n";
1023 atomo64-guest 54 pg_close($db);
1024 evaso-guest 13 }
1025 evaso-guest 26 function dbqa_conn ($dbname,$mode) {
1026 atomo64-guest 54 $id = dba_open($dbname, $mode, "db4");
1027     if (!$id) {
1028     die_status("dba_open failed\n");
1029     }
1030     return $id;
1031 evaso-guest 26 }
1032     function dehsqa_db () {
1033 atomo64-guest 54 global $dirs,$dbconn;
1034     $dir1='/org/alioth.debian.org/chroot/home/groups/dehs/htdocs/';
1035     $dir2="/org/qa.debian.org/data/dehs/";
1036     $dists=array("unstable","experimental");
1037     foreach ($dists as $dist) {
1038     $id=dbqa_conn($dir1 . "dehs_qa_" . $dist . ".db",'n');
1039     $db = pg_pconnect($dbconn) or die_status ("Db error");
1040 atomo64-guest 106 $sql="SELECT name, id, up_version, wwiz_version, watch, wwiz_type, watch_warn, version, dversionmangled, updated FROM pkgs WHERE dist='$dist'";
1041 atomo64-guest 54 $rsql=pg_exec($db, $sql);
1042     while($res_array=pg_fetch_array($rsql)) {
1043    
1044 atomo64-guest 63 if (!$res_array[watch]) { if ($res_array['wwiz_type']==null) $version="N/A"; else $version='-';}
1045 atomo64-guest 54 elseif (!$res_array[up_version]) $version="Error";
1046     else $version=$res_array[up_version];
1047    
1048     if ($res_array['wwiz_type']=="watch") $wwiz=$res_array['wwiz_version'];
1049     else $wwiz=$res_array[wwiz_type];
1050    
1051 atomo64-guest 155 // the updated flag is set to true even when up_version could not be determined
1052     $updated = ($res_array['updated'] && ($res_array[up_version] || $res_array[wwiz_version]))? 'yes' : 'no';
1053 atomo64-guest 106
1054 atomo64-guest 54 $xml="<data><id>$res_array[id]</id>" .
1055     "<up_version>$version</up_version>" .
1056 atomo64-guest 73 "<dversion>$res_array[version]</dversion>" .
1057     "<dversionmangled>$res_array[dversionmangled]</dversionmangled>" .
1058 atomo64-guest 155 "<uptodate>$updated</uptodate>" .
1059 atomo64-guest 54 "<wwiz>$wwiz</wwiz>" .
1060     "</data>";
1061     $value=addslashes($xml);
1062     dba_replace($res_array[name],$xml,$id);
1063     }
1064     dba_optimize($id);
1065     dba_close($id);
1066     pg_close($db);
1067     }
1068 evaso-guest 26 }
1069     function md5_of_file($inFile) {
1070 atomo64-guest 54 if (file_exists($inFile)) {
1071     return md5_file($inFile);
1072     } else {
1073     return false;
1074     }
1075 evaso-guest 26 }
1076 evaso-guest 5 function update_all() {
1077 atomo64-guest 111 global $email, $timeStamp_basedCheck;
1078 atomo64-guest 54 $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1079 atomo64-guest 85 echo __FUNCTION__ . ' started the ' . $intime . "\n";
1080 atomo64-guest 54 db_add();
1081 atomo64-guest 59 dl_diffs();
1082 atomo64-guest 144 dl_from_vcs('%','%',in_array('vcs',$timeStamp_basedCheck));
1083 atomo64-guest 54 db_up_error();
1084 atomo64-guest 99 db_upstream('%', in_array('all', $timeStamp_basedCheck));
1085     watch_wizard('%', in_array('all', $timeStamp_basedCheck));
1086 atomo64-guest 54 up_changes();
1087     dehsqa_db();
1088     $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1089     $messaggio="Dehs executed successful\nBegin: $intime\nEnd: $endtime";
1090     mail($email, "DEHS report", $messaggio,
1091 atomo64-guest 162 "From: dehs-noreply@{$_SERVER['SERVER_NAME']}");
1092 evaso-guest 5 }
1093 atomo64-guest 64 function update_new() {
1094 atomo64-guest 144 global $email_all, $timeStamp_basedCheck;
1095 atomo64-guest 64 $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1096 atomo64-guest 85 echo __FUNCTION__ . ' started the ' . $intime . "\n";
1097 atomo64-guest 102 db_add();
1098 atomo64-guest 64
1099     global $dbconn;
1100     check_db();
1101     $db = pg_pconnect($dbconn);
1102 atomo64-guest 133 $sql = "SELECT name FROM pkgs WHERE"
1103     ." (md5_diff!=md5_atsource or md5_diff is null)"
1104     ." or (lastcheck is null and watch is not null)"
1105 atomo64-guest 134 ." or (lastpkgsourcesupdate>lastcheck)";
1106 atomo64-guest 64 $rsql=pg_exec($db, $sql);
1107     $res_array=pg_fetch_all($rsql);
1108     pg_close($db);
1109    
1110     dl_diffs();
1111     db_up_error();
1112     if ($res_array !== false) {
1113     foreach ($res_array as $entry) {
1114 atomo64-guest 144 dl_from_vcs($entry['name'],'%',in_array('vcs',$timeStamp_basedCheck));
1115 atomo64-guest 64 db_upstream($entry['name']);
1116     up_changes($entry['name']);
1117 atomo64-guest 69 watch_wizard($entry['name']);
1118 atomo64-guest 64 }
1119     dehsqa_db();
1120     }
1121     $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1122     $messaggio="Dehs executed successful\nBegin: $intime\nPackages processed: ".((!is_array($res_array))?'none':count($res_array))."\nEnd: $endtime";
1123     mail($email_all, "DEHS update_new report", $messaggio,
1124 atomo64-guest 162 "From: dehs-noreply@{$_SERVER['SERVER_NAME']}");
1125 atomo64-guest 64 }
1126 atomo64-guest 65 function update_bogus() {
1127 atomo64-guest 66 global $email_all,$dbconn;
1128 atomo64-guest 65 $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1129 atomo64-guest 85 echo __FUNCTION__ . ' started the ' . $intime . "\n";
1130 atomo64-guest 65 check_db();
1131     $db = pg_pconnect($dbconn);
1132     $sql="SELECT name FROM pkgs WHERE up_version='' AND watch!=''";
1133     $rsql=pg_exec($db, $sql);
1134     $res_array=pg_fetch_all($rsql);
1135 atomo64-guest 77 $orig_count = ((!is_array($res_array))?0:count($res_array));
1136 atomo64-guest 65 if ($res_array !== false) {
1137     foreach ($res_array as $entry) {
1138     db_upstream($entry['name']);
1139     up_changes($entry['name']);
1140     }
1141     dehsqa_db();
1142     }
1143 atomo64-guest 77 $sql="SELECT COUNT(name) FROM pkgs WHERE up_version='' AND watch!=''";
1144     $rsql=pg_exec($db, $sql);
1145     $res_array=pg_fetch_array($rsql);
1146     $new_count = (int)$res_array[0];
1147     pg_close($db);
1148 atomo64-guest 65 $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
1149 atomo64-guest 77 $messaggio="Dehs executed successful\nBegin: $intime\n".
1150     "Packages processed: $orig_count\n" .
1151     "New bogus watches count: $new_count\nEnd: $endtime";
1152 atomo64-guest 65 mail($email_all, "DEHS update_bogus report", $messaggio,
1153 atomo64-guest 162 "From: dehs-noreply@{$_SERVER['SERVER_NAME']}");
1154 atomo64-guest 65 }
1155 atomo64-guest 49 function die_status($msg = '', $status = 1) {
1156 atomo64-guest 54 if (empty($msg)) {
1157     die($status);
1158     } else if (is_int($msg) && $status == 1 /* default */) {
1159     die($msg);
1160     } else {
1161 atomo64-guest 113 fwrite(STDERR, $msg);
1162 atomo64-guest 54 die($status);
1163     }
1164 atomo64-guest 49 }
1165 atomo64-guest 70
1166 atomo64-guest 95 function sqldate($timestamp=null) {
1167     if ($timestamp===null) $timestamp=time();
1168     return gmdate("Y-m-d H:i:s", $timestamp);
1169     }
1170    
1171 atomo64-guest 149 function dl_from_vcs($package = '%', $dist = '%', $checkStamps = false, $db = null) {
1172 atomo64-guest 144 global $minimumVCSAge;
1173     $local_db = false;
1174    
1175     if (!$fetchWatchFromVCS) {
1176     return false;
1177     }
1178    
1179     if ($db === null) {
1180     $local_db = true;
1181     $db = pg_pconnect($dbconn) or die_status(pg_last_error($db));
1182     }
1183    
1184 atomo64-guest 149 $sql="SELECT name,dist,vcs_type,vcs FROM pkgs WHERE name LIKE '$package' AND "
1185     . "dist LIKE '$dist' AND vcs!='' AND vcs IS NOT NULL AND vcs_type!='' AND vcs_type IS NOT NULL "
1186 atomo64-guest 144 . ($checkStamps? "AND (lastvcsfetch IS NULL OR lastvcsfetch <='"
1187     . (sqldate(time() - ($minimumVCSAge*24*3600)))."') "
1188     : '');
1189     $rsql=pg_exec($db, $sql);
1190     while ($res = pg_fetch_array($rsql)) {
1191     // avoid miss-parsed entries:
1192     if ( count(explode('\n',$res['vcs_type'])) > 1
1193     || count(explode('\n',$res['vcs'])) > 1)
1194     continue;
1195    
1196 atomo64-guest 149 print "Fetching watch file of $res[name] (type: $res[vcs_type]) from $[vcs]\n";
1197    
1198 atomo64-guest 144 $tmp_dir = shell_exec('mktemp -d') or die_status("mktemp failed to create directory!");
1199     $vcs_watch = null;
1200     if (exec('debcheckout.pl -t ' . escapeshellarg($res['vcs_type'])
1201     . ' -f debian/watch '
1202     . escapeshellarg($res['vcs'])
1203     . ' ' . escapeshellarg($tmp_dir))) {
1204     $vcs_watch = implode('\n', file($tmp_dir . '/debian/watch'));
1205     }
1206    
1207     shell_exec('rm -rf ' . escapeshellarg($tmp_dir));
1208    
1209     $dehs_opts = array();
1210     $dehs_opts['vcs'] = 0;
1211    
1212     if (preg_match('/#\s*DEHS\s*:\s*([\w\s,]+)/i', $vcs_watch, $matches)) {
1213     $_dehs_opts = array_map('trim',explode(',', $matches[1]));
1214     switch ($_dehs_opts) {
1215     case 'vcs':
1216     $dehs_opts['vcs'] = 1;
1217     break;
1218     case 'novcs':
1219     $dehs_opts['vcs'] = 0;
1220     break;
1221     }
1222     }
1223    
1224     if ($vcs_watch != null) {
1225     $vcs_watch = iconv('ISO-8859-1', 'UTF-8', $vcs_watch);
1226     $vcs_watch = pg_escape_string($vcs_watch);
1227     }
1228    
1229     pg_exec($db, "UPDATE pkgs SET vcs_watch='" . $vcs_watch . "', lastvcsfetch = now(), vcsoversource='$dehs_opts[vcs]' WHERE name='$res[name]' AND dist='$res[dist]'") or die_status("Query error");
1230     }
1231    
1232     if ($local_db) pg_close($db);
1233     return true;
1234     }
1235    
1236 atomo64-guest 46 ?>

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5