]> andersk Git - moira.git/blob - gen/stellar.gen
Care about public and hidden bits; look for MACHINE members of lists.
[moira.git] / gen / stellar.gen
1 #!/moira/bin/perl -Tw
2
3 # $Id$
4
5 # The following exit codes are defined and MUST BE CONSISTENT with the
6 # error codes the library uses:
7 $MR_DBMS_ERR = 47836421;
8 $MR_OCONFIG = 47836460;
9
10 $ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
11
12 $outdir = '/moira/dcm/stellar';
13 $outfile = '/moira/dcm/stellar.out';
14 umask 022;
15
16 use DBI;
17
18 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
19   || exit $MR_DBMS_ERR;
20
21 $sth0 = $dbh->prepare("SELECT l.list_id, m.name " .
22                       "FROM list l, machine m, serverhosts sh " .
23                       "WHERE sh.value3 = l.name AND sh.service = 'STELLAR' " .
24                       "AND m.mach_id = sh.mach_id") || exit $MR_DBMS_ERR;
25 $sth0->execute;
26
27 while (($root_list_id, $hostname) = $sth0->fetchrow_array) {
28     open(OUT, ">$outdir/$hostname");
29
30     $sth = $dbh->prepare("SELECT l.name FROM list l, imembers i " .
31                          "WHERE i.list_id = " . $dbh->quote($root_list_id) .
32                          "AND i.member_type = 'LIST' " .
33                          "AND i.member_id = l.list_id " .
34                          "ORDER BY l.name") || exit $MR_DBMS_ERR;
35     $sth->execute;
36     
37     while (($name) = $sth->fetchrow_array) {
38         $sth2 = $dbh->prepare("SELECT UNIQUE i.member_type, i.member_id " .
39                               "FROM imembers i, list l " .
40                               "WHERE l.name = " . $dbh->quote($name) .
41                               "AND i.list_id = l.list_id " .
42                               "AND (i.member_type = 'USER' " .
43                               "OR i.member_type = 'STRING')") || 
44                                   exit $MR_DBMS_ERR;
45         $sth2->execute;
46         
47         $row = "$name:";
48         $row =~ s/\0//g;
49         print OUT $row;
50         $maybecomma = "";
51         
52         while (($type, $id) = $sth2->fetchrow_array) {
53             if ($type eq "USER") {
54                 ($member) = $dbh->selectrow_array("SELECT login FROM users " .
55                                                   "WHERE users_id = " . 
56                                                   $dbh->quote($id)) ||
57                                                       exit $MR_DBMS_ERR;
58                 $member = $member . "\@mit.edu";
59             }
60             elsif ($type eq "STRING") {
61                 ($member) = $dbh->selectrow_array("SELECT string " .
62                                                   "FROM strings " .
63                                                   "WHERE string_id = " .
64                                                   $dbh->quote($id)) ||
65                                                       exit $MR_DBMS_ERR;
66             }
67             $row = "$maybecomma$member";
68             $row =~ s/\0//g;
69             print OUT $row;
70             $maybecomma = ",";
71         }
72         
73         $row = "\n";
74         $row =~ s/\0//g;
75         print OUT $row;
76     }
77     close(OUT);
78 }
79
80 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
81
82 $dbh->disconnect;
83
84 exit 0;
This page took 0.381521 seconds and 5 git commands to generate.