--help, -h display this help
--man, -m display manual
+=head1 SUBCOMMANDS
+
+=head2 help
+
+Display this manual
+
+=head2 bugs
+
+Add bugs
+
+=head2 versions
+
+Add versions
+
+=head2 maintainers
+
+Add source maintainers
+
=head1 OPTIONS
=over
Output more information about what is happening. Probably not useful
if you also set --progress.
-=item B<--debug, -d
+=item B<--debug, -d>
Debug verbosity.
verbose => 0,
quiet => 0,
quick => 0,
- service => 'debbugs',
+ service => $config{debbugs_db},
progress => 0,
);
-my $gop = Getopt::Long::Parser->new();
-$gop->configure('pass_through');
-$gop->getoptions(\%options,
- 'quick|q',
- 'service|s',
- 'sysconfdir|c',
- 'progress!',
- 'spool_dir|spool-dir=s',
- 'verbose|v+',
- 'quiet+',
- 'debug|d+','help|h|?','man|m');
-$gop->getoptions('default');
+Getopt::Long::Configure('pass_through');
+GetOptions(\%options,
+ 'quick|q',
+ 'service|s=s',
+ 'sysconfdir|c=s',
+ 'progress!',
+ 'spool_dir|spool-dir=s',
+ 'verbose|v+',
+ 'quiet+',
+ 'debug|d+','help|h|?','man|m');
+Getopt::Long::Configure('default');
pod2usage() if $options{help};
pod2usage({verbose=>2}) if $options{man};
},
'configuration' => {function => \&add_configuration,
},
+ 'suites' => {function => \&add_suites,
+ },
'logs' => {function => \&add_logs,
},
+ 'help' => {function => sub {pod2usage({verbose => 2});}}
);
my @USAGE_ERRORS;
my ($subcommand) = shift @ARGV;
+if (not defined $subcommand) {
+ $subcommand = 'help';
+ print STDERR "You must provide a subcommand; displaying usage.\n";
+ pod2usage();
+} elsif (not exists $subcommands{$subcommand}) {
+ print STDERR "$subcommand is not a valid subcommand; displaying usage.\n";
+ pod2usage();
+}
my $opts =
- handle_arguments(\@ARGV,$subcommands{$subcommand}{arguments},$gop);
+ handle_subcommand_arguments(\@ARGV,$subcommands{$subcommand}{arguments});
$subcommands{$subcommand}{function}->(\%options,$opts,$prog_bar,\%config,\@ARGV);
sub add_bugs {
my $time = 0;
my $start_time = time;
-
-
- my @dirs = (@{$argv}?@{$argv} : $initialdir);
- my $cnt = 0;
my %tags;
my %severities;
my %queue;
- my $tot_dirs = @{$argv}? @{$argv} : 0;
- my $done_dirs = 0;
- my $avg_subfiles = 0;
- my $completed_files = 0;
- while (my $dir = shift @dirs) {
- printf "Doing dir %s ...\n", $dir if $verbose;
- opendir(DIR, "$dir/.") or die "opendir $dir: $!";
- my @subdirs = readdir(DIR);
- closedir(DIR);
-
- my @list = map { m/^(\d+)\.summary$/?($1):() } @subdirs;
- $tot_dirs -= @dirs;
- push @dirs, map { m/^(\d+)$/ && -d "$dir/$1"?("$dir/$1"):() } @subdirs;
- $tot_dirs += @dirs;
- if ($avg_subfiles == 0) {
- $avg_subfiles = @list;
- }
-
- $p->target($avg_subfiles*($tot_dirs-$done_dirs)+$completed_files+@list) if $p;
- $avg_subfiles = ($avg_subfiles * $done_dirs + @list) / ($done_dirs+1);
- $done_dirs += 1;
-
- for my $bug (@list) {
- $completed_files++;
- $p->update($completed_files) if $p;
- print "Up to $cnt bugs...\n" if (++$cnt % 100 == 0 && $verbose);
- my $stat = stat(getbugcomponent($bug,'summary',$initialdir));
- if (not defined $stat) {
- print STDERR "Unable to stat $bug $!\n";
- next;
- }
- next if $stat->mtime < $time;
- my $data = read_bug(bug => $bug,
- location => $initialdir);
- eval {
- load_bug(db => $s,
- data => split_status_fields($data),
- tags => \%tags,
- severities => \%severities,
- queue => \%queue);
- };
- if ($@) {
- use Data::Dumper;
- print STDERR Dumper($data) if $DEBUG;
- die "failure while trying to load bug $bug\n$@";
- }
- }
- }
- $p->remove() if $p;
+ walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
+ $p,
+ 'summary',
+ $verbose,
+ sub {
+ my $bug = shift;
+ my $stat = stat(getbugcomponent($bug,'summary',$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();
+ }
+ my $data = read_bug(bug => $bug,
+ location => $initialdir);
+ eval {
+ load_bug(db => $s,
+ data => split_status_fields($data),
+ tags => \%tags,
+ severities => \%severities,
+ queue => \%queue);
+ };
+ if ($@) {
+ use Data::Dumper;
+ print STDERR Dumper($data) if $DEBUG;
+ die "failure while trying to load bug $bug\n$@";
+ }
+ }
+ );
handle_load_bug_queue(db => $s,
queue => \%queue);
}
my $s = db_connect($options);
my @files = @{$argv};
- $p->target(@files) if $p;
+ $p->target(scalar @files) if $p;
for my $file (@files) {
my $fh = IO::File->new($file,'r') or
die "Unable to open $file for reading: $!";
my $sp;
if (not defined $src_pkgs{$versions[$i][0]}) {
$src_pkgs{$versions[$i][0]} =
- $s->resultset('SrcPkg')->find({pkg => $versions[$i][0]});
+ $s->resultset('SrcPkg')->find_or_create({pkg => $versions[$i][0]});
}
$sp = $src_pkgs{$versions[$i][0]};
# There's probably something wrong if the source package
# doesn't exist, but we'll skip it for now
next unless defined $sp;
- my $sv = $s->resultset('SrcVer')->find({src_pkg_id=>$sp->id(),
+ my $sv = $s->resultset('SrcVer')->find({src_pkg=>$sp->id(),
ver => $versions[$i][1],
});
if (defined $ancestor_sv and defined $sv and not defined $sv->based_on()) {
my ($options,$opts,$p,$config,$argv) = @_;
my @files = @{$argv};
+ return unless @files;
my $s = db_connect($options);
-
my %arch;
- $p->target(@files) if $p;
+ $p->target(scalar @files) if $p;
for my $file (@files) {
my $fh = IO::File->new($file,'r') or
die "Unable to open $file for reading: $!";
($binarch) = $file =~ /_([^\.]+)\.debinfo/;
}
my $sp = $s->resultset('SrcPkg')->find_or_create({pkg => $srcname});
- my $sv = $s->resultset('SrcVer')->find_or_create({src_pkg_id=>$sp->id(),
+ # update the creation date if the data we have is earlier
+ my $ct_date = DateTime->from_epoch(epoch => $f_stat->ctime);
+ if ($ct_date < $sp->creation) {
+ $sp->creation($ct_date);
+ $sp->last_modified(DateTime->now);
+ $sp->update;
+ }
+ my $sv = $s->resultset('SrcVer')->find_or_create({src_pkg =>$sp->id(),
ver => $srcver});
+ if (not defined $sv->upload_date() or $ct_date < $sv->upload_date()) {
+ $sv->upload_date($ct_date);
+ $sv->update;
+ }
my $arch;
if (defined $arch{$binarch}) {
$arch = $arch{$binarch};
$arch{$binarch} = $arch;
}
my $bp = $s->resultset('BinPkg')->find_or_create({pkg => $binname});
- $s->resultset('BinVer')->find_or_create({bin_pkg_id => $bp->id(),
- src_ver_id => $sv->id(),
- arch_id => $arch->id(),
+ $s->resultset('BinVer')->find_or_create({bin_pkg => $bp->id(),
+ src_ver => $sv->id(),
+ arch => $arch->id(),
ver => $binver,
});
}
find({name => $maint});
if (not defined $maint_r) {
# get e-mail address of maintainer
- my $e_mail = getparsedaddrs($maint);
+ 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,
}
# add the maintainer to the source package for packages with
# no maintainer
- $s->txndo(sub {
- $s->resultset('SrcPkg')->
- search_related_rs('SrcVer',{ maintainer_id => undef})->
- update_all({maintainer_id => $maint_r});
+ $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;
}
sub add_configuration {
my ($options,$opts,$p,$config,$argv) = @_;
+
+ my $s = db_connect($options);
+
+ # tags
+ # add all tags
+ # mark obsolete tags
+
+ # severities
+ my %sev_names;
+ my $order = 0;
+ for my $sev_name (@{$config{severities}}) {
+ # 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->update();
+ $order++;
+ $sev_names{$sev_name} = 1;
+ }
+ # mark obsolete severities
+ for my $sev ($s->resultset('Severity')->find()) {
+ next if exists $sev_names{$sev->severity()};
+ $sev->obsolete(1);
+ $sev->update();
+ }
+}
+
+sub add_suite {
+ my ($options,$opts,$p,$config,$argv) = @_;
+ # suites
+ die "add_suite is currently not implemented; modify suites manually using SQL."
}
sub add_logs {
my ($options,$opts,$p,$config,$argv) = @_;
+
+ chdir($config->{spool_dir}) or
+ die "chdir $config->{spool_dir} failed: $!";
+
+ my $verbose = $options->{debug};
+
+ my $initialdir = "db-h";
+
+ if (defined $argv->[0] and $argv->[0] eq "archive") {
+ $initialdir = "archive";
+ }
+ my $s = db_connect($options);
+
+
+ my $time = 0;
+ my $start_time = time;
+
+ walk_bugs([(@{$argv}?@{$argv} : $initialdir)],
+ $p,
+ 'log',
+ $verbose,
+ sub {
+ my $bug = shift;
+ eval {
+ load_bug_log(db => $s,
+ bug => $bug);
+ };
+ if ($@) {
+ die "failure while trying to load bug log $bug\n$@";
+ }
+ });
+}
+
+sub add_packages {
+
}
sub handle_subcommand_arguments {
- my ($argv,$args,$gop) = @_;
+ my ($argv,$args) = @_;
my $subopt = {};
- $gop->getoptionsfromarray($argv,
+ Getopt::Long::GetOptionsFromArray($argv,
$subopt,
keys %{$args},
);
die "Unable to connect to database: ";
}
+sub walk_bugs {
+ my ($dirs,$p,$what,$verbose,$sub) = @_;
+ my @dirs = @{$dirs};
+ my $tot_dirs = @dirs;
+ my $done_dirs = 0;
+ my $avg_subfiles = 0;
+ my $completed_files = 0;
+ while (my $dir = shift @dirs) {
+ printf "Doing dir %s ...\n", $dir if $verbose;
+
+ opendir(DIR, "$dir/.") or die "opendir $dir: $!";
+ my @subdirs = readdir(DIR);
+ closedir(DIR);
+
+ my @list = map { m/^(\d+)\.$what$/?($1):() } @subdirs;
+ $tot_dirs -= @dirs;
+ push @dirs, map { m/^(\d+)$/ && -d "$dir/$1"?("$dir/$1"):() } @subdirs;
+ $tot_dirs += @dirs;
+ if ($avg_subfiles == 0) {
+ $avg_subfiles = @list;
+ }
+
+ $p->target($avg_subfiles*($tot_dirs-$done_dirs)+$completed_files+@list) if $p;
+ $avg_subfiles = ($avg_subfiles * $done_dirs + @list) / ($done_dirs+1);
+ $done_dirs += 1;
+
+ for my $bug (@list) {
+ $completed_files++;
+ $p->update($completed_files) if $p;
+ print "Up to $completed_files bugs...\n" if ($completed_files % 100 == 0 && $verbose);
+ $sub->($bug);
+ }
+ }
+ $p->remove() if $p;
+}
+
__END__