]> andersk Git - moira.git/blame - regtape/grouper.pl
Command line printer manipulation client, and build goo.
[moira.git] / regtape / grouper.pl
CommitLineData
008e908b 1#!/moira/bin/perl -Tw
2# $Id$
3
4die "Usage: $0 password\n" unless ($#ARGV == 0);
5$whpassword = $ARGV[0];
4ec2c27e 6$db = "";
008e908b 7$mrtest = "mrtest";
4de57380 8$logfile = "/moira/grouper.log";
008e908b 9$ENV{'PATH'} = "/moira/bin";
10use DBI;
11
12$warehouse = DBI->connect("dbi:Oracle:warehouse", "moira", $whpassword,
13 { RaiseError => 1 });
14$moira = DBI->connect("dbi:Oracle:moira", "moira", "moira",
15 { RaiseError => 1});
16
17# Get the current term
18($term) = $warehouse->selectrow_array("SELECT term_code ".
19 "FROM wareuser.whsis_academic_terms ".
20 "WHERE is_current_term='Y'");
21# Convert from "2000FA" to "FA00"
22$term =~ s/\d\d(\d\d)(..)/$2$1/;
23
24# Get list of current classes
25$classes =
26 $warehouse->selectcol_arrayref("SELECT UNIQUE master_subject ".
27 "FROM wareuser.subject_enrollment_moira ".
28 "WHERE term = " . $warehouse->quote($term));
29
30# Get names of current Grouper lists
31$sth = $moira->prepare("SELECT name FROM list");
32$sth->execute;
33while (($name) = $sth->fetchrow_array) {
34 next if $name !~ /^(fa|sp|su|ja)\d\d-/;
35 $lists{$name} = $name;
36}
37
38$lists{"registrar"} = "registrar";
39
40# And MIT ID to username mappings
41$sth = $moira->prepare("SELECT login, clearid FROM users ".
42 "WHERE status = 1 OR status = 2");
43$sth->execute;
44while (($user, $mitid) = $sth->fetchrow_array) {
45 $users{$mitid} = $user;
46}
47
48($root_id) = $moira->selectrow_array("SELECT users_id FROM users ".
49 "WHERE login = 'root'");
50
408e5cd3 51open(MRTEST, "|$mrtest >/dev/null 2>&1");
008e908b 52print MRTEST "connect $db\n";
53print MRTEST "auth\n";
426db67f 54open(LOG, ">>$logfile");
008e908b 55
56# Create any lists that don't already exist in Moira
57foreach $class (@$classes) {
58 $base = "\L$term-$class";
59 $staff = "$base-staff";
60
50e8f688 61 # check_list(name, owner, export, desc)
62 &check_list($staff, $staff, 0,
63 "Teaching staff list for $class");
64 &check_list("$base-reg", $staff, 0,
65 "*** DO NOT MODIFY *** Automatically-created registered students list for $class");
66 &check_list("$base-others", $staff, 0,
67 "Non-registered students and miscellaneous people list for $class");
0b994c44 68 &check_list($base, $staff, 1,
50e8f688 69 "*** DO NOT MODIFY *** Automatically-created participants list for $class");
70 if (!$lists{$base}) {
71 &add_member($staff, LIST, $base);
72 &add_member("$base-reg", LIST, $base);
73 &add_member("$base-others", LIST, $base);
74 }
008e908b 75}
76
77# Now fill in -reg lists
78foreach $class (@$classes) {
79 $changed = 0;
80 $clist = "\L$term-$class-reg";
81
82 # Get current list membership in Moira
83 %mstudents = ();
84 $sth = $moira->prepare("SELECT u.login FROM users u, imembers i, list l ".
85 "WHERE l.list_id = i.list_id AND i.member_id = ".
86 "u.users_id AND i.direct = 1 AND i.member_type = ".
87 "'USER' AND l.name = " . $moira->quote($clist));
88 $sth->execute;
89 while (($login) = $sth->fetchrow_array) {
90 $mstudents{$login} = $login;
91 }
92
93 $wstudents = $warehouse->selectcol_arrayref("SELECT UNIQUE mit_id ".
94 "FROM wareuser.subject_enrollment_moira ".
95 "WHERE term = " . $warehouse->quote($term) .
96 " AND master_subject = " .
97 $warehouse->quote($class));
98
99 foreach $mitid (@$wstudents) {
100 $login = $users{$mitid};
101 next if !$login;
102 if (!$mstudents{$login}) {
4de57380 103 print LOG "Adding $login to $clist\n";
008e908b 104 &add_member($login, USER, $clist);
105 $changed = 1;
106 } else {
107 delete $mstudents{$login};
108 }
109 }
110
111 # Everyone in wstudents will have been removed from mstudents
112 # now, so delete the remaining users since they don't belong
113 foreach $login (keys(%mstudents)) {
4de57380 114 print LOG "Deleting $login from $clist\n";
008e908b 115 &del_member($login, USER, $clist);
116 $changed = 1;
117 }
118
119 if ($changed) {
120 $moira->do("UPDATE list SET modtime = SYSDATE, modby = $root_id, ".
121 "modwith = 'grouper' WHERE name = " .
122 $moira->quote($clist));
123 }
124}
125
126print MRTEST "quit\n";
127close(MRTEST);
4de57380 128close(LOG);
008e908b 129$moira->disconnect;
130$warehouse->disconnect;
131
132exit 0;
133
134sub check_list {
50e8f688 135 my ( $name, $owner, $export, $desc ) = @_;
008e908b 136 if (!$lists{$name}) {
4de57380 137 print LOG "Creating $name\n";
0f5db77d 138 print MRTEST "qy alis $name 0 0 1 $export $export \"create unique GID\" 0 0 [NONE] LIST $owner NONE NONE \"$desc\"\n";
008e908b 139 }
140}
141
142sub add_member {
143 my ( $user, $type, $list ) = @_;
144 print MRTEST "qy amtl $list $type $user\n";
145}
146
147sub del_member {
148 my ( $user, $type, $list ) = @_;
149 print MRTEST "qy dmfl $list $type $user\n";
150}
This page took 0.079063 seconds and 5 git commands to generate.