]> git.donarmstrong.com Git - wannabuild.git/blobdiff - bin/wanna-build
Make info print field names again like the old version
[wannabuild.git] / bin / wanna-build
index 585e4e0e7c81b35f7ef73fe45088709c98793666..0d24fd1485ddbc0630727b2e95cfabf0be1cdf7a 100755 (executable)
@@ -24,8 +24,7 @@ package conf;
 $basedir ||= "/var/lib/debbuild";
 $dbbase ||= "build-db";
 $transactlog ||= "transactions.log";
-#$mailprog ||= "/usr/sbin/sendmail";
-$mailprog = "/bin/true";
+$mailprog ||= "/usr/sbin/sendmail";
 require "/etc/wanna-build.conf";
 die "$conf::basedir is not a directory\n" if ! -d $conf::basedir;
 die "dbbase is empty\n" if ! $dbbase;
@@ -302,8 +301,18 @@ END {
        }
 }
 
-$dbh = DBI->connect("DBI:Pg:database=wanna-build") || 
-       die "FATAL: Cannot open database: $DBI::errstr\n";
+my $schema_suffix = '';
+# TODO: Base this on something else, like an option that is passed.
+if ($real_user eq 'nobody') {
+       $dbh = DBI->connect("DBI:Pg:service=wanna-build") || 
+               die "FATAL: Cannot open database: $DBI::errstr\n";
+       $schema_suffix = '_public';
+}
+else
+{
+       $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") || 
+               die "FATAL: Cannot open database: $DBI::errstr\n";
+}
 
 # TODO: This shouldn't be needed, file a bug.
 $dbh->{pg_server_prepare} = 0;
