use DBI;
use lib '/org/wanna-build/bin';
use WannaBuild;
+use YAML::Tiny;
+use Data::Dumper;
+use Hash::Merge qw ( merge );
our ($verbose, $mail_logs, $list_order, $list_state,
$curr_date, $op_mode, $user, $real_user, $distribution,
# global vars
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:/org/wanna-build/bin/";
+$ENV{'LC_ALL'} = 'C';
$verbose = 0;
$mail_logs = "";
@curr_time = gmtime;
}
}
+my $yamlmap = ();
+my $yamldir = "/org/wanna-build/etc/yaml";
+my @files = ('wanna-build.yaml');
+if ($user =~ /(buildd.*)-/) { push (@files, "$1.yaml") };
+push ( @files, "$user.yaml");
+foreach my $file (@files) {
+ if ($verbose >= 2) { print "Trying to read $file ...\n"; }
+ next unless -f $yamldir."/".$file;
+ if ($verbose >= 2) { print "Read $file ...\n"; }
+ my $m = YAML::Tiny->read( $yamldir."/".$file )->[0];
+ $yamlmap = merge($m, $yamlmap);
+}
+if (not $yamlmap) {
+ die "FATAL: no configuration found\n";
+}
+
my $dbh;
END {
last SWITCH;
};
/W/ && do {
- $x = $b->{'waiting_days'} <=> $a->{'waiting_days'};
+ $x = $b->{'state_days'} <=> $a->{'state_days'};
return $x if $x != 0;
last SWITCH;
};
}
sub calculate_prio {
-######################
-# priority: required = 50, important = 40, standard = 30, optional = 5
-# section: libs = 4, devel = 2
-# component: contrib = -10, non-free = -20
-# never built = -20
-# max(floor(waitingdays),6)
-
- my $priomap;
- $priomap->{'priority'} = { 'required' => 50, 'important' => 40, 'standard' => 30, 'optional' => 5 };
- $priomap->{'section'} = { 'libs' => 4, 'devel' => 2 };
- $priomap->{'component'} = { 'contrib' => -10, 'non-free' => -20 };
- $priomap->{'notes'} = { 'uncompiled' => 20, 'out-of-date' => 40, 'partial' => 40 };
- $priomap->{'waitingdays'} = { 'min' => 0, 'max' => 6, scale => 2 };
+ my $priomap = $yamlmap->{priority};
my $pkg = shift;
$pkg->{'calprio'} = 0;
- foreach my $k (keys %$priomap) {
- $pkg->{'calprio'} += $priomap->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{$k}{$pkg->{$k}};
+ foreach my $k (keys %{$priomap->{keys}}) {
+ $pkg->{'calprio'} += $priomap->{keys}->{$k}{$pkg->{$k}} if $pkg->{$k} and $priomap->{keys}->{$k}{$pkg->{$k}};
}
- my $wd = $pkg->{'waiting_days'};
- $wd = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $wd < $priomap->{'waitingdays'}->{'min'};
- $wd = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $wd > $priomap->{'waitingdays'}->{'max'};
+ my $days = $pkg->{'state_days'};
+ $days = $priomap->{'waitingdays'}->{'min'} if $priomap->{'waitingdays'}->{'min'} and $days < $priomap->{'waitingdays'}->{'min'};
+ $days = $priomap->{'waitingdays'}->{'max'} if $priomap->{'waitingdays'}->{'max'} and $days > $priomap->{'waitingdays'}->{'max'};
my $scale = $priomap->{'waitingdays'}->{'scale'} || 1;
- $pkg->{'calprio'} += $wd * $scale;
+ $pkg->{'calprio'} += $days * $scale;
$pkg->{'calprio'} += $pkg->{'permbuildpri'} if $pkg->{'permbuildpri'};
$pkg->{'calprio'} += $pkg->{'buildpri'} if $pkg->{'buildpri'};
print ":binNMU{" . $pkg->{'binary_nmu_version'} . "}"
if defined $pkg->{'binary_nmu_version'};
print ":calprio{". $pkg->{'calprio'}."}";
- print ":wd{". $pkg->{'waiting_days'}."}";
+ print ":days{". $pkg->{'state_days'}."}";
print "]\n";
print " Reasons for failing:\n",
" [Category: ",
print " Reasons for BD-Uninstallable:\n ",
join("\n ",split("\n",$pkg->{'bd_problem'})), "\n"
if $pkg->{'state'} eq "BD-Uninstallable";
- print " Previous state was $pkg->{'previous_state'} until ",
- "$pkg->{'state_change'}\n"
+ print " Previous state was $pkg->{'previous_state'}\n"
if $verbose && $pkg->{'previous_state'};
print " No previous state recorded\n"
if $verbose && !$pkg->{'previous_state'};
+ print " State changed at $pkg->{'state_change'}\n"
+ if $verbose && $pkg->{'state_change'};
+ print " Previous state $pkg->{'previous_state'} left $pkg->{'state_time'} ago\n"
+ if $verbose && $pkg->{'previous_state'};
print " Previous failing reasons:\n ",
join("\n ",split("\n",$pkg->{'old_failed'})), "\n"
if $verbose && $pkg->{'old_failed'};
my @firstkeys = qw(package version builder state section priority
installed_version previous_state state_change);
my @dists = $info_all_dists ? keys %conf::distributions : ($distribution);
+ my %beautykeys = ( 'package' => 'Package', 'version' => 'Version', 'builder' => 'Builder',
+ 'state' => 'State', 'section' => 'Section', 'priority' => 'Priority',
+ 'installed_version' => 'Installed-Version', 'previous_state' => 'Previous-State',
+ 'state_change' => 'State-Change',
+ 'bd_problem' => 'BD-Problem',
+ 'binary_nmu_changelog' => 'Binary-NMU-Changelog', 'binary_nmu_version' => 'Binary-NMU-Version',
+ 'buildpri' => 'BuildPri', 'depends' => 'Depends', 'failed' => 'Failed',
+ 'failed_category' => 'Failed-Category', 'notes' => 'Notes',
+ 'distribution' => 'Distribution', 'old_failed' => 'Old-Failed',
+ 'permbuildpri' => 'PermBuildPri', 'rel' => 'Rel',
+ 'calprio' => 'CalculatedPri', 'state_days' => 'State-Days'
+ );
foreach $name (@_) {
$name =~ s/_.*$//; # strip version
$val = "\n$val" if isin( $key, qw(Failed Old-Failed));
$val =~ s/\n/\n /g;
my $print_key = $key;
- $print_key = 'Package' if ($key eq 'package');
- $print_key = 'Version' if ($key eq 'version');
- $print_key = 'Builder' if ($key eq 'builder');
- $print_key = 'State' if ($key eq 'state');
- $print_key = 'Section' if ($key eq 'section');
- $print_key = 'Priority' if ($key eq 'priority');
- $print_key = 'Installed-Version' if ($key eq 'installed_version');
- $print_key = 'Previous-State' if ($key eq 'previous_state');
- $print_key = 'State-Change' if ($key eq 'state_change');
+ $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
printf " %-20s: %s\n", $print_key, $val;
}
foreach $key (sort keys %$pkg) {
$val = "\n$val" if isin( $key, qw(Failed Old-Failed));
$val =~ s/\n/\n /g;
my $print_key = $key;
- $print_key = 'BD-Problem' if ($key eq 'bd_problem');
- $print_key = 'Binary-NMU-Changelog' if ($key eq 'binary_nmu_changelog');
- $print_key = 'Binary-NMU-Version' if ($key eq 'binary_nmu_version');
- $print_key = 'BuildPri' if ($key eq 'buildpri');
- $print_key = 'Depends' if ($key eq 'depends');
- $print_key = 'Failed' if ($key eq 'failed');
- $print_key = 'Failed-Category' if ($key eq 'failed_category');
- $print_key = 'Notes' if ($key eq 'notes');
- $print_key = 'Distribution' if ($key eq 'distribution');
- $print_key = 'Old-Failed' if ($key eq 'old_failed');
- $print_key = 'PermBuildPri' if ($key eq 'permbuildpri');
- $print_key = 'Rel' if ($key eq 'rel');
- $print_key = 'CalculatedPri' if ($key eq 'calprio');
- $print_key = 'Waiting-Days' if ($key eq 'waiting_days');
+ $print_key = $beautykeys{$print_key} if $beautykeys{$print_key};
printf " %-20s: %s\n", $print_key, $val;
}
}
sub get_readonly_source_info {
my $name = shift;
# SELECT FLOOR(EXTRACT('epoch' FROM age(localtimestamp, '2010-01-22 23:45')) / 86400) -- change to that?
- my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as waiting_days FROM ' .
+ my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as state_days FROM ' .
table_name() . ' WHERE package = ? AND distribution = ?',
undef, $name, $distribution);
return $pkg;
sub get_source_info {
my $name = shift;
- my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as waiting_days FROM ' .
+ my $pkg = $dbh->selectrow_hashref('SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as state_days FROM ' .
table_name() . ' WHERE package = ? AND distribution = ?' .
' FOR UPDATE',
undef, $name, $distribution);
sub get_all_source_info {
my %options = @_;
- my $q = 'SELECT *, extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as waiting_days FROM ' . table_name()
+ my $q = 'SELECT *, '.
+ 'extract(days from date_trunc(\'days\', now() - state_change::timestamp)) as state_days, '.
+ 'date_trunc(\'seconds\', now() - state_change::timestamp) as state_time'.
+ ' FROM ' . table_name()
. ' WHERE distribution = ? ';
my @args = ($distribution);
if ($options{state} && uc($options{state}) ne "ALL") {