/[collab-qa]/udd/udd/bugs_gatherer.pl
ViewVC logotype

Diff of /udd/udd/bugs_gatherer.pl

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

revision 1217 by lucas, Sun Sep 7 17:28:09 2008 UTC revision 1351 by lucas, Fri Dec 19 13:30:01 2008 UTC
# Line 16  use Time::Local; Line 16  use Time::Local;
16    
17  use Debbugs::Bugs qw{get_bugs};  use Debbugs::Bugs qw{get_bugs};
18  use Debbugs::Status qw{read_bug get_bug_status bug_presence};  use Debbugs::Status qw{read_bug get_bug_status bug_presence};
19  use Debbugs::Packages qw{binarytosource};  use Debbugs::Packages qw{binarytosource getpkgsrc};
20  use Debbugs::Config qw{:globals};  use Debbugs::Config qw{:globals %config};
21  use Debbugs::User;  use Debbugs::User;
22  #use Debbugs::User qw{read_usertags};  #use Debbugs::User qw{read_usertags};
23    
# Line 26  $YAML::Syck::ImplicitTyping = 1; Line 26  $YAML::Syck::ImplicitTyping = 1;
26  #Used for measuring time  #Used for measuring time
27  our $t;  our $t;
28  our $timing = 0;  our $timing = 0;
29    our @archs = grep {  !/(^m68k$|^kfreebsd|^hurd)/ } @{$config{default_architectures}};
30    
31  # Return the list of usernames  # Return the list of usernames
32  sub get_bugs_users {  sub get_bugs_users {
# Line 92  sub without_duplicates { Line 93  sub without_duplicates {
93          return (grep { ($h{$_}++ == 0) || 0 } @_);          return (grep { ($h{$_}++ == 0) || 0 } @_);
94  }  }
95    
 sub setup {  
         my ($config, $source, $dbh) = @_;  
         my $schema = $config->{general}->{'schema-dir'} . '/' . $config->{$source}->{schema};  
         open SQL, "<",  $schema or die $!;  
         my $command = join "", <SQL>;  
         close SQL;  
         $command =~ s/%\(([^)]+)\)s/$config->{$source}->{$1}/g;  
         $dbh->prepare($command)->execute() or die $!;  
 }  
   
 sub tables {  
         my ($config, $source, $dbh) = @_;  
         my @ret = ();  
         foreach my $prefix ($config->{$source}->{table}, $config->{$source}->{'archived-table'}) {  
                 foreach my $postfix (qw{_merged_with _found_in _fixed_in _tags}, '') {  
                         push @ret, "$prefix$postfix";  
                 }  
         }  
         unshift @ret, $config->{$source}->{'usertags-table'};  
         return @ret;  
 }  
   
   
 sub drop {  
         my ($config, $source, $dbh) = @_;  
         map {  
                 $dbh->prepare("DROP VIEW $_")->execute() or die $!;  
         }  
         qw{bugs_rt_affects_stable bugs_rt_affects_testing_and_unstable bugs_rt_affects_unstable bugs_rt_affects_testing};  
   
         foreach my $table (tables($config, $source, $dbh)) {  
                 $dbh->prepare("DROP TABLE $table")->execute() or die $!;  
         }  
 }  
   
96  sub run_usertags {  sub run_usertags {
97          my ($config, $source, $dbh) = @_;          my ($config, $source, $dbh) = @_;
98          my %src_config = %{$config->{$source}};          my %src_config = %{$config->{$source}};
# Line 150  sub run_usertags { Line 116  sub run_usertags {
116                  $user = $dbh->quote($user);                  $user = $dbh->quote($user);
117                  foreach my $tag (keys %tags) {                  foreach my $tag (keys %tags) {
118                          my $qtag = $dbh->quote($tag);                          my $qtag = $dbh->quote($tag);
119                          map { $dbh->do("INSERT INTO $table VALUES ($user, $qtag, $_)") or die $! } @{$tags{$tag}};                          map { $dbh->do("INSERT INTO $table (email, tag, id) VALUES ($user, $qtag, $_)") or die $! } @{$tags{$tag}};
120                  }                  }
121          }          }
122  }  }
# Line 160  sub run { Line 126  sub run {
126    
127          our $t;          our $t;
128          our $timing;          our $timing;
129    
130            run_usertags($config, $source, $dbh);
131          print "Inserting usertags: ",(time() - $t),"s\n" if $timing;          print "Inserting usertags: ",(time() - $t),"s\n" if $timing;
132          $t = time();          $t = time();
         run_usertags($config, $source, $dbh);  