@@ -401,7 +410,9 @@ sub process {
                        die "This operation is restricted to admin users\n"
                                if (defined @conf::admin_users and
                                    !isin( $real_user, @conf::admin_users));
-                       $dbh->do("DELETE from " . table_name())
+                       $dbh->do("DELETE from " . table_name() . 
+                               " WHERE distribution = ?", undef,
+                               $distribution)
                                or die $dbh->errstr;
                        forget_users();
                        read_db( $import_from );
@@ -1553,7 +1564,8 @@ sub parse_quinn_diff {
 
        if ($dubious) {
                send_mail( $conf::db_maint,
-                                  "Dubious versions in " . table_name() . " table",
+                                  "Dubious versions in " . table_name() . " "
+                                  . $distribution . " table",
                                   "The following packages have a newer version in the ".
                                   "wanna-build database\n".
                                   "than what quinn-diff says, and this is strange for ".
@@ -1756,9 +1768,9 @@ sub list_packages {
                next if $category && $pkg->{'state'} eq "Failed" &&
                                $pkg->{'failed_category'} ne $category;
                next if ($list_min_age > 0 &&
-                                ($ctime-parse_date($pkg->{'State-Change'})) < $list_min_age)||
+                                ($ctime-parse_date($pkg->{'state_change'})) < $list_min_age)||
                                ($list_min_age < 0 &&
-                                ($ctime-parse_date($pkg->{'State-Change'})) > -$list_min_age);
+                                ($ctime-parse_date($pkg->{'state_change'})) > -$list_min_age);
                push( @list, $pkg );
        }
 
@@ -1788,7 +1800,7 @@ sub list_packages {
                          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"
+                         "$pkg->{'state_change'}\n"
                        if $verbose && $pkg->{'previous_state'};
                print "  No previous state recorded\n"
                        if $verbose && !$pkg->{'previous_state'};
@@ -1831,7 +1843,17 @@ sub info_packages {
                                chomp( $val );
                                $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
                                $val =~ s/\n/\n    /g;
-                               printf "  %-20s: %s\n", $key, $val;
+                               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');
+                               printf "  %-20s: %s\n", $print_key, $val;
                        }
                        foreach $key (sort keys %$pkg) {
                                next if isin( $key, @firstkeys );
@@ -1839,7 +1861,20 @@ sub info_packages {
                                chomp( $val );
                                $val = "\n$val" if isin( $key, qw(Failed Old-Failed));
                                $val =~ s/\n/\n    /g;
-                               printf "  %-20s: %s\n", $key, $val;
+                               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');
+                               printf "  %-20s: %s\n", $print_key, $val;
                        }
                }
        }
@@ -1864,7 +1899,7 @@ sub forget_packages {
                        $data .= sprintf "  %-20s: %s\n", $key, $val;
                }
                send_mail( $conf::db_maint,
-                                  "$name deleted from DB " . table_name(),
+                                  "$name deleted from DB " . table_name() . " " . $distribution,
                                   "The package '$name' has been deleted from the database ".
                                   "by $user.\n\n".
                                   "Data registered about the deleted package:\n".
@@ -1877,7 +1912,8 @@ sub forget_packages {
 }
 
 sub forget_users {
-       $dbh->do("DELETE from " . user_table_name()) or die $dbh->errstr;
+       $dbh->do("DELETE from " . user_table_name() . 
+               " WHERE distribution = ?", undef, $distribution) or die $dbh->errstr;
 }
 
 sub read_db {
@@ -1909,8 +1945,10 @@ sub read_db {
                elsif(exists($thispkg{'user'})) {
                        # user in import, username in database.
                        $dbh->do('INSERT INTO ' . user_table_name() .
-                                       ' (username, last_seen) values (?, ?)',
-                               undef, $thispkg{'user'}, $thispkg{'last_seen'})
+                                       ' (username, distribution, last_seen)' .
+                                       ' values (?, ?, ?)',
+                               undef, $thispkg{'user'}, $distribution,
+                               $thispkg{'last_seen'})
                                or die $dbh->errstr;
                 }
        }
@@ -1933,18 +1971,18 @@ sub check_entry {
                          join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
                die "Database entry lacks package or username field\n";
        }
-       if (!exists $pkg->{'version'}) {
-               die "Database entry for $pkg->{'package'} lacks Version: field\n";
-       }
        # if no State: field, generate one (for old db compat)
        if (!exists($pkg->{'state'})) {
                $pkg->{'state'} =
                        exists $pkg->{'failed'} ? 'Failed' : 'Building';
        }
+       if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
+               die "Database entry for $pkg->{'package'} lacks Version: field\n";
+       }
        # check state field
        die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
                if !isin( $pkg->{'state'},
-                                 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait
+                                 qw(Needs-Build Building Built Build-Attempted Uploaded Installed Dep-Wait Dep-Wait-Removed
                                         Failed Failed-Removed Not-For-Us BD-Uninstallable
                                         ) );
 }
@@ -1957,7 +1995,7 @@ sub change_state {
        
        return if defined($$state) and $$state eq $newstate;
         $pkg->{'previous_state'} = $$state if defined($$state);
-       $pkg->{'State-Change'} = $curr_date;
+       $pkg->{'state_change'} = $curr_date;
 
        if (defined($$state) and $$state eq 'Failed') {
                $pkg->{'old_failed'} =
@@ -2369,24 +2407,25 @@ sub pkg_version_eq {
 }
 
 sub table_name {
-       return $arch . '_' . $distribution;
+       return '"' . $arch . $schema_suffix . '".packages';
 }
 
 sub user_table_name {
-       return $arch . '_' . $distribution . '_users';
+       return '"' . $arch . $schema_suffix . '".users';
 }
 
 sub get_source_info {
        my $name = shift;
        my $pkg = $dbh->selectrow_hashref('SELECT * FROM ' . 
-               table_name() . ' WHERE package = ?',
-               undef, $name);
+               table_name() . ' WHERE package = ? AND distribution = ?',
+               undef, $name, $distribution);
        return $pkg;
 }
 
 sub get_all_source_info {
-       my $db = $dbh->selectall_hashref('SELECT * FROM ' . table_name(),
-               'package');
+       my $db = $dbh->selectall_hashref('SELECT * FROM ' . table_name() .
+               ' WHERE distribution = ?',
+               'package', undef, $distribution);
        return $db;
 }
 
@@ -2419,7 +2458,7 @@ sub update_source_info {
                        'depends = ?, ' .
                        'rel = ?, ' .
                        'bd_problem = ? ' .
-                       'WHERE package = ?',
+                       'WHERE package = ? AND distribution = ?',
                undef,
                $pkg->{'version'},
                $pkg->{'state'},
@@ -2440,36 +2479,38 @@ sub update_source_info {
                $pkg->{'depends'},
                $pkg->{'rel'},
                $pkg->{'bd_problem'},
-               $pkg->{'package'}) or die $dbh->errstr;
+               $pkg->{'package'},
+               $distribution) or die $dbh->errstr;
 }
 
 sub add_source_info {
        my $pkg = shift;
        $dbh->do('INSERT INTO ' . table_name() .
-                       ' (package) values (?)',
-               undef, $pkg->{'package'}) or die $dbh->errstr;
+                       ' (package, distribution) values (?, ?)',
+               undef, $pkg->{'package'}, $distribution) or die $dbh->errstr;
 }
 
 sub del_source_info {
        my $name = shift;
        $dbh->do('DELETE FROM ' . table_name() .
-                       ' WHERE package = ?',
-               undef, $name) or die $dbh->errstr;
+                       ' WHERE package = ? AND distribution = ?',
+               undef, $name, $distribution) or die $dbh->errstr;
 }
 
 sub get_user_info {
        my $name = shift;
        my $user = $dbh->selectrow_hashref('SELECT * FROM ' . 
-               user_table_name() . ' WHERE username = ?',
-               undef, $name);
+               user_table_name() . ' WHERE username = ? AND distribution = ?',
+               undef, $name, $distribution);
        return $user;
 }
 
 sub update_user_info {
        my $user = shift;
        $dbh->do('UPDATE ' . user_table_name() .
-                       ' SET last_seen = now() WHERE username = ?',
-               undef, $user)
+                       ' SET last_seen = now() WHERE username = ?' .
+                       ' AND distribution = ?',
+               undef, $user, $distribution)
                or die $dbh->errstr;
 }
 
@@ -2477,8 +2518,9 @@ sub update_user_info {
 sub add_user_info {
        my $user = shift;
        $dbh->do('INSERT INTO ' . user_table_name() .
-                       ' (username, last_seen) values (?, now())',
-               undef, $user)
+                       ' (username, distribution, last_seen)' .
+                       ' values (?, ?, now())',
+               undef, $user, $distribution)
                or die $dbh->errstr;
 }