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

Contents of /trunk/dehs_pg.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations) (download)
Sat Dec 8 23:42:12 2007 UTC (5 years, 6 months ago) by atomo64-guest
File size: 40445 byte(s)
All db connections are persistent now
Added update_new command which is a 'minimal' run
Maintainer field is now also converted to utf-8
1 evaso-guest 5 #!/usr/bin/php4 -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 64 Copyright 2007 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 evaso-guest 34 ini_set ( "memory_limit", "40M");
29 evaso-guest 13 #print_R($_SERVER);
30     require "dehs.config.inc";
31 evaso-guest 5 dir_ctrl($dirs);
32 evaso-guest 13 if (!function_exists('file_get_contents')) {
33 atomo64-guest 54 function file_get_contents($filename) {
34     if (!($file = fopen($filename,"rb"))) return false;
35     else {
36     $contents = "";
37     do {
38     $data = fread($file, 4096);
39     if (strlen($data) == 0) {
40     break;
41     }
42     $contents .= $data;
43     } while (true);
44     fclose($file);
45     return $contents;
46     }
47     }
48     }
49    
50     if (!function_exists('file_put_contents')) {
51     function file_put_contents($filename, $content, $flags = 0) {
52     if (!($file = fopen($filename,$flags))) return false;
53     else {
54     $n = fwrite($file, $content);
55     fclose($file);
56     return true;
57     }
58     }
59     }
60    
61 atomo64-guest 64 if (in_array("-db_add",$argv)) db_add($argv[2], false);
62 atomo64-guest 54 elseif (in_array("-db_query",$argv)) db_query($argv[2],$argv[3] );
63 atomo64-guest 59 elseif (in_array("-dl_diffs",$argv) || in_array("-keep_diff",$argv)) dl_diffs($argv[2]);
64 atomo64-guest 64 elseif (in_array("-keep_sources",$argv) || in_array("-download_sources",$argv)) download_sources();
65 atomo64-guest 54 elseif (in_array("-db_popcon",$argv)) db_popcon($argv[2]);
66 atomo64-guest 59 elseif (in_array("-dl_popcon",$argv) || in_array("-keep_popcon",$argv)) dl_popcon($argv[2]);
67 atomo64-guest 54 elseif (in_array("-db_upstream",$argv)) db_upstream($argv[2]);
68     elseif (in_array("-update_all",$argv)) update_all();
69 atomo64-guest 64 elseif (in_array("-update_new",$argv)) update_new();
70 atomo64-guest 54 elseif (in_array("-check_db",$argv)) check_db();
71     elseif (in_array("-dehsqa_db",$argv)) dehsqa_db();
72     elseif (in_array("-clear_db",$argv)) clear_db();
73     elseif (in_array("-db_up_error",$argv)) db_up_error();
74 atomo64-guest 59 elseif (in_array("-up_changes",$argv)) up_changes($argv[2], true);
75     elseif (in_array("-watchf",$argv) || in_array("-wwiz",$argv)) watch_wizard($argv[2]);
76 atomo64-guest 54 elseif (in_array("-kb_total",$argv)) print "Diff
77 evaso-guest 5 #stat_up_error();
78     #stat_up_error();to download Kb => " . kb_total($argv[2]) . "\n" ;
79 atomo64-guest 54 elseif (in_array("-watch_stat",$argv)) watch_stat();
80     else print "Command $argv[1] not found\n";
81 evaso-guest 5 #stat_up_error();
82     function dir_ctrl($dirs) {
83 atomo64-guest 54 foreach ($dirs as $dir) {
84     if (!is_dir($dir)) exec("mkdir -m 0740 -p " . escapeshellarg($dir), $output, $res);
85     if ($res != 0) die_status("Error creating basic dir: $dir\n");
86     }
87 evaso-guest 5 }
88 atomo64-guest 54 function ext_watch ($file,$pkg,$version) {
89     if (!file_exists($file)) return "";
90     $zp=gzopen($file,"r") or die_status("Fail to open $file");
91     while (!gzeof($zp)) {
92     $line = gzgets ($zp,4096);
93 atomo64-guest 59 if (preg_match('/\+\+\+\s.+\/debian\/watch$/',$line)) {
94 atomo64-guest 54 $line = gzgets ($zp,4096);
95     preg_match ("/.+\+\d+\,(\d+)\s/",$line,$watch_lenght);
96     for ($i = 1; $i <= $watch_lenght[1]; $i++) {
97     $line=gzgets ($zp,4096);
98     $watch .=substr($line,1);
99 evaso-guest 5 }
100 atomo64-guest 54 break;
101 evaso-guest 5 }
102 atomo64-guest 54 }
103     if ($watch!=null) return $watch;
104     else return NULL;
105 evaso-guest 5 }
106     function ftp_cn($login,$password,$ftp_server) {
107 atomo64-guest 54 $conn_id = @ftp_connect($ftp_server) or die_status("Error: Cannot contact ftp server $ftp_server\n");
108     // login con user name e password
109     ftp_pasv($conn_id,1);
110     $login_result = ftp_login($conn_id, "anonymous","bo@bo.org");
111     // controllo della connessione
112     if ((!$conn_id) || (!$login_result)) {
113 evaso-guest 5 echo "Ftp connection failed!\n";
114     echo "Failed connection to $ftp_server\n";
115 atomo64-guest 49 die_status();
116 evaso-guest 5 } else {
117     return $conn_id;
118     }
119     }
120 atomo64-guest 59 function dl_diffs($initial = '') {
121 atomo64-guest 54 global $dirs,$dbconn,$mirrors;
122     check_db();
123     $conn_normal=ftp_cn("anonymous","bo@bo.org",$mirrors['unstable']);
124     #$conn_non_us=ftp_cn("anonymous","bo@bo.org",$mirrors["non-US"]);
125     $db = pg_pconnect($dbconn) ;
126     $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");
127     $total=pg_numrows($rsql);
128     $btotal=byte_total($db,$initial);
129     print "Total Diff to downlaod Kb => " . number_format ($btotal/1024, 2, ",",".") . "\n";
130     while ($res_array=pg_fetch_array($rsql)) {
131     #if ($res_array['dist']=='non-US') $conn_id = $conn_non_us;
132     #else
133     $conn_id = $conn_normal;
134     if ($localfile=download_diffs($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])) {
135     $watch=ext_watch($localfile,$res_array[name],$res_array[version]);
136     unlink($localfile);
137     if ($watch!=NULL) {
138     $watch=iconv("ISO-8859-1","UTF-8",$watch);
139     $watch= addslashes($watch);
140     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");
141     }
142     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");
143     }
144     $btotal=$btotal-$res_array['bytes'];
145     number_format ($btotal/1024, 2, ",",".");
146     print "\rDiffs left => " . $total-- . " Bytes left => " . number_format ($btotal/1024, 2, ",",".") . " - " . $res_array[name];
147     }
148     ftp_quit($conn_normal);
149     pg_close($db);
150     return "Fatto\n";
151     }
152 evaso-guest 5 function download_diffs(&$conn_id,$pkg,$version,$directory,$md5_diff,$md5_atsource,$diff_kb,$dist) {
153 atomo64-guest 54 global $dirs,$mirrors;
154     $localfile=$dirs[diffs_dir] . "/$pkg" . "_" . "$version.diff.gz";
155     #if ($dist=="non-US") $remotefile="/debian-non-US/$directory/$pkg" . "_" . "$version.diff.gz";
156     #else
157     $remotefile="/debian/$directory/$pkg" . "_" . "$version.diff.gz";
158     #print "$localfile - $remotefile\n";
159     if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
160     # print "$pkg Diff.gz => Downloaded\n";
161     if(md5_of_file($localfile)==$md5_atsource) {
162     #print "MD5 => OK\n";
163     #unlink($localfile);
164     return $localfile;
165     }
166     }
167     print "Download Diff.gz of package $pkg => Fallito\n";
168     return false;
169 evaso-guest 5 }
170 atomo64-guest 64 function db_add($initial='', $clear_db = true) {
171 atomo64-guest 54 global $dirs,$dists,$dbconn;
172     check_db();
173 atomo64-guest 64 download_sources();
174 atomo64-guest 54
175 atomo64-guest 64 $db = pg_pconnect($dbconn) or die_status(pg_errormessage($db));
176 atomo64-guest 54 pg_exec($db, "CREATE TEMP TABLE pkgs_atsrc (name text,dist text)") or die_status('Error creating temp table pkgs_atsrc');
177     pg_exec($db, "CREATE UNIQUE INDEX idxdis on pkgs_atsrc (name,dist)") or die_status('Error creating index on temp table');
178     pg_exec($db, "CREATE TEMP TABLE bin_atsrc (name text,bin_name text, dist text)") or die_status('Error creating temp table pkgs_atsrc');
179     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');
180    
181     foreach ($dists as $dist=>$sections) {
182 evaso-guest 5 foreach ($sections as $section) {
183 atomo64-guest 54 $filename=$dirs['sources_dir'] . "/$dist/$section/Sources.gz";
184     print "\nI'm parsing $dist/$section => Sources.gz\n";
185     # 1 Pacchetto - 2 versione - 3 np - 4 Directory - 5 md5
186     $regexp="/Package:\s($initial.*)[^a]Binary:\s(.+)[^a]Version:\s(\d+:)?(.+)[^a]Priority.+Maintainer:.+<([^>]+)>[^a].+Directory:\s(.+)[^a]Files:.+\s(\S+)\s(\d+)\s" . '\1\S+' . "\.diff\.gz[^a](Uploaders:\s(.+)[^a])?/Ssi";
187     $zp = gzopen($filename, "r") or die_status("Could not open $filename");
188     $extracted=tempnam("/tmp/", "$dist_$section_Sources");
189     exec("gzip -c -d $filename > $extracted");
190     $sourcesize=filesize($extracted);
191     unlink($extracted);
192     if(filesize($filename)>20) {
193     while (!gzeof($zp)) {
194     $line='';
195     while ($line!="\n") {
196     $line = gzgets ($zp,4096) ;
197     $buff1 .= $line;
198     }
199     if (preg_match($regexp,$buff1,$matches)) {
200 atomo64-guest 64 if ($matches[5]) {
201     $matches[5]=iconv("ISO-8859-1","UTF-8",$matches[5]);
202     $matches[5]=pg_escape_string($matches[5]);
203     }
204 atomo64-guest 54 if ($matches[10]) {
205     $matches[10]=iconv("ISO-8859-1","UTF-8",$matches[10]);
206 atomo64-guest 64 $matches[10]=pg_escape_string($matches[10]);
207 evaso-guest 5 }
208 atomo64-guest 54 @pg_exec($db,"INSERT INTO pkgs_atsrc (name,dist) VALUES ('$matches[1]','$dist')") OR die_status("Temp table pkgs_atsrc query error");
209     $rst=@pg_exec($db, "INSERT INTO pkgs (name,version,maint,dir,md5_atsource,bytes,dist,section,uploaders) VALUES ('$matches[1]','$matches[4]','$matches[5]','$matches[6]','$matches[7]','$matches[8]','$dist','$section','$matches[10]')") ;
210     if (!$rst) {
211     $rst=@pg_exec($db, "UPDATE pkgs SET name='$matches[1]',version='$matches[4]',maint='$matches[5]',dir='$matches[6]',md5_atsource='$matches[7]',bytes='$matches[8]',dist='$dist',section='$section',uploaders='$matches[10]' WHERE name='$matches[1]' AND dist='$dist'") OR die_status("\nDb adding error =>" . pg_errormessage() . "\n");
212     }
213     $bin_names=split(",", $matches[2]);
214     foreach ($bin_names as $bin_name) {
215     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");
216     $rst=@pg_exec($db, "INSERT INTO binpkgs (name,bin_name,dist) VALUES ('$matches[1]','" . trim($bin_name) . "','$dist')") ;
217     }
218     }
219     else {
220     preg_match("/Package:\s(.+)[^a]Binary/im",$buff1,$matches);
221     if(strncmp($initial,$matches[1],strlen($initial))<0) break;
222     }
223     $left=$sourcesize-gztell($zp);
224     print "\rSource file Left => $left";
225     $buff1="";
226     unset($matches);
227     }
228 evaso-guest 5 }
229     gzclose($zp) ;
230     }
231 atomo64-guest 54 }
232 atomo64-guest 64 if (!$clear_db)
233 atomo64-guest 54 clear_db($db);
234     pg_close($db);
235 evaso-guest 5 }
236     function db_query($pkg,$dist) {
237 atomo64-guest 54 global $dirs,$dbconn;
238     $db = pg_pconnect($dbconn ) or die_status(pg_errormessage($db));
239     $rsql=pg_exec($db, "SELECT pkgs.* ,mpop_inst FROM (SELECT name,MAX(binpkgs.pop_inst) AS mpop_inst FROM binpkgs GROUP BY name)
240     AS binpkgs INNER JOIN pkgs ON pkgs.name=binpkgs.name
241     WHERE pkgs.name='$pkg' AND dist='$dist';");
242     if (pg_numrows($rsql)==1) {
243     $res_array=pg_fetch_array($rsql);
244     print "Package=> " . $res_array['name'] . "\n";
245     print "Version => " . $res_array['version'] . "\n";
246     print "Diff MD5 Downloaded => " . $res_array['md5_diff'] . "\n";
247     print "Diff MD5 at Sources => " . $res_array['md5_atsource'] . "\n";
248     print "Distribution => " . $res_array['dist'] . "\n";
249     print "Section => " . $res_array['section'] . "\n";
250     print "KBytes => " . number_format ( $res_array['bytes']/1024, 2, ",",".") . "\n";
251     print "Pop Inst=>" . $res_array['mpop_inst'] . "\n";
252 evaso-guest 5 if ($res_array['watch']) {
253 atomo64-guest 54 $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$res_array['watch']);
254     print "Version Upstream => " . $uscan_res[0] . "\n";
255     print "Watch => " . $res_array['watch'];
256 atomo64-guest 58 print "Watch Warnings => " . $uscan_res[1];
257 evaso-guest 5 }
258     else print "Watch => Not present" . "\n";
259 atomo64-guest 58 if ($res_array['wwiz_type']) {
260     $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$res_array['wwiz']);
261     print "WWiz Upstream => " . $uscan_res[0] . "\n";
262     print "WWiz => " . $res_array['wwiz'];
263     print "WWiz Warings => " . $uscan_res[1];
264     }
265     print "\n";
266 atomo64-guest 54 }
267     else echo "Package=> " . $pkg . "\nNot found\n!!";
268     pg_close($db);
269 evaso-guest 5 }
270 atomo64-guest 54 function byte_total(&$db,$initial) {
271     global $dirs;
272     $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)");
273     $res_array=pg_fetch_array($rsql);
274     return $res_array[totbytes] ;
275 evaso-guest 5 }
276 atomo64-guest 64 function download_sources () {
277 atomo64-guest 54 global $dirs,$dists,$mirrors;
278     foreach ($dists as $dist=>$sections) {
279     $server=$mirrors[$dist];
280     $conn_id = ftp_cn("anonymous","bo@bo.org",$server);
281     foreach ($sections as $section) {
282     $localfile=$dirs[sources_dir] . "/$dist/$section/Sources.gz";
283     $remotefile=remote_dist_dir($dist) . "/$dist/$section/source/Sources.gz";
284     $sources_info=md5_source($section,$dist);
285     if (!file_exists ($dirs[sources_dir] . "/$dist/")) mkdir ( $dirs[sources_dir] . "/$dist",0740);
286     if (!file_exists ($dirs[sources_dir] . "/$dist/$section")) mkdir ($dirs[sources_dir] . "/$dist/$section",0740);
287     if (!file_exists($localfile) OR md5_of_file($localfile)!=$sources_info[md5]) {
288     print "Downloading $remotefile Bytes $sources_info[bytes]=> ";
289     if (ftp_get($conn_id,$localfile,$remotefile,FTP_BINARY)) {
290     print "Done\n";
291     if(md5_of_file($localfile)==$sources_info[md5]) print "MD5 => OK\n";
292 atomo64-guest 59 else print "MD5 => no match\n";
293 atomo64-guest 54 }
294     else {
295 atomo64-guest 59 unlink($localfile);
296 atomo64-guest 54 print "Fail\n";
297     die_status ("Error in source file");
298     }
299     }
300 evaso-guest 5 }
301 atomo64-guest 54 ftp_quit($conn_id);
302     }
303 evaso-guest 5 }
304     function md5_source($section,$dist) {
305 atomo64-guest 54 global $mirrors;
306     $relase=file_get_contents ("ftp://$mirrors[$dist]" . remote_dist_dir($dist) . "/$dist/Release") or die_status("Failed to check MD5 of sources");
307     preg_match ("/\s([^\s]+)\s+(\d+)\s$section\/source\/Sources\.gz/i", $relase,$matches);
308     return array("md5"=>$matches[1],"bytes"=>$matches[2]);
309     # 183dea9ca3c2e35ffd6cf5eee9501c21 2941637 main/binary-i386/Packages.gz
310 evaso-guest 5 }
311 atomo64-guest 54
312 evaso-guest 5 function vers_conv($debvers) {
313 atomo64-guest 54 // Strip off the epoch
314     $pos = strpos($debvers, ':');
315     if ( $pos !== FALSE) {
316     $debvers = substr($debvers, $pos+1);
317     }
318 evaso-guest 45
319 atomo64-guest 54 // strip off the Debian revision (look from the back of the string)
320     $pos = strrpos($debvers, '-');
321     if ( $pos !== FALSE) {
322     $debvers = substr($debvers, 0, $pos);
323     }
324 evaso-guest 45
325 atomo64-guest 54 // strip off repacking indicators
326     $debvers = preg_replace("/[-.+~]?(ds|dfsg|debian)(.*)/i", "", $debvers);
327     return $debvers;
328 evaso-guest 5 }
329     function check_db() {
330 atomo64-guest 54 global $dirs,$dbconn;
331 atomo64-guest 64 $db = pg_pconnect($dbconn) or die_status(1/*pg_last_notice($db)*/);
332 atomo64-guest 54 if (!pg_table_exists($db,"pkgs")){
333     pg_exec($db, "CREATE TABLE pkgs (id serial PRIMARY KEY,name text,version 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)") or die_status('Error creating table pkgs\n');
334     pg_exec($db, "CREATE UNIQUE INDEX idxname on pkgs (name,dist)") or die_status('Errore creating index - ' . pg_last_error($db));
335     $sw=true;
336     }
337     if (!pg_table_exists($db,"binpkgs")){
338     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');
339     pg_exec($db, "CREATE UNIQUE INDEX idxbin on binpkgs (name,bin_name,dist)") or die_status('Errore creating index - ' . pg_last_error($db));
340     $sw=true;
341     }
342     #if (!pg_table_exists($db,"upstream")){
343     # 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');
344     # pg_exec($db, "CREATE UNIQUE INDEX idxupstrm on upstream (name,dist)") or die_status('Errore nel creare gli indici ' . pg_last_error($db));
345     # $sw=true;
346     #}
347     pg_close($db);
348     if($sw) return $sw;
349     else return false;
350 evaso-guest 5 }
351     function pg_table_exists (&$dblink, $table) {
352 atomo64-guest 54 $sql = "SELECT relname as tbl FROM pg_class WHERE relname = '$table'";
353     if ($res = pg_exec ($dblink, $sql)) {
354     return pg_numrows($res) > 0;
355     } else {
356     return false; // or throw exception
357     }
358     }
359 evaso-guest 5
360    
361     function watch_stat() {
362 atomo64-guest 54 global $dirs,$dbconn;
363     $db = pg_pconnect($dbconn) or die_status(pg_errormessage($db));
364     $rsql=pg_exec ($db,"Select count(name) as totwatch FROM pkgs WHERE watch!=''");
365     $tot_watch=pg_fetch_array($rsql);
366     print "Total packages with Watch =>$tot_watch[0]\n";
367     $rsql=pg_exec ($db,"Select count(name) as totwatch FROM pkgs WHERE watch IS NULL");
368     $tot_nowatch=pg_fetch_array($rsql);
369     pg_close($db);
370     print "Totale packages without Watch => $tot_nowatch[0]\n";
371     print "Watch presence rate => " . number_format ($tot_watch[0]/($tot_nowatch[0]+$tot_watch[0])*100, 2, ",",".") . "%\n";
372 evaso-guest 5 }
373     function remote_dist_dir($dist) {
374 atomo64-guest 54 #if ($dist=="non-US") return "/debian-non-US/dists/unstable";
375     #else
376     return "/debian/dists";
377 evaso-guest 5 }
378 evaso-guest 31 function clear_db(&$db) {
379 atomo64-guest 54 #global $dbconn;
380     #if (check_db()) die_status("Il Database era vuoto\n");
381 atomo64-guest 64 #download_sources();
382 atomo64-guest 54 #$db = pg_pconnect($dbconn) or die_status(pg_result_error($db));
383     $sql1= "Delete from binpkgs where id NOT IN
384 evaso-guest 5 (select id FROM binpkgs INNER JOIN bin_atsrc USING (name,bin_name,dist))" ;
385 atomo64-guest 54 $sql2= "Delete from pkgs where id NOT IN (select id FROM pkgs INNER JOIN pkgs_atsrc USING (name,dist))" ;
386     $sql3= "UPDATE pkgs SET wwiz=NULL, wwiz_type=NULL, wwiz_version=NULL WHERE watch IS NOT NULL or watch!=''" ;
387     $sql4= "UPDATE pkgs SET up_changes=NULL WHERE wwiz_version=up_version OR up_version=version" ;
388     if(pg_exec($db,$sql1) AND pg_exec($db,$sql2) AND pg_exec($db,$sql3) AND pg_exec($db,$sql4)) print "Db clear complete\n";
389 evaso-guest 5 }
390     function db_popcon($initial='') {
391 atomo64-guest 54 global $dirs,$dbconn;
392     $db = pg_pconnect($dbconn) or die_status(pg_errormessage($db));
393     $filename=$dirs[popcon_dir] . "/all-popcon-results.txt.gz";
394     $regexp="/Package:\s($initial\S*)\s+(\d+)\s+(\d+)/iS";
395     $zp = gzopen($filename, "r") or die_status("Could not open $filename");
396     $tin=time();
397     if(filesize($filename)>20) {
398     #pg_exec($db, "BEGIN TRANSACTION") OR die_status("Impossibile iniziare la transazione");
399     while (!gzeof($zp)) {
400     $line = gzgets ($zp,4096) ;
401     if (preg_match($regexp,$line,$matches)) {
402     #print "\rName => $matches[1] Install => $matches[2] Vote => $matches[3]";
403     @pg_exec($db, "UPDATE binpkgs SET pop_inst='$matches[2]',pop_vote='$matches[3]' WHERE bin_name='$matches[1]'");
404     $prcessed++;
405     $elapsed_time=time()-$tin;
406     if (($elapsed_time % 20)==0 AND $updtime!=$elapsed_time) {
407     $updtime=$elapsed_time;
408     $wprocessed=$processed-$wprocessed;
409     $avg_time=$wprocessed/20;
410     $wprocessed=$processed;
411     $countdown=(34701- $processed)/$avg_time;
412     $last_time=time();
413     }
414     //print "\rProcessing Popcon: " . date("i:s",$countdown=$countdown-(time()-$last_time)) . " =>" . (34701-$processed) . " Media $avg_time";
415     $last_time=time();
416     }
417     }
418     #pg_exec($db, "COMMIT") OR die_status("Impossibile commsionare la transazione");
419     }
420     @pg_close($db);
421 evaso-guest 5 }
422     function db_popcon_test() {
423 atomo64-guest 54 global $dirs,$dbconn;
424     $db = pg_pconnect($dbconn) or die_status(pg_errormessage($db));
425     $filename=$dirs[popcon_dir] . "/all-popcon-results.txt.gz";
426     $regexp="/Package:\s(\S+)\s+(\d+)\s+(\d+)/";
427     $zp = gzfile($filename, "r") or die_status("Could not open $filename");
428     if(filesize($filename)>20) {
429     foreach ($zp as $line) {
430     if (preg_match($regexp,$line,$matches)) {
431 evaso-guest 5 # print "Name => $matches[1] \n Install => $matches[2] \n Vote => $matches[3]\n";
432 atomo64-guest 54 print "\r" . $i++;
433     #pg_unbuffered_query($db, "UPDATE binpkgs SET pop_inst='$matches[2]',pop_vote='$matches[3]' WHERE bin_name='$matches[1]'");
434     }
435     }
436     }
437     @pg_close($db);
438 evaso-guest 5 }
439 atomo64-guest 59 function dl_popcon() {
440 atomo64-guest 54 global $dirs,$dbconn;
441     $localfile=$dirs[popcon_dir] . "/all-popcon-results.txt.gz";
442     $remotefile="http://popcon.debian.org/all-popcon-results.txt.gz";
443     @file_put_contents($localfile,file_get_contents($remotefile),'w') or die_status("Errore nello scaricare il file popcon\n");
444 evaso-guest 5 }
445 evaso-guest 17 function is_updated ($up_vers,$debian_vers) {
446 atomo64-guest 54 if ($up_vers=='') return 0;
447     passthru("dpkg --compare-versions '".escapeshellarg($up_vers)."' eq '" . escapeshellarg(vers_conv($debian_vers)) . "'",$great);
448     if ($great!=0) return 1;
449     else return 0;
450 evaso-guest 17 }
451     function db_upstream($initial='%') {
452 atomo64-guest 54 global $dirs,$dbconn;
453     check_db();
454 atomo64-guest 64 $db = pg_pconnect($dbconn) ;
455 atomo64-guest 54 $rsql=pg_exec($db, "SELECT id, pkgs.name,pkgs.dist,up_version,version,watch FROM pkgs WHERE watch is not null AND name LIKE '$initial%' ORDER BY name DESC");
456     $tot=pg_numrows($rsql);
457     while ($res_array=pg_fetch_array($rsql)) {
458     $uscan_res=uscan_foo($res_array['name'],$res_array['version'],$res_array['watch']);
459     if($uscan_res[1] !=null) $uscan_res[1]=addslashes($uscan_res[1]);
460     #print $uscan_res[0] . "\n Name => $res_array[name]\n";
461     $version=$res_array[version];
462 atomo64-guest 59 print "\rVersion=>" . $uscan_res[3];
463 atomo64-guest 54 if ($uscan_res[3]!=null) $version=$uscan_res[3];
464     #$updated=is_updated($uscan_res[0],$res_array[version]);
465     $updated=$uscan_res[4];
466     if ($uscan_res[0]!=$res_array[up_version]) ($keep_changes=1);
467     else $keep_changes=0;
468     $up_url=iconv("ISO-8859-1","UTF-8",$uscan_res[2]);
469     $up_version=iconv("ISO-8859-1","UTF-8",$uscan_res[0]);
470     $watch_warn=iconv("ISO-8859-1","UTF-8",$uscan_res[1]);
471     pg_exec($db, "UPDATE pkgs SET up_version='" . $up_version . "',up_url='" . $up_url . "', watch_warn='" . $watch_warn . "',keep_changes='$keep_changes', wwiz_version=NULL, wwiz_type=NULL, wwiz=NULL, updated='$updated' WHERE id=$res_array[id]") or die_status("Error in update pkgs upstream");
472     #print "\rUpdated " . $res_array['name'] . " => $updated Up Version => ". $uscan_res[0];
473 atomo64-guest 59 print "\tUpstream left => " . $tot --;
474 atomo64-guest 54 # }
475     # else print "Added ". $res_array['name'] ."\n";
476     # if ($great==0) {
477    
478     # print "Package=> " . $res_array['name'] . "\n";
479     # print "Version => " . $res_array['version'] . "\n";
480     # print "Upstream Ver=> " . $uscan_res[0] . "\n";
481     #print "Watch warings=> " . $uscan_res[1] . "\n";
482     # }
483     }
484     print "\n";
485     pg_close($db);
486 evaso-guest 5 }
487 evaso-guest 20 function check_url ($url) {
488 atomo64-guest 54 $url_p = parse_url ($url);
489     if (isset ($url_p["host"])) $host = $url_p["host"];
490     else return false;
491     preg_match("/(http|ftp)/",$host,$matches);
492     if ($matches[1]=='http') $fp = fsockopen ($host, 80, $errno, $errstr, 5);
493     elseif ($matches[1]=='ftp') $fp2 = fsockopen ($host, 21, $errno, $errstr, 5);
494     if (!$fp AND !$fp2) return false;
495     else return true;
496 evaso-guest 20 }
497 evaso-guest 17 function keep_remote ($localfile,$remotefile) {
498 atomo64-guest 54 if (!check_url($remotefile)) return false;
499     # $rfp = @fopen ($remotefile, "r");
500     # if (!$rfp) {
501     # return false;
502     # }
503     # fclose($rfp);
504     # $lfp = fopen ($localfile, "w");
505     # stream_set_blocking($rfp,0);
506     # ini_set ( "memory_limit", "100M");
507     # while (!feof($rfp)) {
508     # $data = fread($rfp, 8192);
509     # $bytes+=8192;
510     # print "Downlaoding $remotefile: $bytes\r";
511     # fwrite($lfp, $data);
512     # } while (true);
513     # ini_set ( "memory_limit", "15M");
514    
515     if (!copy($remotefile, $localfile)) {
516     echo "Copia di $file non riuscita ...\n";
517     return false;
518     }
519     # fclose($lfp);
520     # fclose($rfp);
521    
522     return true;
523 evaso-guest 44 }
524 atomo64-guest 59 function up_changes($src_name='%', $force = false) {
525     global $dbconn, $fetchUpstreamChanges;
526    
527     if (!$fetchUpstreamChanges && !$force) {
528     print "\nSkipping download of upstream sources to grab changelogs\n";
529     return;
530     }
531    
532 atomo64-guest 54 $changes_files=array("CHANGES","NEWS","Changelog","ChangeLog","changelog");
533 evaso-guest 44 $db = pg_pconnect($dbconn) ;
534 atomo64-guest 54 $rsql=pg_exec($db, "SELECT id,up_url FROM pkgs WHERE up_url!='' AND keep_changes='t' AND name LIKE '$src_name%'");
535     $tot=pg_numrows($rsql);
536     while ($res_array=pg_fetch_array($rsql)) {
537     $localfile=tempnam("/tmp/", "dehs-" . $res_array[id] . ".tar.gz");
538     print "I'm downloading $res_array[up_url]\r";
539     $res=keep_remote($localfile,$res_array['up_url']);
540     print "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]";
541     if (!$res) {
542     pg_exec($db, "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]");
543     $notdown++;
544     $tot--;
545     print "Packages Left: " . $tot-- . " Found: $found Not found: $notfound Not Down: $notdown\r";
546     #print "\n Not Downlaoded: $res_array[up_url]\n";
547     unlink($localfile);
548     continue;
549     }
550     foreach($changes_files as $filename) {
551 atomo64-guest 59 $command="tar --wildcards -zxOf " . $localfile . " *$filename 2>/dev/null";
552 atomo64-guest 54 exec($command,$up_changes,$cmdres);
553     $up_changes=rtrim(implode("\n",$up_changes));
554     if ($cmdres==0 AND strlen($up_changes)>20) {
555     $sw=true;
556     $up_changes=addslashes($up_changes);
557     $conv_res=iconv("ISO-8859-1","UTF-8",$up_changes);
558     if ($conv_res) $up_changes=$conv_res;
559     $up_changes_sql="UPDATE pkgs SET up_changes='$up_changes', keep_changes='f' WHERE id=$res_array[id]";
560     pg_exec($db,$up_changes_sql);
561     #print "\nFound $filename on $res_array[up_url]\n";
562     $found++;
563     break;
564     }
565     }
566     if (!$sw) {
567     pg_exec($db, "UPDATE pkgs SET up_changes='', keep_changes='f' WHERE id=$res_array[id]");
568     #print "\n Not Found any on $res_array[up_url]\n";
569     $notfound++;
570     }
571     unlink($localfile);
572     print "Packages Left: " . $tot-- . " Found: $found Not found: $notfound Not Down: $notdown\r";
573     }
574     pg_close($db);
575 evaso-guest 17 }
576 evaso-guest 5 function uscan_foo($name,$version,$watch){
577 atomo64-guest 46 global $base, $uscan;
578 atomo64-guest 54
579 evaso-guest 43 $tmpnam=tempnam('/tmp/', $name.'_watch');
580 evaso-guest 42 $fw=fopen($tmpnam,"w");
581 atomo64-guest 54 fwrite($fw,$watch);
582     fclose($fw);
583    
584     $uscan_res=shell_exec("$uscan --dehs --package $name --upstream-version " . escapeshellarg(vers_conv($version)) . " --watchfile $tmpnam 2>/dev/null 2>&1");
585    
586 evaso-guest 43 unlink($tmpnam);
587 atomo64-guest 54
588     $p = xml_parser_create();
589     xml_parse_into_struct($p, $uscan_res, $vals, $index);
590     xml_parser_free($p);
591    
592     $upstream=$vals[$index['UPSTREAM-VERSION'][0]][value];
593     $up_url=$vals[$index['UPSTREAM-URL'][0]][value];
594     $deb_vers=$vals[$index['DEBIAN-UVERSION'][0]][value];
595     $warnings=$vals[$index['WARNINGS'][0]][value];
596     $updated=$vals[$index['STATUS'][0]][value];
597    
598     if ($updated=="up to date") $updated=0;
599     else $updated=1;
600    
601     if ($upstream=='') $upstream=null;
602     if ($up_url=='') $up_url=null;
603     if ($deb_vers=='') $deb_vers=null;
604     if ($warnings=='') $warnings=null;
605    
606     return array($upstream,$warnings,$up_url,$deb_vers,$updated);
607     }
608 evaso-guest 5 function db_up_error() {
609     global $dbconn;
610 atomo64-guest 54 check_db();
611 atomo64-guest 64 $db = pg_pconnect($dbconn) ;
612 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";
613 atomo64-guest 59 print "\nDownloading bugs list =>";
614 atomo64-guest 54 $ferrors=file_get_contents($bugurl) or die_status ("I can't keep error page from bugs.debian.org");
615     print "Done\n";
616     $ferrors=explode("<li>",$ferrors);
617     $totline=count($ferrors);
618     #$errors[]=array();
619     #array_pop($errors);
620 atomo64-guest 59 print "Total lines => $totline\n";
621 atomo64-guest 54 foreach ($ferrors as $line) {
622     # print $line . "\n";
623 atomo64-guest 59 if (preg_match("/Package:.+?>([^<]+)<\/a>.+<strong>((\d+)\syear\sand\s|)(\d+)\sdays/sS",$line,$matches)) {
624 atomo64-guest 54 $errors[$matches[1]][err_tot]++;
625     $errors[$matches[1]][days]+=$matches[3]*365+$matches[4];
626     #if ($matches[3]) print "Anni $matches[3]";
627     #print "Giorni $matches[4]\n";
628     }
629 atomo64-guest 59 print "\rLines left => " . $totline--;
630 atomo64-guest 54 }
631     #arsort($errors);
632     $total=count($errors);
633 atomo64-guest 59 foreach ($errors as $pkg_name=>$value) {
634     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");
635 atomo64-guest 54 #print "Pkg: $error Errori: $value[err_tot] Average Days: " . $value[days]/$value[err_tot] . "\n";
636 atomo64-guest 59 print "\rBugs left => " . $total--;
637 atomo64-guest 54 }
638     pg_close($db);
639 evaso-guest 5 }
640 atomo64-guest 59 function watch_wizard($src_name='%'){
641 atomo64-guest 54 global $dirs,$dbconn,$sfIgnore,$watchFileExts,$watchFormat;
642     $db = pg_pconnect($dbconn) or die_status ("Db error");
643     $checked=$errors=$notfound=$verok=$notmatch=0;
644     $sqlstring="SELECT mpop_inst,name,pkgs.version,pkgs.section,pkgs.dist,tot_up_error, tot_avg_error_date, wwiz_version FROM pkgs INNER JOIN
645     (Select max(pop_inst) as mpop_inst,SUM(up_error) as tot_up_error,AVG(avg_error_date) as tot_avg_error_date,name,dist FROM binpkgs GROUP BY name,dist HAVING max(pop_inst) IS NOT NULL) as binpkgs using(name,dist)
646 evaso-guest 17 WHERE (watch IS NULL OR watch='') AND name LIKE '$src_name%' ORDER BY mpop_inst DESC";
647 atomo64-guest 54 $rsql=pg_exec($db, $sqlstring);
648    
649 atomo64-guest 62 // prepare some stuff that needs to be done once per run
650     $opts = '';
651     $exts = '(';
652    
653     foreach ($watchFileExts as $ext) {
654     $exts .= $ext . '|';
655     }
656     unset($ext);
657    
658     $exts = substr($exts, 0, -1) . ')';
659     if ($exts == '()') {
660     $exts = '';
661     } else {
662     $opts = 'opts=uversionmangle=s/\.' . $exts . '$// \\';
663     }
664    
665 atomo64-guest 54 while ($res_array=pg_fetch_array($rsql)) {
666    
667     if (substr($res_array["name"],0,3)=='lib')
668     $initial=substr($res_array["name"],0,4);
669     else
670     $initial=substr($res_array["name"],0,1);
671    
672     $url="http://packages.debian.org/changelogs/pool/" .
673     $res_array["section"] . "/" .
674     $initial . "/" .
675     $res_array["name"] ."/" .
676     $res_array["name"] . "_" .
677     $res_array["version"] . "/copyright";
678     $contents=@file_get_contents($url) or '';
679     $generatedWatches = array();
680    
681     if (!$contents) {
682     $url="http://packages.debian.org/changelogs/pool/" .
683     $res_array["section"] . "/" .
684     $initial . "/" .
685     $res_array["name"] ."/" .
686     $res_array["name"] . "_" .
687     $res_array["version"] . "/" . $res_array["name"] . ".copyright";
688     $contents=@file_get_contents($url) or '';
689     }
690    
691     if ($contents) {
692    
693     if (preg_match ('/(sf\.net|sourceforge\.net)/i', $contents, $matches) ||
694     (preg_match ('/([\w\-]+)\.(sf\.net|sourceforge\.net)/i', $contents, $matches)
695     && !in_array($matches[1], $sfIgnore))) {
696     preg_match("/([^\d]+)/",$res_array['name'],$dmatches);
697     $depured_debian_name=$dmatches[1];
698     /*$matches[1]="ftp://download.sf.net/pub/sourceforge/" . substr($depured_debian_name,0,1) . "/" . substr($depured_debian_name,0,2) . "/" . $depured_debian_name . "/";*/
699 atomo64-guest 62 $generatedWatches[]=array('url'=>"http://sf.net/" . $depured_debian_name . "/");
700 atomo64-guest 54 $generatedWatches[]=array('url'=>"http://sf.net/" . $depured_debian_name . "/",'name'=>$depured_debian_name);
701    
702     }
703    
704 atomo64-guest 59 if (preg_match ('#((ftp://|http://|https://)\S+(html|htm|/(?(?=.+(tar|tgz|zip|gz))|[^>\s\)\a]+)))#i',$contents,$matches)) {
705 atomo64-guest 54 $final=substr($matches[1],-1);
706     if ($final=='.') {
707     $matches[1]=substr($matches[1],0,-1);
708     $final=substr($matches[1],-1);
709     }
710 atomo64-guest 58 if ($matches[2]=="http://" || $matches[2]=="https://") {
711 atomo64-guest 54 $space=' ' . "(?:.*/)?";
712     } elseif ($final!='/') {
713     $matches[1].='/';
714     }
715 atomo64-guest 59 $generatedWatches[]=array('url' => preg_replace("#((http|https|ftp)://.+):(.*)#i",'$1' . '$3', $matches[1],1), 'space' => $space);
716 atomo64-guest 54 }
717    
718 atomo64-guest 59 if (preg_match ('#((ftp|http)\.\S+(html|htm|/(?(?=.+(tar|tgz|zip|gz))|[^>\s\)\a]+)))#i',$contents,$matches)) {
719 atomo64-guest 54 $final=substr($matches[1],-1);
720     if ($final=='.') {
721     $matches[1]=substr($matches[1],0,-1);
722     $final=substr($matches[1],-1);
723     }
724     $space = '';
725     if ($matches[2]=="http") {
726     $space=' ' . "(?:.*/)?";
727     } elseif ($final!='/') {
728     $matches[1].='/';
729     }
730 atomo64-guest 59 $generatedWatches[]=array('url'=>preg_replace('#(http|ftp)\.(.+)#i','$1://$0', $matches[1],1), 'space'=>$space);
731 atomo64-guest 54 }
732    
733     if (empty($generatedWatches)) {
734     $notmatch++;
735     $contents=iconv("ISO-8859-1","UTF-8",$contents);
736     pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz='" . pg_escape_string($contents) . "', wwiz_type='notmatch', up_url='', up_changes='',keep_changes='f' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
737    
738     } else {
739    
740 atomo64-guest 56 $defs = array('name' => $res_array['name'], 'url' => '', 'space' => '');
741 atomo64-guest 54
742     foreach ($generatedWatches as $tWatch) {
743    
744 atomo64-guest 59 if (!is_array($tWatch)) {
745     $tWatch = array($tWatch);
746     }
747    
748 atomo64-guest 54 $tWatch = array_merge($defs, $tWatch);
749    
750    
751 atomo64-guest 62 $watch = sprintf($watchFormat, $tWatch['url'], $tWatch['space'], $tWatch['name'], $exts, $opts);
752 atomo64-guest 54
753 atomo64-guest 62 $uscan_res=uscan_foo($res_array['name'] ,$res_array['version'],$watch);
754 atomo64-guest 54
755 atomo64-guest 62 if ($uscan_res[0]) {
756     break 2;
757 atomo64-guest 54 }
758     }
759    
760     if ($uscan_res[1] && !$uscan_res[0]) {
761     pg_exec($db, "UPDATE pkgs SET wwiz_version=NULL, wwiz='" . pg_escape_string($uscan_res[1]) . "', wwiz_type='error', up_url='', up_changes='', keep_changes='f' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
762     $errors++;
763     } else {
764     $verok++;
765     if ($uscan_res[0] != $res_array['wwiz_version']) {
766     $keep_changes = 1;
767     } else {
768     $keep_changes = 0;
769     }
770     pg_exec($db, "UPDATE pkgs SET wwiz='" . pg_escape_string($watch) ."', wwiz_type='watch', wwiz_version='" . pg_escape_string($uscan_res[0]) . "', up_url='" . pg_escape_string($uscan_res[2]) . "', keep_changes='$keep_changes' where name='" . pg_escape_string($res_array[name]) . "' AND dist='" . $res_array[dist] ."'");
771     }
772     }
773     } else {
774     $notfound++;
775     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'] ."'");
776     }
777     print "Package checked: " . $checked++ .
778     " OK: $verok Error: $errors Not Matched: $notmatch\r";
779     }
780     print "\nCopyright files not found: $notfound\n";
781 atomo64-guest 59 print "Automatic generated watch file failures: $errors\n";
782 atomo64-guest 54 pg_close($db);
783 evaso-guest 13 }
784 evaso-guest 26 function dbqa_conn ($dbname,$mode) {
785 atomo64-guest 54 $id = dba_open($dbname, $mode, "db4");
786     if (!$id) {
787     die_status("dba_open failed\n");
788     }
789     return $id;
790 evaso-guest 26 }
791     function dehsqa_db () {
792 atomo64-guest 54 global $dirs,$dbconn;
793     $dir1='/org/alioth.debian.org/chroot/home/groups/dehs/htdocs/';
794     $dir2="/org/qa.debian.org/data/dehs/";
795     $dists=array("unstable","experimental");
796     foreach ($dists as $dist) {
797     $id=dbqa_conn($dir1 . "dehs_qa_" . $dist . ".db",'n');
798     $db = pg_pconnect($dbconn) or die_status ("Db error");
799     $sql="SELECT name, id, up_version, wwiz_version, watch, wwiz_type, watch_warn, updated FROM pkgs WHERE dist='$dist'";
800     $rsql=pg_exec($db, $sql);
801     while($res_array=pg_fetch_array($rsql)) {
802    
803 atomo64-guest 63 if (!$res_array[watch]) { if ($res_array['wwiz_type']==null) $version="N/A"; else $version='-';}
804 atomo64-guest 54 elseif (!$res_array[up_version]) $version="Error";
805     else $version=$res_array[up_version];
806    
807     if ($res_array['wwiz_type']=="watch") $wwiz=$res_array['wwiz_version'];
808     else $wwiz=$res_array[wwiz_type];
809    
810     $xml="<data><id>$res_array[id]</id>" .
811     "<up_version>$version</up_version>" .
812     "<wwiz>$wwiz</wwiz>" .
813     "</data>";
814     $value=addslashes($xml);
815     dba_replace($res_array[name],$xml,$id);
816     }
817     dba_optimize($id);
818     dba_close($id);
819     pg_close($db);
820     }
821 evaso-guest 26 }
822     function md5_of_file($inFile) {
823 atomo64-guest 54 if (file_exists($inFile)) {
824     return md5_file($inFile);
825     } else {
826     return false;
827     }
828 evaso-guest 26 }
829 evaso-guest 5 function update_all() {
830 atomo64-guest 54 global $email;
831     $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
832     db_add();
833 atomo64-guest 59 dl_popcon();
834 atomo64-guest 54 db_popcon();
835 atomo64-guest 59 dl_diffs();
836 atomo64-guest 54 db_up_error();
837     db_upstream();
838 atomo64-guest 59 watch_wizard();
839 atomo64-guest 54 up_changes();
840     dehsqa_db();
841     $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
842     $messaggio="Dehs executed successful\nBegin: $intime\nEnd: $endtime";
843     mail($email, "DEHS report", $messaggio,
844     "From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
845     "Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
846     "X-Mailer: PHP/" . phpversion());
847 evaso-guest 5 }
848 atomo64-guest 64 function update_new() {
849     global $email_all;
850     $intime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
851     db_add('',false);
852     dl_popcon();
853     db_popcon();
854    
855     global $dbconn;
856     check_db();
857     $db = pg_pconnect($dbconn);
858     $sql="SELECT name FROM pkgs WHERE (md5_diff!=md5_atsource or md5_diff is null)";
859     $rsql=pg_exec($db, $sql);
860     $res_array=pg_fetch_all($rsql);
861     pg_close($db);
862    
863     dl_diffs();
864     db_up_error();
865     if ($res_array !== false) {
866     foreach ($res_array as $entry) {
867     db_upstream($entry['name']);
868     up_changes($entry['name']);
869     }
870     dehsqa_db();
871     }
872     $endtime=gmdate('D, d M Y H:i:s \C\E\S\T',time()+3600*2);
873     $messaggio="Dehs executed successful\nBegin: $intime\nPackages processed: ".((!is_array($res_array))?'none':count($res_array))."\nEnd: $endtime";
874     mail($email_all, "DEHS update_new report", $messaggio,
875     "From: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
876     "Reply-To: dehs-noreply@{$_SERVER['SERVER_NAME']}\r\n" .
877     "X-Mailer: PHP/" . phpversion());
878     }
879 atomo64-guest 49 function die_status($msg = '', $status = 1) {
880 atomo64-guest 54 if (empty($msg)) {
881     die($status);
882     } else if (is_int($msg) && $status == 1 /* default */) {
883     die($msg);
884     } else {
885     echo $msg;
886     die($status);
887     }
888 atomo64-guest 49 }
889 atomo64-guest 46 ?>

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5