use vars qw($DEBUG);
-use Debbugs::Common qw(checkpid lockpid get_hashname getparsedaddrs getbugcomponent make_list getsourcemaintainers);
+use Debbugs::Common (qw(checkpid lockpid get_hashname getparsedaddrs getbugcomponent make_list getsourcemaintainers),
+ qw(hash_slice));
use Debbugs::Config qw(:config);
use Debbugs::Status qw(read_bug split_status_fields);
use Debbugs::Log;
use Debbugs::DB;
-use Debbugs::DB::Load qw(load_bug handle_load_bug_queue :load_package :load_suite);
+use Debbugs::DB::Load qw(:load_bug :load_package :load_suite);
use DateTime;
use File::stat;
+use File::Basename;
+use File::Spec;
use IO::Dir;
+use IO::File;
use IO::Uncompress::AnyUncompress;
+use Encode qw(decode_utf8);
my %options =
(debug => 0,
my %subcommands =
('bugs' => {function => \&add_bugs,
+ arguments => {'preload' => 0},
},
'versions' => {function => \&add_versions,
},
},
'packages' => {function => \&add_packages,
arguments => {'ftpdists=s' => 1,
+ 'suites=s@' => 0,
},
},
'help' => {function => sub {pod2usage({verbose => 2});}}
pod2usage();
}
+binmode(STDOUT,':encoding(UTF-8)');
+binmode(STDERR,':encoding(UTF-8)');
+
my $opts =
handle_subcommand_arguments(\@ARGV,$subcommands{$subcommand}{arguments});
$subcommands{$subcommand}{function}->(\%options,$opts,$prog_bar,\%config,\@ARGV);
my %severities;
my %queue;
+ if ($opts->{preload}) {
+ my @bugs;
+ walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
+ undef,
+ 'summary',
+ undef,
+ sub {
+ push @bugs,shift;
+ });
+ $s->resultset('Bug')->quick_insert_bugs(@bugs);
+ }
walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
$p,
'summary',
my $s = db_connect($options);
my $maintainers = getsourcemaintainers();
- $p->target(scalar keys %{$maintainers}) if $p;
- for my $pkg (keys %{$maintainers}) {
- my $maint = $maintainers->{$pkg};
- # see if a maintainer already exists; if so, we don't do
- # anything here
- my $maint_r = $s->resultset('Maintainer')->
- find({name => $maint});
- if (not defined $maint_r) {
- # get e-mail address of maintainer
- my $addr = getparsedaddrs($maint);
- my $e_mail = $addr->address();
- my $full_name = $addr->phrase();
- $full_name =~ s/^\"|\"$//g;
- $full_name =~ s/^\s+|\s+$//g;
- # find correspondent
- my $correspondent = $s->resultset('Correspondent')->
- find_or_create({addr => $e_mail});
- if (length $full_name) {
- my $c_full_name = $correspondent->find_or_create_related('correspondent_full_names',
- {full_name => $full_name}) if length $full_name;
- $c_full_name->update({last_seen => 'NOW()'});
- }
- $maint_r =
- $s->resultset('Maintainer')->
- find_or_create({name => $maint,
- correspondent => $correspondent,
- });
- }
- # add the maintainer to the source package for packages with
- # no maintainer
- $s->txn_do(sub {
- $s->resultset('SrcPkg')->search({pkg => $pkg})->
- search_related_rs('src_vers',{ maintainer => undef})->
- update_all({maintainer => $maint_r->id()});
- });
- $p->update() if $p;
+ $p->target(2) if $p;
+ ## get all of the maintainers, and add the missing ones
+ my $maints = $s->resultset('Maintainer')->
+ get_maintainers(values %{$maintainers});
+ $p->update();
+ my @svs = $s->resultset('SrcVer')->
+ search({maintainer => undef
+ },
+ {join => 'src_pkg',
+ group_by => 'me.src_pkg, src_pkg.pkg',
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ columns => [qw(me.src_pkg src_pkg.pkg)],
+ }
+ )->all();
+ $p->target(2+@svs) if $p;
+ $p->update() if $p;
+ for my $sv (@svs) {
+ if (exists $maintainers->{$sv->{src_pkg}{pkg}}) {
+ my $pkg = $sv->{src_pkg}{pkg};
+ my $maint = $maints->
+ {$maintainers->{$pkg}};
+ $s->txn_do(sub {$s->resultset('SrcVer')->
+ search({maintainer => undef,
+ 'src_pkg.pkg' => $pkg
+ },
+ {join => 'src_pkg'}
+ )->update({maintainer => $maint})
+ });
+ }
+ $p->update() if $p;
}
$p->remove() if $p;
}
# tags
# add all tags
+ my %tags;
+ for my $tag (@{$config{tags}}) {
+ $tags{$tag} = 1;
+ $s->resultset('Tag')->find_or_create({tag => $tag});
+ }
# mark obsolete tags
+ for my $tag ($s->resultset('Tag')->search_rs()->all()) {
+ next if exists $tags{$tag->tag};
+ $tag->obsolete(1);
+ $tag->update;
+ }
# severities
my %sev_names;
- my $order = 0;
- for my $sev_name (@{$config{severities}}) {
+ my $order = -1;
+ for my $sev_name (($config{default_severity},@{$config{severity_list}})) {
# add all severitites
my $sev = $s->resultset('Severity')->find_or_create({severity => $sev_name});
# mark strong severities
if (grep {$_ eq $sev_name} @{$config{strong_severities}}) {
$sev->strong(1);
}
- $sev->order($order);
+ $sev->ordering($order);
$sev->update();
$order++;
$sev_names{$sev_name} = 1;
}
# mark obsolete severities
- for my $sev ($s->resultset('Severity')->find()) {
+ for my $sev ($s->resultset('Severity')->search_rs()->all()) {
next if exists $sev_names{$sev->severity()};
$sev->obsolete(1);
$sev->update();
$verbose,
sub {
my $bug = shift;
- eval {
+ my $stat = stat(getbugcomponent($bug,'log',$initialdir));
+ if (not defined $stat) {
+ print STDERR "Unable to stat $bug $!\n";
+ next;
+ }
+ if ($options{quick}) {
+ my $rs = $s->resultset('Bug')->search({bug=>$bug})->single();
+ next if defined $rs and $stat->mtime < $rs->last_modified()->epoch();
+ }
+ eval {
load_bug_log(db => $s,
bug => $bug);
};
sub add_packages {
my ($options,$opts,$p,$config,$argv) = @_;
- my $s = db_connect($options);
-
my $dist_dir = IO::Dir->new($opts->{ftpdists});
my @dist_names =
grep { $_ !~ /^\./ and
not -l $opts->{ftpdists}.'/'.$_
} $dist_dir->read;
my %s_p;
- my %s_info;
while (my $dist = shift @dist_names) {
my $dist_dir = $opts->{ftpdists}.'/'.$dist;
- # parse release
- my $rfh = IO::Uncompress::AnyUncompress->new($dist_dir.'/Release');
- my %dist_info;
- my $in_sha1;
- my %p_f;
- while (<$rfh>) {
- chomp;
- if (s/^(\S+):\s*//) {
- if ($1 eq 'SHA1'or $1 eq 'SHA256') {
- $in_sha1 = 1;
- next;
- }
- $dist_info{$1} = $_;
- } elsif ($in_sha1) {
- s/^\s//;
- my ($sha,$size,$file) = split /\s+/,$_;
- next unless $file =~ /(?:Packages|Sources)(?:\.gz|\.xz)$/;
- next unless $file =~ m{^([^/]+)/([^/]+)/([^/]+)$};
- my ($component,$arch,$package_source) = ($1,$2,$3);
- $arch =~ s/binary-//;
- next if exists $p_f{$component}{$arch};
- $p_f{$component}{$arch} = $dist_dir.'/'.$file;
- }
+ my ($dist_info,$package_files) =
+ read_release_file($dist_dir.'/Release');
+ $s_p{$dist_info->{Codename}} = $package_files;
+ }
+ my $tot = 0;
+ for my $suite (keys %s_p) {
+ for my $component (keys %{$s_p{$suite}}) {
+ $tot += scalar keys %{$s_p{$suite}{$component}};
}
- $s_p{$dist_info{Suite}} = \%p_f;
- $s_info{$dist_info{Suite}} = \%s_info;
}
+ $p->target($tot) if $p;
+ my $i = 0;
+ my $avg_pkgs = 0;
+ my $tot_suites = scalar keys %s_p;
+ my $done_suites=0;
+ my $completed_pkgs=0;
# parse packages files
for my $suite (keys %s_p) {
+ my @pkgs;
for my $component (keys %{$s_p{$suite}}) {
- for my $arch (keys %{$s_p{$suite}{$component}}) {
- my $pfh = IO::Uncompress::AnyUncompress->new($s_p{$suite}{$component}{$arch}) or
+ my @archs = keys %{$s_p{$suite}{$component}};
+ if (grep {$_ eq 'source'} @archs) {
+ @archs = ('source',grep {$_ ne 'source'} @archs);
+ }
+ for my $arch (@archs) {
+ my $pfh = open_compressed_file($s_p{$suite}{$component}{$arch}) or
die "Unable to open $s_p{$suite}{$component}{$arch} for reading: $!";
- my $lastkey;
- my %pkg;
+ local $_;
+ local $/ = ''; # paragraph mode
while (<$pfh>) {
- if (/^$/) {
- load_package($s,$suite,$component,$arch,\%pkg);
- %pkg = ();
- next;
+ my %pkg;
+ for my $field (qw(Package Maintainer Version Source)) {
+ /^\Q$field\E: (.*)/m;
+ $pkg{$field} = $1;
}
- if (my ($key, $value) = m/^(\S+): (.*)/) {
- $pkg{$key} = $value;
- $lastkey=$key;
- }
- else {
- s/ //;
- s/^\.$//;
- chomp;
- $pkg{$lastkey} .= "\n" . $_;
- }
- }
- if (keys %pkg) {
- load_package($s,$suite,$component,$arch,\%pkg);
+ next unless defined $pkg{Package} and
+ defined $pkg{Version};
+ push @pkgs,[$arch,$component,\%pkg];
}
}
}
+ my $s = db_connect($options);
+ if ($avg_pkgs==0) {
+ $avg_pkgs = @pkgs;
+ }
+ $p->target($avg_pkgs*($tot_suites-$done_suites-1)+
+ $completed_pkgs+@pkgs) if $p;
+ load_packages($s,
+ $suite,
+ \@pkgs,
+ $p);
+ $avg_pkgs=($avg_pkgs*$done_suites + @pkgs)/($done_suites+1);
+ $completed_pkgs += @pkgs;
+ $done_suites++;
}
- use Data::Printer;
- p %s_p;
+ $p->remove() if $p;
}
sub handle_subcommand_arguments {
die "Unable to connect to database: ";
}
+sub open_compressed_file {
+ my ($file) = @_;
+ my $fh;
+ my $mode = '<:encoding(UTF-8)';
+ my @opts;
+ if ($file =~ /\.gz$/) {
+ $mode = '-|:encoding(UTF-8)';
+ push @opts,'gzip','-dc';
+ }
+ if ($file =~ /\.xz$/) {
+ $mode = '-|:encoding(UTF-8)';
+ push @opts,'xz','-dc';
+ }
+ if ($file =~ /\.bz2$/) {
+ $mode = '-|:encoding(UTF-8)';
+ push @opts,'bzip2','-dc';
+ }
+ open($fh,$mode,@opts,$file);
+ return $fh;
+}
+
+sub read_release_file {
+ my ($file) = @_;
+ # parse release
+ my $rfh = open_compressed_file($file) or
+ die "Unable to open $file for reading: $!";
+ my %dist_info;
+ my $in_sha1;
+ my %p_f;
+ while (<$rfh>) {
+ chomp;
+ if (s/^(\S+):\s*//) {
+ if ($1 eq 'SHA1'or $1 eq 'SHA256') {
+ $in_sha1 = 1;
+ next;
+ }
+ $dist_info{$1} = $_;
+ } elsif ($in_sha1) {
+ s/^\s//;
+ my ($sha,$size,$f) = split /\s+/,$_;
+ next unless $f =~ /(?:Packages|Sources)(?:\.gz|\.xz)$/;
+ next unless $f =~ m{^([^/]+)/([^/]+)/([^/]+)$};
+ my ($component,$arch,$package_source) = ($1,$2,$3);
+ $arch =~ s/binary-//;
+ next if exists $p_f{$component}{$arch};
+ $p_f{$component}{$arch} = File::Spec->catfile(dirname($file),$f);
+ }
+ }
+ return (\%dist_info,\%p_f);
+}
+
sub walk_bugs {
my ($dirs,$p,$what,$verbose,$sub) = @_;
my @dirs = @{$dirs};