script for changing compiler name
[buildfarm-server.git] / scripts / rename_system.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use DBI;
6 use Data::Dumper;
7
8 die "Must pass current and new sysnames\n" unless scalar @ARGV == 2;
9
10 use vars qw($dbhost $dbname $dbuser $dbpass $dbport
11             $user_list_format
12 );
13
14 use FindBin qw($RealBin);
15 require "$RealBin/../BuildFarmWeb.pl";
16
17 die "no dbname" unless $dbname;
18 die "no dbuser" unless $dbuser;
19
20 my $dsn="dbi:Pg:dbname=$dbname";
21 $dsn .= ";host=$dbhost" if $dbhost;
22 $dsn .= ";port=$dbport" if $dbport;
23
24 my $db = DBI->connect($dsn,$dbuser,$dbpass);
25
26 die $DBI::errstr unless $db;
27
28 my $sth_up = $db->prepare(q[
29        UPDATE buildsystems AS b
30        SET name = ?
31        WHERE name = ?
32       ]);
33 $sth_up->execute($ARGV[1],$ARGV[0]);
34
35 my $sth = $db->prepare(q[ 
36        SELECT name, status, operating_system, os_version, sys_owner, owner_email
37        FROM buildsystems AS b
38        ORDER BY name ASC
39       ]);
40 $sth->execute();
41
42 printf $user_list_format,
43        "SysName", "Status", "Owner", "Email", "Distro", "Version";
44 while (my $row = $sth->fetchrow_hashref)
45 {
46   printf $user_list_format,
47                   $row->{name}, $row->{status}, $row->{sys_owner},
48                   $row->{owner_email}, $row->{operating_system},
49                   $row->{os_version};
50 }
51 $db->disconnect();