133    
134          my %src_config = %{$config->{$source}};          my %src_config = %{$config->{$source}};
135          my $table = $src_config{table};          my $table = $src_config{table};
136          my $archived_table = $src_config{'archived-table'};          my $archived_table = $src_config{'archived-table'};
137    
138            my %pkgsrc = %{getpkgsrc()};
139    
140          my @modified_bugs;          my @modified_bugs;
141          ####### XXX EXPERIMENT  
         ####### XXX What to do with bugs both archived and unarchived  
         #my $max_last_modified = get_db_max_last_modified($dbh);  
         #my @modified_bugs;  
         #if($max_last_modified) {  
         #       @modified_bugs = @{get_modified_bugs($max_last_modified)};  
                 # Delete modified bugs  
                 #       for my $bug (@modified_bugs) {  
                 #               map {  
                 #                       $dbh->prepare("DELETE FROM $_ WHERE id = $bug")->execute()  
                 #               } qw{bugs bug_merged_with bug_found_in bug_fixed_in};  
                 #       }  
                 #} else {  
                 #       @modified_bugs = get_bugs(archive => 'both');  
                 #}  
                 #@modified_bugs = without_duplicates(@modified_bugs);  
142          if($src_config{archived}) {          if($src_config{archived}) {
143                  @modified_bugs = get_bugs(archive => 1);                  # some bugs (the unarchived ones) are in both list. exclude them.
144                    my %unarchived;
145                    foreach my $b (get_bugs()) {
146                            $unarchived{$b} = 1;
147                    }
148                    foreach my $b (get_bugs(archive => 1)) {
149                            push(@modified_bugs, $b) if not $unarchived{$b};
150                    }
151          } else {          } else {
152                  @modified_bugs = get_bugs();                  @modified_bugs = get_bugs();
153          }          }
   
154          my @modified_bugs2;          my @modified_bugs2;
155          if ($src_config{debug}) {          if ($src_config{debug}) {
156                  foreach $b (@modified_bugs) {                  print "Running in debug mode with restricted bug list!!\n";
157                          push(@modified_bugs2, $b) if ($b =~ /0$/);                  foreach my $b (@modified_bugs) {
158                            push(@modified_bugs2, $b) if ($b =~ /58$/);
159                  }                  }
160                  @modified_bugs = @modified_bugs2;                  @modified_bugs = @modified_bugs2;
161          }          }
# Line 203  sub run { Line 164  sub run {
164          $t = time();          $t = time();
165    
166          foreach my $prefix ($table, $archived_table) {          foreach my $prefix ($table, $archived_table) {
167                  foreach my $postfix ('', qw{_merged_with _found_in _fixed_in _tags}) {                  foreach my $postfix (qw{_packages _merged_with _found_in _fixed_in _tags}, '') {
168                          my $sth = $dbh->prepare("DELETE FROM $prefix$postfix WHERE id = \$1");                          my $sth = $dbh->prepare("DELETE FROM $prefix$postfix WHERE id = \$1");
169                          map {                          map {
170                                  $sth->execute($_) or die $!;                                  $sth->execute($_) or die $!;
# Line 213  sub run { Line 174  sub run {
174          print "Deleting bugs: ",(time() - $t),"s\n" if $timing;          print "Deleting bugs: ",(time() - $t),"s\n" if $timing;
175          $t = time();          $t = time();
176    
         # Used to chache binary to source mappings  
         my %binarytosource = ();  
         # XXX What if a bug is in location 'db' (which currently doesn't exist)  
177          my $location = $src_config{archived} ? 'archive' : 'db_h';          my $location = $src_config{archived} ? 'archive' : 'db_h';
         #my $table = $src_config{archived} ? 'bugs_archived' : 'bugs';  
178          $table = $src_config{archived} ? $archived_table : $table;          $table = $src_config{archived} ? $archived_table : $table;
179          # Read all bugs          # Read all bugs
180          my $insert_bugs_handle = $dbh->prepare("INSERT INTO $table VALUES (\$1, \$2, \$3, \$4::abstime, \$5, \$6, \$7, \$8, \$9, \$10::abstime, \$11, \$12, \$13)");          my $insert_bugs_handle = $dbh->prepare("INSERT INTO $table (id, package, source, arrival, status, severity, submitter, owner, title, last_modified, affects_stable, affects_testing, affects_unstable, affects_experimental) VALUES (\$1, \$2, \$3, \$4::abstime, \$5, \$6, \$7, \$8, \$9, \$10::abstime, \$11, \$12, \$13, \$14)");
181          my $insert_bugs_found_handle = $dbh->prepare("INSERT INTO ${table}_found_in VALUES (\$1, \$2)");          my $insert_bugs_packages_handle = $dbh->prepare("INSERT INTO ${table}_packages (id, package, source) VALUES (\$1, \$2, \$3)");
182          my $insert_bugs_fixed_handle = $dbh->prepare("INSERT INTO ${table}_fixed_in VALUES (\$1, \$2)");          my $insert_bugs_found_handle = $dbh->prepare("INSERT INTO ${table}_found_in (id, version) VALUES (\$1, \$2)");
183          my $insert_bugs_merged_handle = $dbh->prepare("INSERT INTO ${table}_merged_with VALUES (\$1, \$2)");          my $insert_bugs_fixed_handle = $dbh->prepare("INSERT INTO ${table}_fixed_in (id, version) VALUES (\$1, \$2)");
184          my $insert_bugs_tags_handle = $dbh->prepare("INSERT INTO ${table}_tags VALUES (\$1, \$2)");          my $insert_bugs_merged_handle = $dbh->prepare("INSERT INTO ${table}_merged_with (id, merged_with) VALUES (\$1, \$2)");
185            my $insert_bugs_tags_handle = $dbh->prepare("INSERT INTO ${table}_tags (id, tag) VALUES (\$1, \$2)");
186          $insert_bugs_handle->bind_param(4, undef, SQL_INTEGER);          $insert_bugs_handle->bind_param(4, undef, SQL_INTEGER);
187          $insert_bugs_handle->bind_param(10, undef, SQL_INTEGER);          $insert_bugs_handle->bind_param(10, undef, SQL_INTEGER);
188    
         print "Inserting bugs: ",(time() - $t),"s\n" if $timing;  
189          $t = time();          $t = time();
190          foreach my $bug_nr (@modified_bugs) {          foreach my $bug_nr (@modified_bugs) {
191                  # Fetch bug using Debbugs                  # Fetch bug using Debbugs
# Line 255  sub run { Line 212  sub run {
212                  } qw{date log_modified};                  } qw{date log_modified};
213    
214    
215                  if(not exists $binarytosource{$bug{package}}) {                  my $source = exists($pkgsrc{$bug{package}}) ? $pkgsrc{$bug{package}} : $bug{package};
                         $binarytosource{$bug{package}} = (binarytosource($bug{package}))[0];  
                 }  
                 my $source = $binarytosource{$bug{package}};  
   
                 if(not defined $source) {  
                 # if source is not defined, then we $bug{package} is likely to  
                 # be a source package name (or the source package has the same  
                 # name as the binary package). See #480818 for ex.  
                         $source = $bug{package};  
                 }  
216    
217                  #Calculate bug presence in distributions                  #Calculate bug presence in distributions
218                  my ($present_in_stable, $present_in_testing, $present_in_unstable);                  my ($present_in_stable, $present_in_testing, $present_in_unstable, $present_in_experimental);
219                  if($src_config{archived}) {                  if($src_config{archived}) {
220                          $present_in_stable = $present_in_testing = $present_in_unstable = 'FALSE';                          $present_in_stable = $present_in_testing = $present_in_unstable = $present_in_experimental = 'FALSE';
221                  } else {                  } else {
222                          $present_in_stable =                          $present_in_stable =
223                                  bug_presence(bug => $bug_nr, status => \%bug,                                  bug_presence(bug => $bug_nr, status => \%bug,
224                                                           dist => 'stable');                                                           dist => 'stable',
225                                                             arch => \@archs);
226                          $present_in_testing =                          $present_in_testing =
227                                  bug_presence(bug => $bug_nr, status => \%bug,                                  bug_presence(bug => $bug_nr, status => \%bug,
228                                                           dist => 'testing');                                                           dist => 'testing',
229                                                             arch => \@archs);
230                          $present_in_unstable =                          $present_in_unstable =
231                                  bug_presence(bug => $bug_nr, status => \%bug,                                  bug_presence(bug => $bug_nr, status => \%bug,
232                                                           dist => 'unstable');                                                           dist => 'unstable',
233                          if(!defined($present_in_stable) or !defined($present_in_unstable) or !defined($present_in_testing)) {                                                           arch => \@archs);
234                            $present_in_experimental =
235                                    bug_presence(bug => $bug_nr, status => \%bug,
236                                                             dist => 'experimental',
237                                                             arch => \@archs);
238    
239                            if(!defined($present_in_stable) or !defined($present_in_unstable) or !defined($present_in_testing) or !defined($present_in_experimental)) {
240                                  print "NUMBER: $bug_nr\n";                                  print "NUMBER: $bug_nr\n";
241                          }                          }
242    
# Line 300  sub run { Line 255  sub run {
255                          } else {                          } else {
256                                  $present_in_unstable = 'TRUE';                                  $present_in_unstable = 'TRUE';
257                          }                          }
258                            if(defined($present_in_experimental) and ($present_in_experimental eq 'absent' or $present_in_experimental eq 'fixed')) {
259                                    $present_in_experimental = 'FALSE';
260                            } else {
261                                    $present_in_experimental = 'TRUE';
262                            }
263                  }                  }
264    
265                  # Insert data into bugs table                  # Insert data into bugs table
266                  $insert_bugs_handle->execute($bug_nr, $bug{package}, $source, $bug{date}, $bug{pending},                  $insert_bugs_handle->execute($bug_nr, $bug{package}, $source, $bug{date}, $bug{pending},
267                          $bug{severity}, $bug{originator}, $bug{owner}, $bug{subject}, $bug{log_modified},                          $bug{severity}, $bug{originator}, $bug{owner}, $bug{subject}, $bug{log_modified},
268                          $present_in_stable, $present_in_testing, $present_in_unstable) or die $!;                          $present_in_stable, $present_in_testing, $present_in_unstable, $present_in_experimental) or die $!;
269    
270                    my $src;
271                    foreach my $pkg (keys %{{ map { $_ => 1 } split(/\s*,\s*/, $bug{package})}}) {
272                            $src = exists($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : $pkg;
273                            $insert_bugs_packages_handle->execute($bug_nr, $pkg, $src) or die $!;
274                    }
275    
276                  # insert data into bug_fixed_in and bug_found_in tables                  # insert data into bug_fixed_in and bug_found_in tables
277                  foreach my $version (without_duplicates(@found_versions)) {                  foreach my $version (without_duplicates(@found_versions)) {
# Line 321  sub run { Line 287  sub run {
287                          $insert_bugs_tags_handle->execute($bug_nr, $tag) or die $!;                          $insert_bugs_tags_handle->execute($bug_nr, $tag) or die $!;
288                  }                  }
289          }          }
290            print "Inserting bugs: ",(time() - $t),"s\n" if $timing;
291  }  }
292    
293  sub main {  sub main {
# Line 337  sub main { Line 304  sub main {
304          my $source = $ARGV[2];          my $source = $ARGV[2];
305    
306          my $dbname = $config->{general}->{dbname};          my $dbname = $config->{general}->{dbname};
307            my $dbport;
308            if ($config->{general}->{dbport} ne '') {
309              $dbport = ";port=".$config->{general}->{dbport};
310            } else {
311              $dbport = "";
312            }
313          # Connection to DB          # Connection to DB
314          my $dbh = DBI->connect("dbi:Pg:dbname=$dbname");          my $dbh = DBI->connect("dbi:Pg:dbname=$dbname".$dbport);
315          # We want to commit the transaction as a hole at the end          # We want to commit the transaction as a hole at the end
316          $dbh->{AutoCommit} = 0;          $dbh->{AutoCommit} = 0;
317            $dbh->do('SET CONSTRAINTS ALL DEFERRED');
318    
319          if($command eq 'run') {          if($command eq 'run') {
320                  run($config, $source, $dbh);                  run($config, $source, $dbh);
         } elsif ($command eq 'setup') {  
                 setup($config, $source, $dbh);  
         } elsif ($command eq 'drop') {  
                 drop($config, $source, $dbh);  
         } elsif ($command eq 'tables') {  
                 print join "\n", tables($config, $source, $dbh)  
321          } else {          } else {
322                  print STDERR "<command> has to be one of run, drop and setup\n";                  print STDERR "<command> has to be one of run, drop and setup\n";
323                  exit(1)                  exit(1)

Legend:
Removed from v.1217  
changed lines
  Added in v.1351

  ViewVC Help
Powered by ViewVC 1.1.5